|
@@ -275,56 +275,43 @@ export function useAMap(options) {
|
|
|
};
|
|
|
let maskPolygon2 = [];
|
|
|
const creatMask2 = (data, option) => {
|
|
|
- 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 data2 = mergeGeoJsonPolygons(data);
|
|
|
- data2.geometry.coordinates.forEach((coords) => {
|
|
|
- pathArray.push(coords[0]);
|
|
|
- });
|
|
|
- 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
|
|
|
- });
|
|
|
- map.add(maskPolygon);
|
|
|
- // 边界部分
|
|
|
- data.features.forEach((feature) => {
|
|
|
- if (feature.geometry.type === 'Polygon') {
|
|
|
- const polygonPath = feature.geometry.coordinates[0].map((coord) => {
|
|
|
- return [coord[0], coord[1]];
|
|
|
- });
|
|
|
- const polygon = new AMap.Polygon({
|
|
|
- path: polygonPath,
|
|
|
- strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
|
|
|
- strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
|
|
|
- strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
|
|
|
- fillOpacity: 0
|
|
|
- });
|
|
|
- maskPolygon2.push(polygon);
|
|
|
- map.add(polygon);
|
|
|
- } else if (feature.geometry.type === 'MultiPolygon') {
|
|
|
- feature.geometry.coordinates.forEach((polygonCoords) => {
|
|
|
- const polygonPath = polygonCoords.map((ring) => {
|
|
|
- return ring.map((coord) => {
|
|
|
- return [coord[0], coord[1]];
|
|
|
- });
|
|
|
+ if (maskPolygon2 && maskPolygon2.length > 0) {
|
|
|
+ maskPolygon2.forEach((polygon) => {
|
|
|
+ polygon.show();
|
|
|
+ });
|
|
|
+ } 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 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') {
|
|
|
+ const polygonPath = feature.geometry.coordinates[0].map((coord) => {
|
|
|
+ return [coord[0], coord[1]];
|
|
|
});
|
|
|
- const outerPath = polygonPath[0];
|
|
|
- const innerPaths = polygonPath.slice(1);
|
|
|
const polygon = new AMap.Polygon({
|
|
|
- path: outerPath,
|
|
|
- holes: innerPaths,
|
|
|
+ path: polygonPath,
|
|
|
strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
|
|
|
strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
|
|
|
strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
|
|
@@ -332,20 +319,38 @@ export function useAMap(options) {
|
|
|
});
|
|
|
maskPolygon2.push(polygon);
|
|
|
map.add(polygon);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
- const removeMask2 = () => {
|
|
|
- if (!!maskPolygon) {
|
|
|
- map.remove(maskPolygon);
|
|
|
- maskPolygon = null;
|
|
|
+ } else if (feature.geometry.type === 'MultiPolygon') {
|
|
|
+ feature.geometry.coordinates.forEach((polygonCoords) => {
|
|
|
+ const polygonPath = polygonCoords.map((ring) => {
|
|
|
+ return ring.map((coord) => {
|
|
|
+ return [coord[0], coord[1]];
|
|
|
+ });
|
|
|
+ });
|
|
|
+ const outerPath = polygonPath[0];
|
|
|
+ const innerPaths = polygonPath.slice(1);
|
|
|
+ const polygon = new AMap.Polygon({
|
|
|
+ path: outerPath,
|
|
|
+ holes: innerPaths,
|
|
|
+ strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
|
|
|
+ strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
|
|
|
+ strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
|
|
|
+ fillOpacity: 0
|
|
|
+ });
|
|
|
+ maskPolygon2.push(polygon);
|
|
|
+ map.add(polygon);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ };
|
|
|
+ const removeMask2 = (isHidden) => {
|
|
|
if (maskPolygon2 && maskPolygon2.length > 0) {
|
|
|
maskPolygon2.forEach((polygon) => {
|
|
|
- map.remove(polygon);
|
|
|
+ polygon.hide();
|
|
|
});
|
|
|
- maskPolygon2 = [];
|
|
|
+ if (!isHidden) {
|
|
|
+ maskPolygon2 = [];
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
let moveMarker, movePolyline, movePassedPolyline, timerId;
|