UNPKG

map-integration

Version:

vue集成地图第三方插件

109 lines (108 loc) 3.27 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.LeafletResult = void 0 /* * @Descripttion: leaflet 图层操作工具 * @Author: xuyanqi * @Date: 2022-06-09 09:04:56 */ var vue_1 = require('vue') var L = vue_1['default'].prototype.$L var common_1 = require('./common') var gis_1 = require('../utils/gis') var Marker = /** @class */ (function (_super) { __extends(Marker, _super) function Marker() { return (_super !== null && _super.apply(this, arguments)) || 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 LeafletResult = /** @class */ (function () { function LeafletResult() {} LeafletResult.prototype.addMarker = function (marker) { var obj = new Marker() obj = Marker.assign(obj, marker) var gps = (0, gis_1.gcj02_To_Gps84)(obj.lat, obj.lng) var layer = L.marker( [gps.mgLat, gps.mgLon], Object.assign({}, obj, { icon: L.icon({ iconUrl: obj.icon, iconSize: [obj.size, obj.size], }), }) ) layer.addTo(this.map) layer.addTo(this.features) this.map.flyToBounds(this.features.getBounds()) return layer } LeafletResult.prototype.addPolyline = function (polyline) { var obj = new Polyline() obj = Polyline.assign(obj, polyline) var layer = L.polyline((0, gis_1.lnglatExchange)(obj.path), Object.assign({}, obj, { color: obj.strokeColor, weight: obj.borderWeight })).addTo(this.map) layer.addTo(this.features) return layer } LeafletResult.prototype.clickLayer = function (callback) { this.features.on('click', function (e) { var options = e.sourceTarget.options try { callback(options) } catch (_a) { console.log('no callback') } }) } LeafletResult.prototype.clickMap = function (callback) { this.map.on('click', function (e) { try { callback({ lng: e.latlng.lng, lat: e.latlng.lat, }) } catch (_a) { console.log('no callback') } }) } LeafletResult.prototype.clearLayers = function () { this.features.clearLayers() } LeafletResult.prototype.removeLayer = function (layer) { this.map.removeLayer(layer) } return LeafletResult })() exports.LeafletResult = LeafletResult