Przeglądaj źródła

地图隐藏遮罩

Hwf 8 miesięcy temu
rodzic
commit
a4d3461511
2 zmienionych plików z 54 dodań i 54 usunięć
  1. 21 21
      src/hooks/AMap/useAMap.ts
  2. 33 33
      src/utils/olMap/olMap.ts

+ 21 - 21
src/hooks/AMap/useAMap.ts

@@ -282,28 +282,28 @@ export function useAMap(options) {
     } else {
       data = convertCoordinates(data);
       // 遮罩部分
-      const outer = [
-        new AMap.LngLat(-180, 90, true),
-        new AMap.LngLat(-180, -90, true),
-        new AMap.LngLat(180, -90, true),
-        new AMap.LngLat(180, 90, true)
-      ];
-      const pathArray = [outer];
+      // const outer = [
+      //   new AMap.LngLat(-180, 90, true),
+      //   new AMap.LngLat(-180, -90, true),
+      //   new AMap.LngLat(180, -90, true),
+      //   new AMap.LngLat(180, 90, true)
+      // ];
+      // const pathArray = [outer];
       // 合并区边界
-      const data2 = mergeGeoJsonPolygons(data);
-      data2.geometry.coordinates.forEach((coords) => {
-        pathArray.push(coords[0]);
-      });
-      const maskPolygon = new AMap.Polygon({
-        path: pathArray,
-        strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
-        strokeOpacity: 1,
-        strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
-        fillColor: option.fillColor ? option.fillColor : '#10243b',
-        fillOpacity: option.fillOpacity ? option.fillOpacity : 0.65
-      });
-      maskPolygon2.push(maskPolygon);
-      map.add(maskPolygon);
+      // const data2 = mergeGeoJsonPolygons(data);
+      // data2.geometry.coordinates.forEach((coords) => {
+      //   pathArray.push(coords[0]);
+      // });
+      // const maskPolygon = new AMap.Polygon({
+      //   path: pathArray,
+      //   strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
+      //   strokeOpacity: 1,
+      //   strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
+      //   fillColor: option.fillColor ? option.fillColor : '#10243b',
+      //   fillOpacity: option.fillOpacity ? option.fillOpacity : 0.65
+      // });
+      // maskPolygon2.push(maskPolygon);
+      // map.add(maskPolygon);
       // 边界部分
       data.features.forEach((feature) => {
         if (feature.geometry.type === 'Polygon') {

+ 33 - 33
src/utils/olMap/olMap.ts

@@ -338,39 +338,39 @@ export class olMap {
         this.map.addLayer(layer);
       });
     } else {
-      const layer = new VectorLayer({
-        source: new VectorSource(),
-        style: new Style({
-          fill: new Fill({
-            color: options.fillColor ? options.fillColor : 'rgba(16, 36, 59, 0.65)'
-          }),
-          stroke: new Stroke({
-            color: options.strokeColor ? options.strokeColor : 'rgba(38, 138, 185, 1)',
-            width: 2
-          })
-        }),
-        zIndex: options.zIndex ? options.zIndex : 99
-      });
-      // 合并区边界
-      const format = new GeoJSON();
-      const data2 = mergeGeoJsonPolygons(json);
-      const fs = format.readFeatures(data2);
-      const extent = [-180, -90, 180, 90];
-      const polygonRing = fromExtent(extent);
-      fs.forEach((x) => {
-        const ft = x.values_.geometry;
-        const coords = ft.getCoordinates();
-        coords.forEach((coord) => {
-          const linearRing = new LinearRing(coord[0]);
-          polygonRing.appendLinearRing(linearRing);
-        });
-      });
-      const convertFt = new Feature({
-        geometry: polygonRing
-      });
-      layer.getSource().addFeature(convertFt);
-      this.maskLayer2.push(layer);
-      this.map.addLayer(layer);
+      // const layer = new VectorLayer({
+      //   source: new VectorSource(),
+      //   style: new Style({
+      //     fill: new Fill({
+      //       color: options.fillColor ? options.fillColor : 'rgba(16, 36, 59, 0.65)'
+      //     }),
+      //     stroke: new Stroke({
+      //       color: options.strokeColor ? options.strokeColor : 'rgba(38, 138, 185, 1)',
+      //       width: 2
+      //     })
+      //   }),
+      //   zIndex: options.zIndex ? options.zIndex : 99
+      // });
+      // // 合并区边界
+      // const format = new GeoJSON();
+      // const data2 = mergeGeoJsonPolygons(json);
+      // const fs = format.readFeatures(data2);
+      // const extent = [-180, -90, 180, 90];
+      // const polygonRing = fromExtent(extent);
+      // fs.forEach((x) => {
+      //   const ft = x.values_.geometry;
+      //   const coords = ft.getCoordinates();
+      //   coords.forEach((coord) => {
+      //     const linearRing = new LinearRing(coord[0]);
+      //     polygonRing.appendLinearRing(linearRing);
+      //   });
+      // });
+      // const convertFt = new Feature({
+      //   geometry: polygonRing
+      // });
+      // layer.getSource().addFeature(convertFt);
+      // this.maskLayer2.push(layer);
+      // this.map.addLayer(layer);
       // 边界部分
       json.features.forEach((feature) => {
         if (feature.geometry.type === 'Polygon') {