|
@@ -15,7 +15,7 @@ CityLandAction.prototype = {
|
|
|
createStatus : false,
|
|
|
create(){
|
|
|
let that = this
|
|
|
- this.obj.getTileLayer()
|
|
|
+ this.obj.createTileLayer()
|
|
|
this.tempVectorLayer = this.loadTempVectorLayer()
|
|
|
this.drawMultiPolygon = new DrawMultiPolygon({vector: this.tempVectorLayer, map: this.context.currentMap,wkt: this.context.wkt})
|
|
|
|
|
@@ -46,10 +46,10 @@ CityLandAction.prototype = {
|
|
|
return
|
|
|
}
|
|
|
// this.context.clicks[this.id] = this
|
|
|
+ this.obj.addTileLayer(this.context.currentMap)
|
|
|
this.drawMultiPolygon.show()
|
|
|
-
|
|
|
this.tempVectorLayer.setVisible(true)
|
|
|
-
|
|
|
+ this.context.landFilter()
|
|
|
this.context.getSldStyleSign(this.obj.wmsData.params.STYLE)
|
|
|
this.startStatus = true;
|
|
|
|
|
@@ -61,9 +61,7 @@ CityLandAction.prototype = {
|
|
|
return
|
|
|
}
|
|
|
this.tempVectorLayer.setVisible(false)
|
|
|
- for(let layer of this.obj.layerData.layer){
|
|
|
- this.context.currentMap.removeLayer(layer)
|
|
|
- }
|
|
|
+ this.obj.removeTileLayer(this.context.currentMap)
|
|
|
console.log("drawMultiPolygon close")
|
|
|
this.drawMultiPolygon.close()
|
|
|
console.log("tempVectorLayer cleared")
|
|
@@ -144,18 +142,18 @@ CityLandAction.prototype = {
|
|
|
let source = this.tempVectorLayer.getSource();
|
|
|
source.addFeature(point)
|
|
|
},
|
|
|
- newFieldPoint(f){
|
|
|
- let centerPoint = f.get("center_point")
|
|
|
+ newFieldPoint(data){
|
|
|
+ let geom = this.context.geojson.readGeometry(data["geojson"])
|
|
|
let point = new ol.Feature({
|
|
|
- geometry: new ol.geom.Point(centerPoint.coordinates)
|
|
|
+ geometry: geom
|
|
|
});
|
|
|
- for(let key of f.getKeys()){
|
|
|
- if(key != "geometry"){
|
|
|
- point.set(key,f.get(key))
|
|
|
+ for(let key in data){
|
|
|
+ if(key != "geojson"){
|
|
|
+ point.set(key,data[key])
|
|
|
}
|
|
|
}
|
|
|
point.set("isPoint",1)
|
|
|
- point.setId(f.get("id"))
|
|
|
+ point.setId(data["id"])
|
|
|
return point;
|
|
|
}
|
|
|
,loadTempVectorLayer(){
|
|
@@ -166,12 +164,16 @@ CityLandAction.prototype = {
|
|
|
format: new ol.format.GeoJSON(),
|
|
|
loader: function(extent, resolution, projection, success, failure) {
|
|
|
const proj = projection.getCode();
|
|
|
- const url = baseUrl + '?service=WFS&' +
|
|
|
- 'version=1.1.0&request=GetFeature&typename=wuhan:p_crop&' +
|
|
|
- 'outputFormat=application/json&srsname=' + proj + '&' +
|
|
|
- 'bbox=' + extent.join(',') + ',' + proj;
|
|
|
+ let typeNames = that.obj.getVisibleLayers()
|
|
|
+ console.log(typeNames)
|
|
|
+ let projCode = "3857"
|
|
|
+ if(typeNames == ""){
|
|
|
+ typeNames = "p_crop"
|
|
|
+ projCode = "4326"
|
|
|
+ }
|
|
|
+
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
- xhr.open('GET', url);
|
|
|
+ xhr.open('GET', "/crop/getGeoJson?tableNames="+typeNames + "&x1=" + extent[0] + "&y1=" + extent[1]+"&x2=" + extent[2] + "&y2="+extent[3]);
|
|
|
const onError = function() {
|
|
|
vectorSource.removeLoadedExtent(extent);
|
|
|
failure();
|
|
@@ -179,17 +181,17 @@ CityLandAction.prototype = {
|
|
|
xhr.onerror = onError;
|
|
|
xhr.onload = function() {
|
|
|
if (xhr.status == 200) {
|
|
|
- const features = vectorSource.getFormat().readFeatures(xhr.responseText);
|
|
|
- vectorSource.addFeatures(features);
|
|
|
- for(let feature of features){
|
|
|
- let id = feature.getId().substring(feature.getId().indexOf(".") + 1)
|
|
|
- feature.set("id",id)
|
|
|
- let area = feature.getGeometry().getArea()
|
|
|
- area = (area + area / 2) / 1000
|
|
|
- feature.set("area", area.toFixed(2));
|
|
|
- vectorSource.addFeature(that.newFieldPoint(feature))
|
|
|
+ let res = JSON.parse(xhr.responseText);
|
|
|
+ if(res.code == 0){
|
|
|
+ let features = []
|
|
|
+ let datas = res.data;
|
|
|
+ for(let data of datas){
|
|
|
+ let feature = that.newFieldPoint(data,projCode)
|
|
|
+ vectorSource.addFeature(feature)
|
|
|
+ features.push(feature)
|
|
|
+ }
|
|
|
+ success(features);
|
|
|
}
|
|
|
- success(features);
|
|
|
} else {
|
|
|
onError();
|
|
|
}
|
|
@@ -285,12 +287,36 @@ function CityLand(opt){
|
|
|
}
|
|
|
|
|
|
CityLand.prototype = {
|
|
|
+ visibleLayers:[],
|
|
|
+ getVisibleLayers(){
|
|
|
+ let names = "";
|
|
|
+ let i = 0;
|
|
|
+ for(let layerName of this.visibleLayers){
|
|
|
+ if(i > 0){
|
|
|
+ names += ","
|
|
|
+ }
|
|
|
+ names += layerName
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return names;
|
|
|
+ },
|
|
|
layerNames:['wuhan:p_land_banan','wuhan:p_land_beibei','wuhan:p_land_bishan','wuhan:p_land_changshou','wuhan:p_land_chengkou','wuhan:p_land_dadukou','wuhan:p_land_dazu','wuhan:p_land_dianjiang','wuhan:p_land_fengdu','wuhan:p_land_fengjie','wuhan:p_land_fuling','wuhan:p_land_hechuan','wuhan:p_land_jiangbei','wuhan:p_land_jiangjin','wuhan:p_land_jiulongpo','wuhan:p_land_kaizhou','wuhan:p_land_liangping','wuhan:p_land_nanan','wuhan:p_land_nanchuan','wuhan:p_land_pengshui','wuhan:p_land_qianjiang','wuhan:p_land_qijiang','wuhan:p_land_qiuyang','wuhan:p_land_rongchang','wuhan:p_land_shapingba','wuhan:p_land_shizhu','wuhan:p_land_tongliang','wuhan:p_land_tongnan','wuhan:p_land_wanzhou','wuhan:p_land_wulong','wuhan:p_land_wushan','wuhan:p_land_wuxi','wuhan:p_land_xiushan','wuhan:p_land_yongchuan','wuhan:p_land_yubei','wuhan:p_land_yunyang','wuhan:p_land_yuzhong','wuhan:p_land_zhong','wuhan:p_crop'],
|
|
|
- getTileLayer(){
|
|
|
+ createTileLayer(){
|
|
|
for(let layer of this.layerNames){
|
|
|
this.getWMTS(layer)
|
|
|
}
|
|
|
- },getWMS(){
|
|
|
+ },
|
|
|
+ addTileLayer(map){
|
|
|
+ for(let layer of this.layerData.layer){
|
|
|
+ map.addLayer(layer)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ removeTileLayer(map){
|
|
|
+ for(let layer of this.layerData.layer){
|
|
|
+ map.removeLayer(layer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ,getWMS(){
|
|
|
this.layerData.source = new ol.source.ImageWMS({
|
|
|
ratio: 1,
|
|
|
url: 'http://change.zylfsm.com/geoserver/wuhan/wms',
|
|
@@ -334,20 +360,26 @@ CityLand.prototype = {
|
|
|
wrapX: true
|
|
|
})
|
|
|
this.layerData.source.push(source);
|
|
|
-
|
|
|
- this.layerData.layer.push(new ol.layer.Tile({
|
|
|
+ let tile = new ol.layer.Tile({
|
|
|
source: source,
|
|
|
zIndex: 2,
|
|
|
minZoom: 7,
|
|
|
- maxZoom: 30
|
|
|
- }));
|
|
|
+ maxZoom: 30,
|
|
|
+ visible: false,
|
|
|
+ properties:{"name":typeName.substring(typeName.indexOf(":") + 1)}
|
|
|
+ })
|
|
|
+ this.layerData.layer.push(tile);
|
|
|
+ return tile;
|
|
|
},
|
|
|
- loadWMTS(tableNames){
|
|
|
- for(let layer of this.obj.layerData.layer){
|
|
|
- for(let tableName of tableNames){
|
|
|
- asd12312" "
|
|
|
+ visibleWMTS(tableNames){
|
|
|
+ console.log(tableNames)
|
|
|
+ this.visibleLayers = tableNames
|
|
|
+ for(let layer of this.layerData.layer){
|
|
|
+ if(tableNames.includes(layer.get("name"))){
|
|
|
+ layer.setVisible(true)
|
|
|
+ }else{
|
|
|
+ layer.setVisible(false)
|
|
|
}
|
|
|
- this.context.currentMap.addLayer(layer)
|
|
|
}
|
|
|
}
|
|
|
}
|