效果
数据结构
1.简单实例
单纯的绘制缓冲器,采用akglobe封装的方法,并将数据放入到数组内
var id = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
var db = data;
var name = db.name;
var jwd = db.value;
var obj = new Object();
obj.id = id;
obj.name = db.name;
obj.address = db.address;
obj.lat = db.x;
obj.lng = db.y;
obj.z = 60;
obj.tag = 1;
obj.code = db.countrycode;
obj.addtypemarker = config.addtypemarker.common2;
obj.attributes = obj; // 设置属性
obj.radius = ak_xq_syj.cm; //设置半径
obj.color = new Cesium.Color(1.0, 1.0, 0.0, 0.5); //设置颜色
var tt = new geo_circle(obj);
tt.draw();
ak_xq_syj.circleArr.push(tt);
说明:
obj.addtypemarker = config.addtypemarker.common2; 设置了他的类型 在Popu.js内识别
属性设置,方便识别这个缓冲区圆
obj.attributes = obj; // 设置属性
obj.radius = ak_xq_syj.cm; //设置半径
obj.color = new Cesium.Color(1.0, 1.0, 0.0, 0.5); //设置颜色
var tt = new geo_circle(obj);
tt.draw();
放到数组内,方便清除
ak_xq_syj.circleArr.push(tt);
2.正式代码
2.1查数据
这个功能不是点击地图形成缓冲区,而是根据 这个已经标注的点位,所以根据这个标注的点位编码先去查询数据获取XY ,根据XY在去做缓冲区:
// 获取缓冲区的数据
getData2: function() {
var options = new Object();
var temp = {}
temp.id = ak_xq_syj.id;
options.url = "/manage-api/baseDaiDiao/getbyId";
options.type = "GET";
options.data = temp;
options.errorback = akglobe_config.errBack;
options.callback = function(data) {
if (!data) return;
console.log(data)
// var x = data.x;
// var y = data.y;
ak_xq_syj.setYuan(data);
ak_xq_syj.getDataMi(data);
}
akglobe_config.ajaxQuery(options);
},
2.2生成缓冲区
获取DB内的XY
// 生成缓冲区的方法
setYuan: function(data) {
//clickSaoMiao clicklabelNew2
var id = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
var db = data;
var name = db.name;
var jwd = db.value;
var obj = new Object();
obj.id = id;
obj.name = db.name;
obj.address = db.address;
// // 为飞行处理
// obj.latitude=jwd[0];
// obj.longitude=jwd[1];
obj.lat = db.x;
obj.lng = db.y;
obj.z = 60;
obj.tag = 1;
obj.code = db.countrycode;
obj.addtypemarker = config.addtypemarker.common2;
obj.attributes = obj; // 设置属性
obj.radius = ak_xq_syj.cm; //设置半径
obj.color = new Cesium.Color(1.0, 1.0, 0.0, 0.5); //设置颜色
var tt = new geo_circle(obj);
tt.draw();
ak_xq_syj.circleArr.push(tt);
},
2.3获取缓冲区的点位数据
缓冲区形成后 根据 XY 半径进行 后台缓冲区查询
// 获取缓冲区内的点位数据
getDataMi: function(data) {
var options = new Object();
var temp = {}
temp.x = data.x;
temp.y = data.y;
temp.mi = ak_xq_syj.cm;
options.url = "/manage-api/fanWei/fanwei";
options.type = "GET";
options.data = temp;
options.errorback = akglobe_config.errBack;
options.callback = function(data) {
if (!data) return;
console.log(data)
ak_xq_syj.clearObject(); //清除数据
ak_xq_syj.objectPositionType(data)
}
akglobe_config.ajaxQuery(options);
},
2.4定位缓冲区中的点位
// 定位缓冲区内的点位
objectPositionType: function(data) {
// ak_nav.clearAll();
this.billboards = scene.primitives.add(new Cesium.BillboardCollection());
var nongcun = data.nongcun;
for (var i = 0; i < nongcun.length; i++) {
var nameClass = '';
nameClass = "农村水源井"
var db = nongcun[i];
var obj = new Object();
var id = db.id;
obj.id = "tzhbWr;" + config.addtypemarker.common + ";" + nameClass + "_" + db.name + ";" + db
.address + ";" + db
.statisticsmonth;
obj.name = db.name;
obj.address = db.address;
obj.lat = db.x;
obj.lng = db.y;
var src = config.markerImgProejctNc; //mark4
obj.src = src;
obj.width = config.markerImgProejctWidth;
obj.height = config.markerImgProejctHeight;
obj.addtypemarker = config.addtypemarker.ceccXm;
ak_pm_tool.addPoint(this.billboards, obj);
}
},
2.5清除
// 清除最近水源井的点位和线
clearObject: function() {
viewer.scene.primitives.remove(this.billboards);
viewer.scene.primitives.remove(this.labels);
viewer.scene.primitives.remove(this.geoCollectionLine1);
for (var i = 0; i < this.gztArr.length; i++) {
var objEntine = this.gztArr[i];
objEntine.destroy();
}
},
// 清除缓冲区
clearPositionYuan: function() {
for (var i = 0; i < this.circleArr.length; i++) {
var objEntine = this.circleArr[i];
objEntine.destroy();
}
},
2.6后台代码
范围是多少米,例:500米,1000米
Integer mi= Integer.valueOf(mapuser.get("mi").toString()); Double jie= Double.valueOf(mi/1000.0*0.01);
@RequestMapping(value = "/fanwei", method = RequestMethod.GET)
public Map fanwei(HttpServletRequest request) {
Map map = new HashMap();
Map mapuser= getParametersUserinfo(request);
Integer mi= Integer.valueOf(mapuser.get("mi").toString());
Double jie= Double.valueOf(mi/1000.0*0.01);
logger.info(String.valueOf(Double.valueOf(mi/1000.0*0.01)));
StringBuilder sbd = new StringBuilder();
sbd.append(" select name,ST_AsText(geom) as geom,____2 as x,____3 as y from geo_nongcun_shuiyuanjing_point a where ST_Intersects(a.geom, ");
sbd.append(" st_buffer(ST_SetSrid(ST_MakePoint(");
sbd.append(mapuser.get("x").toString()+","+mapuser.get("y").toString());
sbd.append("),4326),");
sbd.append(jie);
sbd.append("))");
String sql = sbd.toString();
List list = jdbcTemplate.queryForList(sql);
map.put("nongcun", list);
System.out.println(sql);
return map;
}
2.6.1缓冲区形成作为一个几何对象 和点图层去相交
2.6.1.1先形成缓冲区
st_buffer 函数可以创建多种类型的缓冲区,包括圆形缓冲区多边形缓冲区和几何对象缓冲区。使用不同的参数组合可以创建不同类型的缓冲区。
0.005 代表半径时500米
SELECT ST_Buffer(ST_SetSrid(ST_MakePoint(116.55,39.55),4326,0.005)
2.6.1.2相交
ST_Intersects简单的说就是判断geometry geomA 与geometry geomB 是否存在geometry格式的交集;也可以判断geography geogA 与 geography geogB 是否存在geography这种类型的交集。
SELECT ST_Intersects('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry); st_intersects
如程序中的语句
sbd.append(" select name,ST_AsText(geom) as geom,____2 as x,____3 as y from geo_nongcun_shuiyuanjing_point a where ST_Intersects(a.geom, ");
sbd.append(" st_buffer(ST_SetSrid(ST_MakePoint(");
sbd.append(mapuser.get("x").toString()+","+mapuser.get("y").toString());
sbd.append("),4326),");
ST_Intersects 后面的a.geom 就是 点的几何对象, 后面的 几何对象时 缓冲区 , 缓冲区作为一个面 进行和点相交 查询
sql:select name,ST_AsText(geom) as geom,____2 as x,____3 as y from geo_nongcun_shuiyuanjing_point a where ST_Intersects(a.geom, st_buffer(ST_SetSrid(ST_MakePoint(116.749025,39.636772),4326),0.005))