效果
数据结构
{
"rows": [{
"fid": 27,
"baohan": "t",
"fenli": "f",
"xiangMian": "116.66101080875922 39.87880553596932,116.66235598770595 39.878613047944896,116.66284705236262 39.87860255909101,116.66335863647885 39.8783824589479,116.66223434115375 39.877115395962335,116.66192176882271 39.877114911394074,116.66185957604523 39.87737713667309,116.66156809207223 39.877335496105445,116.66075907533013 39.877567493553556,116.66086020242278 39.87792441270449,116.66098512412566 39.878644199658595,116.66101080875922 39.87880553596932",
"xiangjiao": "t",
"xiangMianJi": 22.0183,
"feiMian": [{
"jcm": "16.66104650067415 39.878936406324584,116.66239167962088 39.878743918300074,116.66286345431905 39.87869261319022,116.66353841602242 39.87864571838519,116.66020113347075 39.87741533324694,116.6603056469199 39.87785975964694,116.66057343849101 39.878998379978725,116.66104650067415 39.878936406324584"
}],
"beuZhu": "备注",
"name": "名称",
"dname": "名称",
"chumian": "116.66057343849101 39.878998379978725,116.66168181148171 39.877088637377696,116.66020113347075 39.87741533324694,116.6603056469199 39.87785975964694,116.66057343849101 39.878998379978725",
"mianJi": 59.70174,
"cid": 96,
"fmian": "116.66098512412566 39.878644199658595,116.66101080875922 39.87880553596932,116.66192176882271 39.877114911394074,116.66185957604523 39.87737713667309,116.66156809207223 39.877335496105445,116.66075907533013 39.877567493553556,116.66086020242278 39.87792441270449,116.66098512412566 39.878644199658595",
"fmianJi": 2.0145
}]
}
1.获取数据
根据地块的id和分期建设的id,根据两个id去两个表里面查数据,两个地块是否相交
ycddbBox: function(data) {
ak_right_fqjstc.removeCdmap();
viewer.entities.removeAll();
console.log(data);
// 关闭左侧
ak_right.closeLeft();
$("#ycbdcdb_panel").css('top', '20%');
$("#ycbdcdb_panel").css('left', '5%');
showDivPanel("#ycbdcdb_panel")
var options = new Object();
var temp = {};
temp.cWaiId = data.tudiBian;
temp.fqjsId = data.id;
temp.type = 1;
options.url = "/manage-api/baseFenQiJstc/duiBi";
options.type = "GET";
options.data = temp;
options.errorback = akglobe_config.errBack;
options.callback = function(data) {
if (!data) return;
console.log(data);
var object = data.rows[0];
ak_right_fqjstc.ycddbText(object);
}
akglobe_config.ajaxQuery(options);
},
2.被比对的面
// 初步调查的面
getCbMap: function(object) {
var db = object;
var name = object.name;
var id = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
db.addtypemarker = config.addtypemarker.polygon;
var lnglatList = []; //经纬度数组
var geoXyz = object.chumian;
var xyzList = geoXyz.split(",");
for (var j = 0; j < xyzList.length; j++) {
var xyz = xyzList[j].split(" ");
if (j == 0) {
db.x = parseFloat(xyz[0]);
db.y = parseFloat(xyz[1]);
}
var sm1 = [];
sm1.push(parseFloat(xyz[0]));
sm1.push(parseFloat(xyz[1]));
sm1.push(parseFloat(xyz[2]));
lnglatList.push(sm1);
}
var mianJi = object.mianJi;
mianJi = mianJi.toFixed(2)
mianJi = mianJi + '㎡'
var positions = cCesium.lnglatArrToCartesianArr(lnglatList); //经纬度转为笛卡尔坐标系
if (positions) {
console.log(positions)
var positionPointer = positions[2];
var lnglat = cCesium.cartesianToLnglat(positionPointer);
var newLnglat = Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1], 5);
var c001 = newLnglat;
db.cartesianList = positions; //将转换后的坐标放入到对象中 在编辑的时候直接使用
var proper = new Cesium.PropertyBag(db);
var options = new Object();
options.material = Cesium.Color.DARKKHAKI.withAlpha(0.8);
//options.material =Cesium.Color.DARKKHAKI;
// options.extrudedHeight = 200; //
var polygonInit = new geo_draw_polygon(options);
polygonInit.createGon(positions);
polygonInit.polygon.properties = proper;
// var polyPositions = polygonInit.polygon.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;//properties.hierarchy
// var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center;//中心点
// polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
// 添加label
var hdObj = {
position: c001,
label: {
backgroundColor: Cesium.Color.fromCssColorString('#000'),
// position: c001,
text: "初步调查面积是" + mianJi,
color: Cesium.Color.white,
fillColor: Cesium.Color.white,
font: 'normal 24px MicroSoft YaHei',
showBackground: true,
scale: 0.5,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
}
}
viewer.entities.add(hdObj);
}
var jsonstr = JSON.stringify(db); //将json对象转换为json字符串
},
parseFloat() 函数可解析一个字符串,并返回一个浮点数
根据返回面坐标数据进行绘制面的图形:
var positions = cCesium.lnglatArrToCartesianArr(lnglatList); //经纬度转为笛卡尔坐标系
if (positions) {
console.log(positions)
var positionPointer = positions[2];
var lnglat = cCesium.cartesianToLnglat(positionPointer);
var newLnglat = Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1], 5);
var c001 = newLnglat;
db.cartesianList = positions; //将转换后的坐标放入到对象中 在编辑的时候直接使用
var proper = new Cesium.PropertyBag(db);
var options = new Object();
options.material = Cesium.Color.DARKKHAKI.withAlpha(0.8);
//options.material =Cesium.Color.DARKKHAKI;
// options.extrudedHeight = 200; //
var polygonInit = new geo_draw_polygon(options);
polygonInit.createGon(positions);
polygonInit.polygon.properties = proper;
}
添加label:
var hdObj = {
position: c001,
label: {
backgroundColor: Cesium.Color.fromCssColorString('#000'),
// position: c001,
text: "初步调查面积是" + mianJi,
color: Cesium.Color.white,
fillColor: Cesium.Color.white,
font: 'normal 24px MicroSoft YaHei',
showBackground: true,
scale: 0.5,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
}
}
viewer.entities.add(hdObj);
3.分类数据
ycddbText: function(object) {
ak_right_fqjstc.getCbMap(object)
// title
var name = object.name;
var title = name + '图形与初调图形对比结果如下:';
var mianjiName = name + '图形面积';
$("#ycbdcdb_panel_title_top").text(title);
$("#ycbdcdb_panel_nameMj").text(mianjiName);
// 是否包含
var baohan = object.baohan;
// 初步调查的面积
if (object.mianJi) {
var mianJi = object.mianJi;
mianJi = mianJi.toFixed(2)
mianJi = mianJi + '㎡'
$("#ycbdcdb_panel_cdtxmj").text(mianJi);
}
// 分期建设的面积
if (object.fmianJi) {
var fmianJi = object.fmianJi;
fmianJi = fmianJi.toFixed(2)
fmianJi = fmianJi + '㎡'
$("#ycbdcdb_panel_jstxmj").text(fmianJi);
}
if (baohan == 't') {
ak_right_fqjstc.getBhMap(object);
$("#ycbdcdb_panel_sfbh").text('是');
$("#ycbdcdb_panel_sfbh").css('color', 'red');
} else if (baohan == 'f') {
$("#ycbdcdb_panel_sfbh").css('color', '#00FFFF');
$("#ycbdcdb_panel_sfbh").text('否');
}
},
判断是包含
if (baohan == 't') {
ak_right_fqjstc.getBhMap(object);
$("#ycbdcdb_panel_sfbh").text('是');
$("#ycbdcdb_panel_sfbh").css('color', 'red');
判断不包含
} else if (baohan == 'f') {
$("#ycbdcdb_panel_sfbh").css('color', '#00FFFF');
$("#ycbdcdb_panel_sfbh").text('否');
}
4.包含面
getBhMap: function(object) {
var db = object;
var name = object.name;
var id = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
db.addtypemarker = config.addtypemarker.polygon;
var lnglatList = []; //经纬度数组
var geoXyz = object.fmian;
var xyzList = geoXyz.split(",");
for (var j = 0; j < xyzList.length; j++) {
var xyz = xyzList[j].split(" ");
if (j == 0) {
db.x = parseFloat(xyz[0]);
db.y = parseFloat(xyz[1]);
}
var sm1 = [];
sm1.push(parseFloat(xyz[0]));
sm1.push(parseFloat(xyz[1]));
sm1.push(parseFloat(xyz[2]));
lnglatList.push(sm1);
}
var xiangMianJi = object.xiangMianJi;
xiangMianJi = xiangMianJi.toFixed(2)
xiangMianJi = xiangMianJi + '㎡'
var positions = cCesium.lnglatArrToCartesianArr(lnglatList); //经纬度转为笛卡尔坐标系
if (positions) {
console.log(positions)
var positionPointer = positions[2];
db.cartesianList = positions; //将转换后的坐标放入到对象中 在编辑的时候直接使用
var proper = new Cesium.PropertyBag(db);
var options = new Object();
options.material = Cesium.Color.RED.withAlpha(0.8);
//options.material =Cesium.Color.DARKKHAKI;
options.extrudedHeight = 200; //
var polygonInit = new geo_draw_polygon(options);
polygonInit.createGon(positions);
polygonInit.polygon.properties = proper;
var polyPositions = polygonInit.polygon.polygon.hierarchy.getValue(Cesium.JulianDate.now())
.positions; //properties.hierarchy
var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; //中心点
polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
var lnglat = cCesium.cartesianToLnglat(polyCenter);
var newLnglat = Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1], 412);
var c001 = newLnglat;
var hiline = ak_marker.heightLine(lnglat[0], lnglat[1], 412);
var hlineEntine = viewer.entities.add(hiline);
// 添加label
var hdObj = {
position: c001,
label: {
showBackground: true, //指定标签后面背景的可见性。
backgroundColor: Cesium.Color.fromCssColorString('#000'),
text: "包含的面积是" + xiangMianJi,
color: Cesium.Color.RED,
fillColor: Cesium.Color.YELLOW,
font: 'normal 24px MicroSoft YaHei',
scale: 0.5,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
}
}
viewer.entities.add(hdObj);
}
var jsonstr = JSON.stringify(db); //将json对象转换为json字符串
},
判断是否包含,如果包含则根据返回的面数据进行绘制面图形,并且给了图形高度
if (positions) {
console.log(positions)
var positionPointer = positions[2];
db.cartesianList = positions; //将转换后的坐标放入到对象中 在编辑的时候直接使用
var proper = new Cesium.PropertyBag(db);
var options = new Object();
options.material = Cesium.Color.RED.withAlpha(0.8);
//options.material =Cesium.Color.DARKKHAKI;
options.extrudedHeight = 200; //
var polygonInit = new geo_draw_polygon(options);
polygonInit.createGon(positions);
polygonInit.polygon.properties = proper;
var polyPositions = polygonInit.polygon.polygon.hierarchy.getValue(Cesium.JulianDate.now())
.positions; //properties.hierarchy
var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; //中心点
polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
var lnglat = cCesium.cartesianToLnglat(polyCenter);
var newLnglat = Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1], 412);
var c001 = newLnglat;
var hiline = ak_marker.heightLine(lnglat[0], lnglat[1], 412);
var hlineEntine = viewer.entities.add(hiline);
}
添加label
var hdObj = {
position: c001,
label: {
showBackground: true, //指定标签后面背景的可见性。
backgroundColor: Cesium.Color.fromCssColorString('#000'),
text: "包含的面积是" + xiangMianJi,
color: Cesium.Color.RED,
fillColor: Cesium.Color.YELLOW,
font: 'normal 24px MicroSoft YaHei',
scale: 0.5,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
}
}
5.后台代码
/**
* 比对
*/
@RequestMapping(value = "/duiBi", method = RequestMethod.GET)
public Map chuBi(HttpServletRequest request) {
Map paramMap = getParameters(request);
Map mapuser= getParametersUserinfo(request);
Map ret = new HashMap();
Map page = new HashMap();
// 统一校验 传入的参数是否有特殊字符 或者 sql 注入 等保需要 校验
if (paramMap.containsKey("flagTGG1001") && !StringUtils.isEmpty(paramMap.get("flagTGG1001"))) {
ret.put("flag", false);
ret.put("msg", StatusCode.C00511.getMsg());
ret.put("status",StatusCode.C00511.getCode());
ret.put("total", 0);
ret.put("rows", null);
return ret;
}
Integer userid=Integer.parseInt(mapuser.get("userid").toString());
List<TBaseWuranFqjstc> list = null;
List<TBaseWuranFqjstc> list2 = null;
TBaseWuranFqjstc list3 = null;
Integer usertype=Integer.parseInt(mapuser.get("usertype").toString());
if(usertype!=1) {
page.put("createUser",userid);
}
if (paramMap.containsKey("cWaiId")
&&!StringUtils.isEmpty(paramMap.get("cWaiId"))) {
Integer cWaiId=Integer.parseInt(paramMap.get("cWaiId").toString());
page.put("cWaiId", cWaiId );
}
if (paramMap.containsKey("fqjsWaiId")
&&!StringUtils.isEmpty(paramMap.get("fqjsWaiId"))) {
Integer fqjsWaiId=Integer.parseInt(paramMap.get("fqjsWaiId").toString());
page.put("fqjsWaiId", fqjsWaiId );
}
if (paramMap.containsKey("fqjsId")
&&!StringUtils.isEmpty(paramMap.get("fqjsId"))) {
Integer fqjsId=Integer.parseInt(paramMap.get("fqjsId").toString());
page.put("fqjsId", fqjsId );
}
Integer type=Integer.parseInt(paramMap.get("type").toString());
Map maps=new HashMap();
ArrayList at=new ArrayList();
list= objServices.chuBu(page);
if(list!=null && !list.isEmpty()) {
maps.put("name", list.get(0).getName());
maps.put("beuZhu", list.get(0).getBeuZhu());
maps.put("cid", list.get(0).getcId());
maps.put("fid", list.get(0).getfId());
maps.put("dname", list.get(0).getDiname());
String geom = list.get(0).getChuMian();
String geolist = geom.substring(geom.indexOf("(") + 3, geom.indexOf(")"));
maps.put("chumian", geolist);
String geom2 = list.get(0).getfMian();
String geolist2 = geom2.substring(geom2.indexOf("(") + 3, geom2.indexOf(")"));
maps.put("fmian", geolist2);
maps.put("baohan", list.get(0).getBaoHan());
maps.put("xiangjiao", list.get(0).getXiangJiao());
maps.put("mianJi", list.get(0).getMianJi());
maps.put("fmianJi", list.get(0).getFmianJi());
}else{
maps.put("name","");
maps.put("beuZhu","");
maps.put("cid","");
maps.put("fid","");
maps.put("dname","");
maps.put("chumian","");
maps.put("fmian","");
maps.put("baohan","");
maps.put("xiangjiao","");
maps.put("xiangMian", "");
maps.put("feiMian", "");
maps.put("mianJi", "");
maps.put("fmianJi","");
maps.put("xiangMianJi","");
}
at.add(maps);
ret.put("rows", at);
return ret;
}
<select id="cbbd" resultMap="TObjectMap" useCache="false">
SELECT
p1.id as cid,
p2.id as fid,
p2.NAME,
p2.beu_zhu,
p1.NAME AS dname,
ST_AsText(p1.geometry) as chumian,
ST_AsText(p2.geometry) as fmian,
ST_Contains ( p1.geometry, p2.geometry ) AS baohan,
ST_NumGeometries ( ST_Intersection ( p1.geometry, p2.geometry ) ) > 0 AS xiangjiao,
st_disjoint ( p1.geometry, p2.geometry ) AS fenli,
st_area ( ST_Transform (p1.geometry, 4527 )) as mianji,
st_area ( ST_Transform (p2.geometry, 4527 )) as fmianji
FROM
t_base_wuran_mdkxx AS p1,
t_base_wuran_fqjstc AS p2
<include refid="findPage_where"/>
<include refid="limit"/>
</select>
是否绝对包含 SELECT ST_Contains(p1.geometry, p2.geometry) AS baohanFROM t_base_wuran_fqjstc AS p2,t_base_wuran_mdkxx AS p1where p1.wai_id=58 and p2.tudi_bian=58
sql: SELECT p1.id as cid, p2.id as fid, p2.NAME, p2.beu_zhu, p1.NAME AS dname, ST_AsText(p1.geometry) as chumian, ST_AsText(p2.geometry) as fmian, ST_Contains ( p1.geometry, p2.geometry ) AS baohan,st_area ( ST_Transform (p1.geometry, 4527 )) as mianji, st_area ( ST_Transform (p2.geometry, 4527 )) as fmianji FROM t_base_wuran_mdkxx AS p1, t_base_wuran_fqjstc AS p2 WHERE p1.wai_id = 102 AND p2.id = 27