suerprisePlus
2024-07-16 6069325e1a37cf0462afda1627d4c660735dc57e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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;