useAMap.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. import AMapLoader from '@amap/amap-jsapi-loader';
  2. import { nanoid } from 'nanoid';
  3. import { deepClone } from '@/utils';
  4. import { mergeGeoJsonPolygons, wgs_gcj_encrypts } from '@/utils/gisUtils';
  5. export function useAMap(options) {
  6. let AMap, map, nowLayer, labelsLayer, scale, cluster;
  7. const markers = {
  8. point: []
  9. };
  10. let clickMarker = null;
  11. let addPoints = [];
  12. // 初始化事件
  13. const initMap = (options) => {
  14. window._AMapSecurityConfig = {
  15. securityJsCode: options.securityJsCode
  16. };
  17. AMapLoader.load({
  18. key: options.key, // 申请好的Web端开发者Key,首次调用 load 时必填
  19. version: !!options.version ? options.version : '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  20. plugins: options.plugins
  21. ? options.plugins
  22. : [
  23. 'AMap.Scale',
  24. 'AMap.RangingTool',
  25. 'AMap.MouseTool',
  26. 'AMap.PolygonEditor',
  27. 'AMap.MarkerCluster',
  28. 'AMap.DistrictSearch',
  29. 'AMap.MoveAnimation',
  30. 'AMap.Driving',
  31. 'AMap.Geocoder',
  32. 'AMap.PlaceSearch',
  33. 'AMap.GeoJSON'
  34. ]
  35. }).then((res) => {
  36. AMap = res;
  37. map = new AMap.Map(options.el ? options.el : 'aMap', {
  38. WebGLParams: {
  39. preserveDrawingBuffer: true
  40. },
  41. // 是否为3D地图模式
  42. viewMode: '3D',
  43. pitch: options.pitch,
  44. // 初始化地图级别
  45. zoom: options.zoom ? options.zoom : 11,
  46. // 初始化地图中心点位置
  47. center: options.center,
  48. // 是否可拖拽
  49. dragEnable: options.dragEnable,
  50. // 是否允许通过鼠标滚轮来缩放
  51. scrollWheel: options.scrollWheel
  52. });
  53. // 初始化比例尺
  54. if (options.showScale) {
  55. scale = new AMap.Scale();
  56. map.addControl(scale);
  57. }
  58. if (typeof options.onLoadCompleted === 'function') {
  59. options.onLoadCompleted(AMap, map);
  60. }
  61. });
  62. };
  63. const getAMap = () => {
  64. return AMap;
  65. };
  66. const getMap = () => {
  67. return map;
  68. };
  69. const getScale = () => {
  70. return scale;
  71. };
  72. // 切换地图
  73. const switchMap = (type: string) => {
  74. if (type === 'vectorgraph') {
  75. map.removeLayer(nowLayer);
  76. } else if (type === 'satellite') {
  77. const satellite = new AMap.TileLayer.WMTS({
  78. // url: 'http://t0.tianditu.gov.cn/img_c/wmts',
  79. url: 'http://t4.tianditu.gov.cn/img_w/wmts',
  80. blend: false,
  81. tileSize: 256,
  82. params: {
  83. Layer: 'img',
  84. Version: '1.0.0',
  85. Format: 'tiles',
  86. TileMatrixSet: 'w',
  87. STYLE: 'default',
  88. tk: 'a8df87f1695d224d2679aa805c1268d9' // 申请的天地图开发者key
  89. }
  90. });
  91. satellite.setMap(map);
  92. // const satellite = new AMap.TileLayer.Satellite();
  93. // map.addLayer(satellite);
  94. nowLayer = satellite;
  95. }
  96. };
  97. // 添加搜索的标记的
  98. const addSearchMarker = (item) => {
  99. map.setZoom(18);
  100. map.setCenter(item.lnglat);
  101. addMarker([item], true);
  102. clickMarker = item;
  103. options.onMarkerClick(item);
  104. };
  105. // 添加多个点
  106. const addMarker = (points, notClean?: boolean) => {
  107. if (!notClean) {
  108. clearMarker('point');
  109. }
  110. addPoints = points;
  111. const count = points.length;
  112. const _renderClusterMarker = function (context) {
  113. // 聚合中点个数
  114. const clusterCount = context.count;
  115. const div = document.createElement('div');
  116. div.style.backgroundColor = 'rgba(78,179,211,.5)';
  117. const size = Math.round(25 + Math.pow(clusterCount / count, 1 / 5) * 20);
  118. div.style.width = div.style.height = size + 'px';
  119. div.style.border = 'solid 1px rgba(78,179,211,1)';
  120. div.style.borderRadius = size / 2 + 'px';
  121. div.innerHTML = context.count;
  122. div.style.lineHeight = size + 'px';
  123. div.style.color = '#ffffff';
  124. div.style.fontSize = '12px';
  125. div.style.textAlign = 'center';
  126. context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
  127. context.marker.setContent(div);
  128. context.marker.on('click', (e) => {
  129. const bounds = e.target.getBounds();
  130. map.setZoomAndCenter(map.getZoom() + 1, bounds.getCenter());
  131. });
  132. };
  133. const _renderMarker = function (context) {
  134. const content =
  135. '<div style="display: flex;flex-direction: column;align-items: center;justify-content: center">' +
  136. '<div style="background: url(' +
  137. context.data[0].icon +
  138. ') no-repeat; width: ' +
  139. context.data[0].size[0] +
  140. 'px;height: ' +
  141. context.data[0].size[1] +
  142. 'px;cursor: pointer; background-size: cover"></div>' +
  143. // '<div style="font-size: 36px;white-space: nowrap">'+ context.data[0].name +'</div>' +
  144. '</div>';
  145. const offset = new AMap.Pixel(-9, -9);
  146. context.marker.setContent(content);
  147. context.marker.setOffset(offset);
  148. context.marker.setExtData(context.data[0]);
  149. context.marker.on('click', function (e) {
  150. const extData = e.target.getExtData();
  151. let index = 0;
  152. let index2 = 0;
  153. for (let i = 0; i < addPoints.length; i++) {
  154. if (addPoints[i].id === extData.id && addPoints[i].imageHover) {
  155. addPoints[i].icon = addPoints[i].imageHover;
  156. e.target.setContent(content);
  157. index++;
  158. } else if (!!clickMarker) {
  159. const extData2 = clickMarker.getExtData();
  160. if (addPoints[i].id === extData2.id) {
  161. addPoints[i].icon = addPoints[i].image;
  162. clickMarker.setContent(content);
  163. index2++;
  164. }
  165. }
  166. if ((!!clickMarker && index === 1 && index2 === 1) || (!clickMarker && index === 1)) {
  167. break;
  168. }
  169. }
  170. addMarker(addPoints);
  171. clickMarker = e.target;
  172. options.onMarkerClick(extData);
  173. });
  174. };
  175. cluster = new AMap.MarkerCluster(
  176. map, //地图实例
  177. points, //海量点数据,数据中需包含经纬度信息字段 lnglat
  178. {
  179. gridSize: 30, //数据聚合计算时网格的像素大小
  180. renderClusterMarker: _renderClusterMarker, //上述步骤的自定义聚合点样式
  181. renderMarker: _renderMarker //上述步骤的自定义非聚合点样式
  182. }
  183. );
  184. points.forEach((item) => {
  185. markers['point'].push(item);
  186. });
  187. };
  188. // 清除所有标加
  189. const clearMarker = (id) => {
  190. if (!cluster || !markers[id]) return;
  191. cluster.setMap(null);
  192. markers[id] = [];
  193. };
  194. const handleHover = (extData, dataType) => {
  195. map.setZoom(18);
  196. map.setCenter([extData.lng, extData.lat]);
  197. setTimeout(() => {
  198. let index = 0;
  199. let index2 = 0;
  200. let data = {};
  201. for (let i = 0; i < addPoints.length; i++) {
  202. if (addPoints[i].id === extData.id.toString() && addPoints[i].dataType === dataType) {
  203. addPoints[i].icon = addPoints[i].imageHover;
  204. index++;
  205. data = addPoints[i];
  206. } else if (!!clickMarker) {
  207. const extData2 = clickMarker.getExtData ? clickMarker.getExtData() : clickMarker;
  208. if (addPoints[i].id === extData2.id) {
  209. addPoints[i].icon = addPoints[i].image;
  210. index2++;
  211. }
  212. }
  213. if ((!!clickMarker && index === 1 && index2 === 1) || (!clickMarker && index === 1)) {
  214. break;
  215. }
  216. }
  217. addMarker(addPoints);
  218. options.onMarkerClick(data);
  219. }, 2000);
  220. };
  221. const getMarkers = () => {
  222. return markers;
  223. };
  224. // 显示信息框
  225. let infoWindow;
  226. const showInfo = (content, position, isCustom) => {
  227. hideInfo();
  228. // 实例化InfoWindow
  229. infoWindow = new AMap.InfoWindow({
  230. // 完全自定义
  231. isCustom: isCustom,
  232. autoMove: false,
  233. offset: new AMap.Pixel(0, -20) // 信息窗体的偏移量
  234. // 可以根据需要设置其他InfoWindow的属性
  235. });
  236. const lnglat = new AMap.LngLat(position[0], position[1]);
  237. // 打开InfoWindow,并设置其内容和位置
  238. infoWindow.setContent(content);
  239. infoWindow.open(map, lnglat);
  240. // 解决2.0版本无法滚动问题
  241. infoWindow.on('mouseover', () => map.setStatus({ zoomEnable: false }));
  242. infoWindow.on('mouseout', () => map.setStatus({ zoomEnable: true }));
  243. };
  244. const hideInfo = (e) => {
  245. map.setStatus({ zoomEnable: true });
  246. if (!!infoWindow) {
  247. infoWindow.close();
  248. if (!!clickMarker && e) {
  249. const extData = clickMarker.getExtData ? clickMarker.getExtData() : clickMarker;
  250. for (let i = 0; i < addPoints.length; i++) {
  251. if (addPoints[i].id === extData.id) {
  252. addPoints[i].icon = addPoints[i].image;
  253. clickMarker = null;
  254. addMarker(addPoints);
  255. break;
  256. }
  257. }
  258. }
  259. }
  260. };
  261. let maskPolygon;
  262. const creatMask = (options, name = '茂名市') => {
  263. new AMap.DistrictSearch({
  264. extensions: 'all',
  265. subdistrict: 0
  266. }).search(name, function (status, result) {
  267. // 外多边形坐标数组和内多边形坐标数组
  268. const outer = [
  269. new AMap.LngLat(-360, 90, true),
  270. new AMap.LngLat(-360, -90, true),
  271. new AMap.LngLat(360, -90, true),
  272. new AMap.LngLat(360, 90, true)
  273. ];
  274. options.forEach((option) => {
  275. const holes = result.districtList[0].boundaries;
  276. const pathArray = [outer];
  277. pathArray.push.apply(pathArray, holes);
  278. maskPolygon = new AMap.Polygon({
  279. pathL: pathArray,
  280. strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
  281. strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
  282. strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
  283. fillColor: option.fillColor ? option.fillColor : '#10243b',
  284. fillOpacity: option.fillOpacity ? option.fillOpacity : 0.65
  285. });
  286. maskPolygon.setPath(pathArray);
  287. map.add(maskPolygon);
  288. });
  289. });
  290. };
  291. const removeMask = () => {
  292. if (!!maskPolygon) {
  293. map.remove(maskPolygon);
  294. maskPolygon = null;
  295. }
  296. };
  297. let maskPolygon2 = [];
  298. const creatMask2 = (data, option) => {
  299. if (maskPolygon2 && maskPolygon2.length > 0) {
  300. maskPolygon2.forEach((polygon) => {
  301. polygon.show();
  302. });
  303. } else {
  304. data = convertCoordinates(data);
  305. // 遮罩部分
  306. // const outer = [
  307. // new AMap.LngLat(-180, 90, true),
  308. // new AMap.LngLat(-180, -90, true),
  309. // new AMap.LngLat(180, -90, true),
  310. // new AMap.LngLat(180, 90, true)
  311. // ];
  312. // const pathArray = [outer];
  313. // 合并区边界
  314. // const data2 = mergeGeoJsonPolygons(data);
  315. // data2.geometry.coordinates.forEach((coords) => {
  316. // pathArray.push(coords[0]);
  317. // });
  318. // const maskPolygon = new AMap.Polygon({
  319. // path: pathArray,
  320. // strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
  321. // strokeOpacity: 1,
  322. // strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
  323. // fillColor: option.fillColor ? option.fillColor : '#10243b',
  324. // fillOpacity: option.fillOpacity ? option.fillOpacity : 0.65
  325. // });
  326. // maskPolygon2.push(maskPolygon);
  327. // map.add(maskPolygon);
  328. // 边界部分
  329. data.features.forEach((feature) => {
  330. if (feature.geometry.type === 'Polygon') {
  331. const polygonPath = feature.geometry.coordinates[0].map((coord) => {
  332. return [coord[0], coord[1]];
  333. });
  334. const polygon = new AMap.Polyline({
  335. path: polygonPath,
  336. strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
  337. strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
  338. strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
  339. clickable: false
  340. });
  341. maskPolygon2.push(polygon);
  342. map.add(polygon);
  343. } else if (feature.geometry.type === 'MultiPolygon') {
  344. feature.geometry.coordinates.forEach((polygonCoords) => {
  345. const polygonPath = polygonCoords.map((ring) => {
  346. return ring.map((coord) => {
  347. return [coord[0], coord[1]];
  348. });
  349. });
  350. const outerPath = polygonPath[0];
  351. const innerPaths = polygonPath.slice(1);
  352. const polygon = new AMap.Polyline({
  353. path: outerPath,
  354. holes: innerPaths,
  355. strokeColor: option.strokeColor ? option.strokeColor : '#268ab9',
  356. strokeOpacity: option.strokeOpacity ? option.strokeOpacity : 1,
  357. strokeWeight: option.strokeWeight ? option.strokeWeight : 1,
  358. clickable: false
  359. });
  360. maskPolygon2.push(polygon);
  361. map.add(polygon);
  362. });
  363. }
  364. });
  365. }
  366. };
  367. const removeMask2 = (isHidden) => {
  368. if (maskPolygon2 && maskPolygon2.length > 0) {
  369. maskPolygon2.forEach((polygon) => {
  370. polygon.hide();
  371. });
  372. if (!isHidden) {
  373. maskPolygon2 = [];
  374. }
  375. }
  376. };
  377. let moveMarker, movePolyline, movePassedPolyline, timerId;
  378. const trackPlayback = (lineArr) => {
  379. if (timerId) {
  380. clearTimeout(timerId);
  381. }
  382. movePolyline?.remove();
  383. movePassedPolyline?.remove();
  384. moveMarker?.remove();
  385. let index = 0;
  386. const icon = new AMap.Icon({
  387. size: new AMap.Size(26, 52),
  388. image: 'https://a.amap.com/jsapi_demos/static/demo-center-v2/car.png'
  389. });
  390. moveMarker = new AMap.Marker({
  391. map: map,
  392. position: [116.478935, 39.997761],
  393. icon: icon,
  394. offset: new AMap.Pixel(-13, -26)
  395. });
  396. // 绘制轨迹
  397. movePolyline = new AMap.Polyline({
  398. map: map,
  399. path: lineArr,
  400. showDir: true,
  401. strokeColor: '#28F', //线颜色
  402. // strokeOpacity: 1, //线透明度
  403. strokeWeight: 6 //线宽
  404. // strokeStyle: "solid" //线样式
  405. });
  406. movePassedPolyline = new AMap.Polyline({
  407. map: map,
  408. strokeColor: '#AF5', //线颜色
  409. strokeWeight: 6 //线宽
  410. });
  411. moveMarker.on('moving', function (e) {
  412. movePassedPolyline.setPath(e.passedPath);
  413. map.setCenter(e.target.getPosition(), true);
  414. });
  415. moveMarker.on('moveend', function (e) {
  416. index++;
  417. if (index === lineArr.length - 1) {
  418. timerId = setTimeout(() => {
  419. movePolyline.remove();
  420. movePassedPolyline.remove();
  421. moveMarker.remove();
  422. }, 5000);
  423. }
  424. });
  425. moveMarker.moveAlong(lineArr, {
  426. // 每一段的时长
  427. duration: 1000, //可根据实际采集时间间隔设置
  428. // JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
  429. autoRotation: true
  430. });
  431. };
  432. const drawData = (data) => {
  433. const res = [];
  434. data.forEach((item) => {
  435. let graphic;
  436. if (['rectangle', 'polygon', 'anyLine'].includes(item.type)) {
  437. graphic = new AMap.Polygon({
  438. path: item.path,
  439. strokeColor: item.strokeColor,
  440. strokeOpacity: item.strokeOpacity,
  441. strokeWeight: item.strokeWeight,
  442. fillColor: item.fillColor,
  443. fillOpacity: item.fillOpacity
  444. });
  445. graphic._opts.extData = {
  446. id: item.id
  447. };
  448. map.add(graphic);
  449. res.push(graphic);
  450. } else if (item.type === 'circle') {
  451. graphic = new AMap.Circle({
  452. center: item.center,
  453. radius: item.radius,
  454. strokeColor: item.strokeColor,
  455. strokeOpacity: item.strokeOpacity,
  456. strokeWeight: item.strokeWeight,
  457. fillColor: item.fillColor,
  458. fillOpacity: item.fillOpacity
  459. });
  460. graphic._opts.extData = {
  461. id: item.id
  462. };
  463. map.add(graphic);
  464. res.push(graphic);
  465. } else if (item.type === 'straightLine') {
  466. graphic = new AMap.Polyline({
  467. path: item.path,
  468. strokeColor: item.strokeColor,
  469. strokeOpacity: item.strokeOpacity,
  470. strokeWeight: item.strokeWeight,
  471. strokeStyle: item.strokeStyle
  472. });
  473. graphic._opts.extData = {
  474. id: item.id
  475. };
  476. map.add(graphic);
  477. res.push(graphic);
  478. } else if (item.type === 'text') {
  479. const { text } = addText(item);
  480. res.push(text);
  481. } else if (item.type === 'measureArea') {
  482. graphic = new AMap.Polygon({
  483. path: item.path,
  484. strokeColor: item.strokeColor,
  485. strokeOpacity: item.strokeOpacity,
  486. strokeWeight: item.strokeWeight,
  487. fillColor: item.fillColor,
  488. fillOpacity: item.fillOpacity
  489. });
  490. graphic._opts.extData = {
  491. id: item.id
  492. };
  493. map.add(graphic);
  494. // 计算区域面积
  495. const area = Math.round(AMap.GeometryUtil.ringArea(item.path));
  496. const text = new AMap.Text({
  497. position: item.path[item.path.length - 1],
  498. text: '区域面积' + area + '平方米',
  499. offset: new AMap.Pixel(-20, -20)
  500. });
  501. text._opts.extData = {
  502. id: item.id
  503. };
  504. data.area = area;
  505. map.add([graphic, text]);
  506. // res.push(text);
  507. } else if (item.type === 'marker') {
  508. // 创建标注点
  509. const marker = new AMap.Marker({
  510. position: new AMap.LngLat(item.longitude, item.latitude), // 标注点的位置
  511. icon: new AMap.Icon({
  512. size: item.size, //图标所处区域大小
  513. image: item.icon
  514. }),
  515. size: item.size
  516. });
  517. marker._opts.extData = {
  518. id: item.id
  519. };
  520. marker.setLabel({
  521. content: '<div>' + item.title + '</div>',
  522. direction: 'top'
  523. });
  524. map.add(marker);
  525. res.push(marker);
  526. }
  527. });
  528. return res;
  529. };
  530. const addText = (options) => {
  531. // 文本覆盖物的样式
  532. const textStyle = {
  533. fontSize: options.fontSize,
  534. color: options.fontColor,
  535. borderColor: 'transparent',
  536. backgroundColor: 'transparent',
  537. borderWidth: 0,
  538. cursor: 'pointer' // 鼠标悬停时显示指针
  539. };
  540. // 创建文本覆盖物
  541. const text = new AMap.Text({
  542. text: options.text, // 文本内容,可以根据需要自定义
  543. position: options.lnglat, // 文本位置(经纬度)
  544. style: textStyle, // 文本样式
  545. zIndex: 100, // 文本层级
  546. draggable: false // 是否可拖动(可选)
  547. });
  548. // 将文本覆盖物添加到地图
  549. map.add(text);
  550. const id = nanoid();
  551. text._opts.extData = {
  552. id: id
  553. };
  554. const data: any = deepClone(options);
  555. data.id = id;
  556. return { text, data };
  557. };
  558. const convertCoordinates = (geoJson) => {
  559. const features = geoJson.features.map((feature) => {
  560. const geometry = feature.geometry;
  561. let newGeometry;
  562. if (geometry.type === 'Point') {
  563. const [x, y] = geometry.coordinates;
  564. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  565. newGeometry = { ...geometry, coordinates: [obj.lng, obj.lat] };
  566. } else if (geometry.type === 'MultiPoint') {
  567. const newCoordinates = geometry.coordinates.map((coords) => {
  568. const [x, y] = coords;
  569. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  570. return [obj.lng, obj.lat];
  571. });
  572. newGeometry = { ...geometry, coordinates: newCoordinates };
  573. } else if (geometry.type === 'LineString') {
  574. const newCoordinates = geometry.coordinates.map((coords) => {
  575. const [x, y] = coords;
  576. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  577. return [obj.lng, obj.lat];
  578. });
  579. newGeometry = { ...geometry, coordinates: newCoordinates };
  580. } else if (geometry.type === 'MultiLineString') {
  581. const newCoordinates = geometry.coordinates.map((line) =>
  582. line.map((coords) => {
  583. const [x, y] = coords;
  584. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  585. return [obj.lng, obj.lat];
  586. })
  587. );
  588. newGeometry = { ...geometry, coordinates: newCoordinates };
  589. } else if (geometry.type === 'Polygon') {
  590. const newCoordinates = geometry.coordinates.map((polygon) =>
  591. polygon.map((coords) => {
  592. const [x, y] = coords;
  593. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  594. return [obj.lng, obj.lat];
  595. })
  596. );
  597. newGeometry = { ...geometry, coordinates: newCoordinates };
  598. } else if (geometry.type === 'MultiPolygon') {
  599. const newCoordinates = geometry.coordinates.map((polygon) =>
  600. polygon.map((ring) =>
  601. ring.map((coords) => {
  602. const [x, y] = coords;
  603. const obj = wgs_gcj_encrypts([{ lng: x, lat: y }])[0];
  604. return [obj.lng, obj.lat];
  605. })
  606. )
  607. );
  608. newGeometry = { ...geometry, coordinates: newCoordinates };
  609. }
  610. return { ...feature, geometry: newGeometry };
  611. });
  612. return { ...geoJson, features };
  613. };
  614. onMounted(() => {
  615. initMap(options);
  616. });
  617. return {
  618. getAMap,
  619. getMap,
  620. switchMap,
  621. addMarker,
  622. addSearchMarker,
  623. clearMarker,
  624. getMarkers,
  625. getScale,
  626. showInfo,
  627. hideInfo,
  628. handleHover,
  629. creatMask,
  630. removeMask,
  631. creatMask2,
  632. removeMask2,
  633. trackPlayback,
  634. drawData
  635. };
  636. }