const wfsConfig = { url: "", layer: "", color: "", property: "", keyVal: "", polygonLayer: null, wfsLayer: null, // 参数初始化 Init() { this.url = "https://cim.smartearth.cn/SEserver/wfsserver/SubicBayAreaVector_wfs"; this.layer = "GeoEntity"; this.color = "#f40824"; this.keyVal = "市政"; this.setPolyGonStart(); }, //wfsLayer初始化 setPolyGonStart() { this.polygonLayer = earthCtrl.factory.createWfsLayer("polygon", { urls: this.url, layer: this.layer, color: this.color, extrudedHeight: 100, // 拉伸高度,无拉伸高度则为贴地面 extrudedkey: "ELEVATION" }); this.setWfsLayerStart(); }, //wfsLayer初始化 setWfsLayerStart() { this.wfsLayer = new OpenLayers.Protocol.WFS({ version: "1.1.0", url: this.url, layer: this.layer }); this.setLayerQuery(); }, setLayerQuery() { const filter = new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.EQUAL_TO, property: "SJFL", value: this.keyVals }); var that = this; console.log(this.wfsLayer); that.wfsLayer.read({ filter: filter, callback: function (result) { console.log(1231,result); if (result.success() && result.features.length > 0) { var feature = result.features[0]; // var lon = Number(feature.attributes.lon); // var lat = Number(feature.attributes.lat); that.setLayerQuery2(feature); } } }); }, setLayerQuery2() { var that = this; var wfs2 = new OpenLayers.Protocol.WFS({ version: "1.1.0", url: this.url, featureType: this.layer, geometryName: "TargetType" }); wfs2.read({ filter: new OpenLayers.Filter.Spatial({ type: OpenLayers.Filter.Spatial.DWITHIN, value: feature.geometry, distance: 0.1, distanceUnits: "km" }), callback: function (result) { console.log('w1223',result); if (result.success()) { if (result.features && result.features.length) { that.addFeaturesToMap(result.features); } } } }); }, addFeaturesToMap(features) { const highlightColor = Cesium.Color.YELLOW.withAlpha(0.5); const highlightIds = []; features.forEach((feature) => { const id = feature.attributes.OBJECTID; highlightIds.push(id); }); this.polygonLayer.setHighlightColor(highlightIds, highlightColor); } }; export default wfsConfig;