UNPKG

map-integration

Version:

vue集成地图第三方插件

105 lines (104 loc) 3.67 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); exports.__esModule = true; exports.AmapResult = void 0; /* * @Descripttion: 高德地图 图层操作工具 * @Author: xuyanqi * @Date: 2022-06-08 13:36:07 */ var common_1 = require("./common"); var Marker = /** @class */ (function (_super) { __extends(Marker, _super); function Marker() { var _this = _super !== null && _super.apply(this, arguments) || this; // 点标记显示位置偏移量,默认值为 [0,0] _this.offset = [0, 0]; return _this; } return Marker; }(common_1.MarkerExtends)); var Polyline = /** @class */ (function (_super) { __extends(Polyline, _super); function Polyline() { return _super !== null && _super.apply(this, arguments) || this; } return Polyline; }(common_1.PolylineExtends)); var AmapResult = /** @class */ (function () { function AmapResult() { } AmapResult.prototype.addMarker = function (marker) { var obj = new Marker(); obj = Marker.assign(obj, marker); return new this.AMap.Marker(Object.assign({}, obj, { map: this.map, position: new this.AMap.LngLat(obj.lng, obj.lat), offset: new this.AMap.Pixel(0, 0), icon: new this.AMap.Icon({ image: obj.icon, imageOffset: new this.AMap.Pixel(0, 0), size: new this.AMap.Size(obj.size, obj.size), imageSize: new this.AMap.Size(obj.size, obj.size) }) })); }; AmapResult.prototype.addPolyline = function (polyline) { var obj = new Polyline(); obj = Polyline.assign(obj, polyline); var layer = new this.AMap.Polyline(Object.assign({}, obj, { path: obj.path, borderWeight: obj.borderWeight, strokeColor: obj.strokeColor })); this.map.add(layer); return layer; }; AmapResult.prototype.clickLayer = function (callback) { this.map.getAllOverlays().forEach(function (layer) { layer.on('click', function () { try { callback(layer.getExtData()); } catch (_a) { console.log('no callback'); } }); }); }; AmapResult.prototype.clickMap = function (callback) { this.map.on('click', function (e) { try { callback({ lng: e.lnglat.lng, lat: e.lnglat.lat }); } catch (_a) { console.log('no callback'); } }); }; AmapResult.prototype.clearLayers = function () { this.map.remove(this.map.getAllOverlays()); }; AmapResult.prototype.removeLayer = function (layer) { this.map.remove(layer); }; return AmapResult; }()); exports.AmapResult = AmapResult;