|
@@ -1,6 +1,7 @@
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
import { nanoid } from 'nanoid';
|
|
import { nanoid } from 'nanoid';
|
|
import { deepClone } from '@/utils';
|
|
import { deepClone } from '@/utils';
|
|
|
|
+import { wgs_gcj_encrypts } from '@/utils/gisUtils';
|
|
|
|
|
|
export function useAMap(options) {
|
|
export function useAMap(options) {
|
|
let AMap, map, nowLayer, labelsLayer, scale, cluster;
|
|
let AMap, map, nowLayer, labelsLayer, scale, cluster;
|
|
@@ -266,12 +267,6 @@ export function useAMap(options) {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- const removeMask = () => {
|
|
|
|
- if (!!maskPolygon) {
|
|
|
|
- map.remove(maskPolygon);
|
|
|
|
- maskPolygon = null;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
const creatMask2 = (data, option) => {
|
|
const creatMask2 = (data, option) => {
|
|
// 外多边形坐标数组和内多边形坐标数组
|
|
// 外多边形坐标数组和内多边形坐标数组
|
|
const outer = [
|
|
const outer = [
|
|
@@ -282,12 +277,13 @@ export function useAMap(options) {
|
|
];
|
|
];
|
|
//outer
|
|
//outer
|
|
const pathArray = [outer];
|
|
const pathArray = [outer];
|
|
|
|
+ data = convertCoordinates(data);
|
|
data.features.forEach((item, index) => {
|
|
data.features.forEach((item, index) => {
|
|
let arr = [];
|
|
let arr = [];
|
|
const geometry = item.geometry;
|
|
const geometry = item.geometry;
|
|
geometry.coordinates.forEach((coordinate) => {
|
|
geometry.coordinates.forEach((coordinate) => {
|
|
if (geometry.type === 'MultiPolygon') {
|
|
if (geometry.type === 'MultiPolygon') {
|
|
- coordinate[0].forEach(coordinate2 => {
|
|
|
|
|
|
+ coordinate[0].forEach((coordinate2) => {
|
|
arr.push(coordinate2);
|
|
arr.push(coordinate2);
|
|
});
|
|
});
|
|
pathArray.push(arr);
|
|
pathArray.push(arr);
|
|
@@ -309,6 +305,12 @@ export function useAMap(options) {
|
|
});
|
|
});
|
|
map.add(maskPolygon);
|
|
map.add(maskPolygon);
|
|
};
|
|
};
|
|
|
|
+ const removeMask = () => {
|
|
|
|
+ if (!!maskPolygon) {
|
|
|
|
+ map.remove(maskPolygon);
|
|
|
|
+ maskPolygon = null;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
let moveMarker, movePolyline, movePassedPolyline, timerId;
|
|
let moveMarker, movePolyline, movePassedPolyline, timerId;
|
|
const trackPlayback = (lineArr) => {
|
|
const trackPlayback = (lineArr) => {
|
|
if (timerId) {
|
|
if (timerId) {
|
|
@@ -495,6 +497,61 @@ export function useAMap(options) {
|
|
data.id = id;
|
|
data.id = id;
|
|
return { text, data };
|
|
return { text, data };
|
|
};
|
|
};
|
|
|
|
+ const convertCoordinates = (geoJson) => {
|
|
|
|
+ const features = geoJson.features.map((feature) => {
|
|
|
|
+ const geometry = feature.geometry;
|
|
|
|
+ let newGeometry;
|
|
|
|
+ if (geometry.type === 'Point') {
|
|
|
|
+ const [x, y] = geometry.coordinates;
|
|
|
|
+ const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
|
|
|
|
+ newGeometry = { ...geometry, coordinates: [obj.lng, obj.lat] };
|
|
|
|
+ } else if (geometry.type === 'MultiPoint') {
|
|
|
|
+ const newCoordinates = geometry.coordinates.map((coords) => {
|
|
|
|
+ const [x, y] = coords;
|
|
|
|
+ const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
|
|
|
|
+ return [obj.lng, obj.lat];
|
|
|
|
+ });
|
|
|
|
+ newGeometry = { ...geometry, coordinates: newCoordinates };
|
|
|
|
+ } else if (geometry.type === 'LineString') {
|
|
|
|
+ const newCoordinates = geometry.coordinates.map((coords) => {
|
|
|
|
+ const [x, y] = coords;
|
|
|
|
+ const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
|
|
|
|
+ return [obj.lng, obj.lat];
|
|
|
|
+ });
|
|
|
|
+ newGeometry = { ...geometry, coordinates: newCoordinates };
|
|
|
|
+ } else if (geometry.type === 'MultiLineString') {
|
|
|
|
+ const newCoordinates = geometry.coordinates.map((line) =>
|
|
|
|
+ line.map((coords) => {
|
|
|
|
+ const [x, y] = coords;
|
|
|
|
+ const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
|
|
|
|
+ return [obj.lng, obj.lat];
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+ newGeometry = { ...geometry, coordinates: newCoordinates };
|
|
|
|
+ } else if (geometry.type === 'Polygon') {
|
|
|
|
+ const newCoordinates = geometry.coordinates.map((ring) => {
|
|
|
|
+ const obj = wgs_gcj_encrypts(ring);
|
|
|
|
+ return obj;
|
|
|
|
+ });
|
|
|
|
+ newGeometry = { ...geometry, coordinates: newCoordinates };
|
|
|
|
+ } else if (geometry.type === 'MultiPolygon') {
|
|
|
|
+ const newCoordinates = geometry.coordinates.map((polygon) =>
|
|
|
|
+ polygon.map((ring) =>
|
|
|
|
+ ring.map((coords) => {
|
|
|
|
+ const [x, y] = coords;
|
|
|
|
+ const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
|
|
|
|
+ return [obj.lng, obj.lat];
|
|
|
|
+ })
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ newGeometry = { ...geometry, coordinates: newCoordinates };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return { ...feature, geometry: newGeometry };
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return { ...geoJson, features };
|
|
|
|
+ };
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
initMap(options);
|
|
initMap(options);
|
|
});
|
|
});
|