@sword916/vae-map-plus 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/index.mjs +113 -0
- package/examples/App.vue +18 -0
- package/examples/index.js +13 -0
- package/examples/router/index.js +35 -0
- package/examples/views/amap.vue +29 -0
- package/examples/views/amarker.vue +58 -0
- package/examples/views/buffer.vue +66 -0
- package/examples/views/cluster.vue +74 -0
- package/examples/views/cover.vue +85 -0
- package/examples/views/draw-line.vue +49 -0
- package/examples/views/draw.vue +54 -0
- package/examples/views/echarts.vue +142 -0
- package/examples/views/emarker.vue +39 -0
- package/examples/views/image.vue +182 -0
- package/examples/views/index.vue +61 -0
- package/examples/views/lrmap.vue +108 -0
- package/examples/views/map.vue +82 -0
- package/examples/views/measure.vue +86 -0
- package/examples/views/parts/popup.vue +39 -0
- package/examples/views/parts/tooltip.vue +39 -0
- package/examples/views/push-area.vue +52 -0
- package/examples/views/push-line.vue +84 -0
- package/examples/views/trace.vue +49 -0
- package/index.html +13 -0
- package/jsconfig.json +17 -0
- package/package.json +47 -0
- package/public/favicon.ico +0 -0
- package/public/images/game.png +0 -0
- package/public/images/grid.png +0 -0
- package/public/images/marker.png +0 -0
- package/public/index.html +30 -0
- package/src/components/resize-listener/component.jsx +30 -0
- package/src/components/resize-listener/index.js +3 -0
- package/src/composables/useAutoMessage.js +41 -0
- package/src/composables/useContextMenu.js +99 -0
- package/src/composables/useMapMeasure.js +191 -0
- package/src/composables/useResizeObserver.js +81 -0
- package/src/mixins/message.js +1 -0
- package/src/packages/index.js +16 -0
- package/src/packages/vae-amap/index.js +8 -0
- package/src/packages/vae-amap/style.less +9 -0
- package/src/packages/vae-amap/vae-amap.jsx +98 -0
- package/src/packages/vae-cloudmap/ctrl-context-menu/index.vue +74 -0
- package/src/packages/vae-cloudmap/ctrl-draw/index.vue +499 -0
- package/src/packages/vae-cloudmap/ctrl-draw-line/index.vue +161 -0
- package/src/packages/vae-cloudmap/index.js +57 -0
- package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/index.js +2690 -0
- package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/style.css +14 -0
- package/src/packages/vae-cloudmap/scripts/L.Vae.CRS/index.js +212 -0
- package/src/packages/vae-cloudmap/scripts/L.Vae.Client/index.js +780 -0
- package/src/packages/vae-cloudmap/scripts/Mixin.ContextMenu/index.js +101 -0
- package/src/packages/vae-cloudmap/style.less +163 -0
- package/src/packages/vae-cloudmap/vae-cloudmap.jsx +272 -0
- package/src/packages/vae-map/ctrl-context-menu/index.vue +74 -0
- package/src/packages/vae-map/ctrl-draw/index.vue +498 -0
- package/src/packages/vae-map/ctrl-draw-line/index.vue +128 -0
- package/src/packages/vae-map/index.js +59 -0
- package/src/packages/vae-map/scripts/L.MarkerCluster/index.js +2690 -0
- package/src/packages/vae-map/scripts/L.MarkerCluster/style.css +14 -0
- package/src/packages/vae-map/scripts/L.Vae.CRS/index.js +114 -0
- package/src/packages/vae-map/scripts/L.Vae.Client/index.js +548 -0
- package/src/packages/vae-map/scripts/Mixin.ContextMenu/index.js +1 -0
- package/src/packages/vae-map/style.less +161 -0
- package/src/packages/vae-map/vae-lrmap.jsx +237 -0
- package/src/packages/vae-map/vae-map.jsx +135 -0
- package/src/plugins/L.AnimatedMarker/index.js +158 -0
- package/src/plugins/L.EchartsLayer/index.js +339 -0
- package/src/plugins/L.ElasticMarker/index.js +162 -0
- package/src/plugins/L.FootageCalculator.Area/index.js +263 -0
- package/src/plugins/L.FootageCalculator.Line/index.js +273 -0
- package/src/plugins/L.GeoUtil/buffer.js +67 -0
- package/src/plugins/L.GeoUtil/index.js +284 -0
- package/src/plugins/L.Glyphicon/index.js +91 -0
- package/src/plugins/L.Glyphicon/style.less +37 -0
- package/src/plugins/L.MarkerClusterX/index.js +93 -0
- package/src/plugins/L.MarkerClusterX/style.less +162 -0
- package/src/plugins/L.SafeDivOverlay/index.js +55 -0
- package/src/plugins/L.TileLayer.ChinaProvider/index.js +108 -0
- package/src/plugins/L.VuePopup/index.js +67 -0
- package/src/plugins/L.VueTooltip/index.js +63 -0
- package/src/plugins/Mixin.Map.Measure/index.js +248 -0
- package/src/plugins/globals/index.js +7 -0
- package/src/utils/index.js +36 -0
- package/src/utils/resize-event.js +45 -0
- package/vite.config.mjs +25 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import * as echarts from "echarts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @class L.supermap.echartsLayer
|
|
5
|
+
* @classdesc 百度 ECharts 图层类。
|
|
6
|
+
* @category Visualization ECharts
|
|
7
|
+
* @extends {L.Layer}
|
|
8
|
+
* @param {Object} echartsOptions - 图表参数。
|
|
9
|
+
* @param {Object} options - 可选图层参数。
|
|
10
|
+
* @param {boolean} [options.loadWhileAnimating=false] - 是否在移动时实时绘制。
|
|
11
|
+
* @param {string} [options.attribution='© 2018 百度 ECharts'] - 版权信息。
|
|
12
|
+
*/
|
|
13
|
+
L.EchartsLayer = L.Layer.extend({
|
|
14
|
+
|
|
15
|
+
includes: [],
|
|
16
|
+
_echartsContainer: null,
|
|
17
|
+
_map: null,
|
|
18
|
+
_ec: null,
|
|
19
|
+
_echartsOptions: null,
|
|
20
|
+
|
|
21
|
+
options: {
|
|
22
|
+
loadWhileAnimating: false
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
initialize: function (echartsOptions, options) {
|
|
26
|
+
L.Util.setOptions(this, options)
|
|
27
|
+
this.setOption(echartsOptions)
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* @function L.supermap.echartsLayer.prototype.setOption
|
|
31
|
+
* @description 设置图表地图参数。
|
|
32
|
+
* @param {Object} echartsOptions - 图表参数。
|
|
33
|
+
* @param {string} lazyUpdate - 后台自动更新。
|
|
34
|
+
* @param {boolean} [notMerge] - 是否合并参数。
|
|
35
|
+
*/
|
|
36
|
+
setOption: function (echartsOptions, notMerge, lazyUpdate) {
|
|
37
|
+
const baseOption = echartsOptions.baseOption || echartsOptions
|
|
38
|
+
baseOption.LeafletMap = baseOption.LeafletMap || {
|
|
39
|
+
roam: true
|
|
40
|
+
}
|
|
41
|
+
baseOption.animation = baseOption.animation === true
|
|
42
|
+
this._echartsOptions = echartsOptions
|
|
43
|
+
this._ec && this._ec.setOption(echartsOptions, notMerge, lazyUpdate)
|
|
44
|
+
},
|
|
45
|
+
getEcharts: function () {
|
|
46
|
+
return this._ec
|
|
47
|
+
},
|
|
48
|
+
_disableEchartsContainer: function () {
|
|
49
|
+
this._echartsContainer.style.visibility = "hidden"
|
|
50
|
+
},
|
|
51
|
+
_enableEchartsContainer: function () {
|
|
52
|
+
this._echartsContainer.style.visibility = "visible"
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @private
|
|
57
|
+
* @function L.supermap.echartsLayer.prototype.onAdd
|
|
58
|
+
* @description 添加地图。
|
|
59
|
+
* @param {L.Map} map - 待添加的地图。
|
|
60
|
+
*/
|
|
61
|
+
onAdd: function (map) {
|
|
62
|
+
this._map = map
|
|
63
|
+
this._initEchartsContainer()
|
|
64
|
+
this._ec = echarts.init(this._echartsContainer)
|
|
65
|
+
this._ec.leafletMap = map
|
|
66
|
+
const me = this
|
|
67
|
+
|
|
68
|
+
map.on("zoomstart", function () {
|
|
69
|
+
me._disableEchartsContainer()
|
|
70
|
+
})
|
|
71
|
+
!me.options.loadWhileAnimating && map.on("movestart", function () {
|
|
72
|
+
me._disableEchartsContainer()
|
|
73
|
+
})
|
|
74
|
+
echarts.registerAction({
|
|
75
|
+
type: 'LeafletMapLayout',
|
|
76
|
+
event: 'LeafletMapLayout',
|
|
77
|
+
update: 'updateLayout'
|
|
78
|
+
}, function (payload) { // eslint-disable-line no-unused-vars
|
|
79
|
+
})
|
|
80
|
+
echarts.registerCoordinateSystem(
|
|
81
|
+
'leaflet', LeafletMapCoordSys
|
|
82
|
+
)
|
|
83
|
+
echarts.extendComponentModel({
|
|
84
|
+
type: 'LeafletMap',
|
|
85
|
+
getBMap: function () {
|
|
86
|
+
return this.__LeafletMap
|
|
87
|
+
},
|
|
88
|
+
defaultOption: {
|
|
89
|
+
roam: false
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
echarts.extendComponentView({
|
|
93
|
+
type: 'LeafletMap',
|
|
94
|
+
render: function (LeafletMapModel, ecModel, api) {
|
|
95
|
+
let rendering = true
|
|
96
|
+
let leafletMap = ecModel.scheduler.ecInstance.leafletMap
|
|
97
|
+
const viewportRoot = api.getZr().painter.getViewportRoot()
|
|
98
|
+
|
|
99
|
+
const animated = leafletMap.options.zoomAnimation && L.Browser.any3d
|
|
100
|
+
viewportRoot.className = ' leaflet-layer leaflet-zoom-' + (animated ? 'animated' : 'hide') + ' echarts-layer'
|
|
101
|
+
|
|
102
|
+
const originProp = L.DomUtil.testProp(['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin'])
|
|
103
|
+
viewportRoot.style[originProp] = '50% 50%'
|
|
104
|
+
|
|
105
|
+
const coordSys = LeafletMapModel.coordinateSystem
|
|
106
|
+
|
|
107
|
+
const ecLayers = api.getZr().painter.getLayers()
|
|
108
|
+
|
|
109
|
+
const moveHandler = function () {
|
|
110
|
+
if (rendering) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
const offset = me._map.containerPointToLayerPoint([0, 0])
|
|
114
|
+
const mapOffset = [offset.x || 0, offset.y || 0]
|
|
115
|
+
viewportRoot.style.left = mapOffset[0] + 'px'
|
|
116
|
+
viewportRoot.style.top = mapOffset[1] + 'px'
|
|
117
|
+
|
|
118
|
+
if (!me.options.loadWhileAnimating) {
|
|
119
|
+
for (let item in ecLayers) {
|
|
120
|
+
if (!ecLayers.hasOwnProperty(item)) {
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
ecLayers[item] && clearContext(ecLayers[item].ctx)
|
|
124
|
+
}
|
|
125
|
+
me._enableEchartsContainer()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
coordSys.setMapOffset(mapOffset)
|
|
129
|
+
LeafletMapModel.__mapOffset = mapOffset
|
|
130
|
+
|
|
131
|
+
api.dispatchAction({
|
|
132
|
+
type: 'LeafletMapLayout'
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function clearContext(context) {
|
|
139
|
+
context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function zoomEndHandler() {
|
|
143
|
+
if (rendering) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
api.dispatchAction({
|
|
148
|
+
type: 'LeafletMapLayout'
|
|
149
|
+
})
|
|
150
|
+
me._enableEchartsContainer()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (me._oldMoveHandler) {
|
|
154
|
+
leafletMap.off(me.options.loadWhileAnimating ? 'move' : 'moveend', me._oldMoveHandler)
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
if (me._oldZoomEndHandler) {
|
|
158
|
+
leafletMap.off('zoomend', me._oldZoomEndHandler)
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
leafletMap.on(me.options.loadWhileAnimating ? 'move' : 'moveend', moveHandler)
|
|
163
|
+
leafletMap.on('zoomend', zoomEndHandler)
|
|
164
|
+
me._oldMoveHandler = moveHandler
|
|
165
|
+
me._oldZoomEndHandler = zoomEndHandler
|
|
166
|
+
rendering = false
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
this._ec.setOption(this._echartsOptions)
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
onRemove: function () {
|
|
173
|
+
// 销毁echarts实例
|
|
174
|
+
this._ec.clear()
|
|
175
|
+
this._ec.dispose()
|
|
176
|
+
delete this._ec
|
|
177
|
+
L.DomUtil.remove(this._echartsContainer)
|
|
178
|
+
|
|
179
|
+
if (this._oldZoomEndHandler) {
|
|
180
|
+
this._map.off("zoomend", this._oldZoomEndHandler)
|
|
181
|
+
this._oldZoomEndHandler = null
|
|
182
|
+
}
|
|
183
|
+
if (this._oldMoveHandler) {
|
|
184
|
+
this._map.off(this.options.loadWhileAnimating ? 'move' : 'moveend', this._oldMoveHandler)
|
|
185
|
+
this._oldMoveHandler = null
|
|
186
|
+
}
|
|
187
|
+
if (this._resizeHandler) {
|
|
188
|
+
this._map.off('resize', this._resizeHandler)
|
|
189
|
+
this._resizeHandler = null
|
|
190
|
+
}
|
|
191
|
+
delete this._map
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
_initEchartsContainer: function () {
|
|
195
|
+
const size = this._map.getSize()
|
|
196
|
+
|
|
197
|
+
const _div = document.createElement('div')
|
|
198
|
+
_div.style.position = 'absolute'
|
|
199
|
+
_div.style.height = size.y + 'px'
|
|
200
|
+
_div.style.width = size.x + 'px'
|
|
201
|
+
_div.style.zIndex = 10
|
|
202
|
+
this._echartsContainer = _div
|
|
203
|
+
|
|
204
|
+
this.getPane().appendChild(this._echartsContainer)
|
|
205
|
+
const me = this
|
|
206
|
+
|
|
207
|
+
function _resizeHandler(e) {
|
|
208
|
+
let size = e.newSize
|
|
209
|
+
me._echartsContainer.style.width = size.x + 'px'
|
|
210
|
+
me._echartsContainer.style.height = size.y + 'px'
|
|
211
|
+
me._ec.resize()
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this._map.on('resize', _resizeHandler)
|
|
215
|
+
this._resizeHandler = _resizeHandler
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @class L.supermap.LeafletMapCoordSys
|
|
222
|
+
* @private
|
|
223
|
+
* @classdesc 地图坐标系统类。
|
|
224
|
+
* @param {L.Map} leafletMap - 地图。
|
|
225
|
+
*/
|
|
226
|
+
export function LeafletMapCoordSys(leafletMap) {
|
|
227
|
+
this._LeafletMap = leafletMap
|
|
228
|
+
this.dimensions = ['lng', 'lat']
|
|
229
|
+
this._mapOffset = [0, 0]
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
LeafletMapCoordSys.prototype.dimensions = ['lng', 'lat']
|
|
233
|
+
|
|
234
|
+
LeafletMapCoordSys.prototype.setMapOffset = function (mapOffset) {
|
|
235
|
+
this._mapOffset = mapOffset
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
LeafletMapCoordSys.prototype.getBMap = function () {
|
|
239
|
+
return this._LeafletMap
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
LeafletMapCoordSys.prototype.prepareCustoms = function () {
|
|
243
|
+
const zrUtil = echarts.util
|
|
244
|
+
|
|
245
|
+
const rect = this.getViewRect()
|
|
246
|
+
return {
|
|
247
|
+
coordSys: {
|
|
248
|
+
// The name exposed to user is always 'cartesian2d' but not 'grid'.
|
|
249
|
+
type: 'leaflet',
|
|
250
|
+
x: rect.x,
|
|
251
|
+
y: rect.y,
|
|
252
|
+
width: rect.width,
|
|
253
|
+
height: rect.height
|
|
254
|
+
},
|
|
255
|
+
api: {
|
|
256
|
+
coord: zrUtil.bind(this.dataToPoint, this),
|
|
257
|
+
size: zrUtil.bind(dataToCoordSize, this)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function dataToCoordSize(dataSize, dataItem) {
|
|
262
|
+
dataItem = dataItem || [0, 0]
|
|
263
|
+
return zrUtil.map([0, 1], function (dimIdx) {
|
|
264
|
+
const val = dataItem[dimIdx]
|
|
265
|
+
const halfSize = dataSize[dimIdx] / 2
|
|
266
|
+
const p1 = []
|
|
267
|
+
const p2 = []
|
|
268
|
+
p1[dimIdx] = val - halfSize
|
|
269
|
+
p2[dimIdx] = val + halfSize
|
|
270
|
+
p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx]
|
|
271
|
+
return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx])
|
|
272
|
+
}, this)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
LeafletMapCoordSys.prototype.dataToPoint = function (data) {
|
|
277
|
+
//处理数据中的null值
|
|
278
|
+
if (data[1] === null) {
|
|
279
|
+
data[1] = L.CRS.EPSG3857.projection.MAX_LATITUDE
|
|
280
|
+
}
|
|
281
|
+
//平面坐标系不能这么处理
|
|
282
|
+
//data[1] = this.fixLat(data[1])
|
|
283
|
+
|
|
284
|
+
const px = this._LeafletMap.latLngToLayerPoint([data[1], data[0]])
|
|
285
|
+
|
|
286
|
+
const mapOffset = this._mapOffset
|
|
287
|
+
return [px.x - mapOffset[0], px.y - mapOffset[1]]
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
LeafletMapCoordSys.prototype.fixLat = function (lat) {
|
|
291
|
+
if (lat >= 90) {
|
|
292
|
+
return 89.99999999999999
|
|
293
|
+
}
|
|
294
|
+
if (lat <= -90) {
|
|
295
|
+
return -89.99999999999999
|
|
296
|
+
}
|
|
297
|
+
return lat
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
LeafletMapCoordSys.prototype.pointToData = function (pt) {
|
|
301
|
+
let mapOffset = this._mapOffset
|
|
302
|
+
let point = this._LeafletMap.layerPointToLatLng([pt[0] + mapOffset[0], pt[1] + mapOffset[1]])
|
|
303
|
+
return [point.lng, point.lat]
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
LeafletMapCoordSys.prototype.getViewRect = function () {
|
|
307
|
+
const size = this._LeafletMap.getSize()
|
|
308
|
+
return new echarts.graphic.BoundingRect(0, 0, size.x, size.y)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
LeafletMapCoordSys.prototype.getRoamTransform = function () {
|
|
312
|
+
return echarts.matrix.create()
|
|
313
|
+
}
|
|
314
|
+
LeafletMapCoordSys.dimensions = LeafletMapCoordSys.prototype.dimensions
|
|
315
|
+
|
|
316
|
+
LeafletMapCoordSys.create = function (ecModel) {
|
|
317
|
+
let coordSys
|
|
318
|
+
let leafletMap = ecModel.scheduler.ecInstance.leafletMap
|
|
319
|
+
ecModel.eachComponent('LeafletMap', function (leafletMapModel) {
|
|
320
|
+
if (!coordSys) {
|
|
321
|
+
coordSys = new LeafletMapCoordSys(leafletMap)
|
|
322
|
+
}
|
|
323
|
+
leafletMapModel.coordinateSystem = coordSys
|
|
324
|
+
leafletMapModel.coordinateSystem.setMapOffset(leafletMapModel.__mapOffset || [0, 0])
|
|
325
|
+
})
|
|
326
|
+
ecModel.eachSeries(function (seriesModel) {
|
|
327
|
+
if (!seriesModel.get('coordinateSystem') || seriesModel.get('coordinateSystem') === 'leaflet') {
|
|
328
|
+
if (!coordSys) {
|
|
329
|
+
coordSys = new LeafletMapCoordSys(leafletMap)
|
|
330
|
+
}
|
|
331
|
+
seriesModel.coordinateSystem = coordSys
|
|
332
|
+
seriesModel.animation = seriesModel.animation === true
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
L.echartsLayer = (echartsOptions, options) => {
|
|
338
|
+
return new L.EchartsLayer(echartsOptions, options)
|
|
339
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import jQuery from 'jquery'
|
|
2
|
+
|
|
3
|
+
// 灵活marker
|
|
4
|
+
L.ElasticMarker = L.Marker.extend({
|
|
5
|
+
|
|
6
|
+
targetMap: null,
|
|
7
|
+
|
|
8
|
+
options: {
|
|
9
|
+
// 启用动态尺寸
|
|
10
|
+
elasticScale: true,
|
|
11
|
+
// 合适的级别
|
|
12
|
+
fitZoom: 10,
|
|
13
|
+
// 最大比例
|
|
14
|
+
maxScale: 1.35,
|
|
15
|
+
// 最小比例
|
|
16
|
+
minScale: 0.35,
|
|
17
|
+
// 比例变换系数
|
|
18
|
+
scaleFactor: 1.35,
|
|
19
|
+
|
|
20
|
+
// 启用动态透明度
|
|
21
|
+
elasticOpacity: false,
|
|
22
|
+
opacityFitZoom: null,
|
|
23
|
+
minOpacity: 0.1,
|
|
24
|
+
opacityFactor: 2,
|
|
25
|
+
|
|
26
|
+
// 启动动态tooltip
|
|
27
|
+
elasticTooltip: true,
|
|
28
|
+
tooltipFitZoom: null
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
initialize(latLng, options) {
|
|
32
|
+
L.setOptions(this, options)
|
|
33
|
+
this.options.opacityFitZoom = this.options.opacityFitZoom || this.options.fitZoom
|
|
34
|
+
this.options.tooltipFitZoom = this.options.tooltipFitZoom || this.options.fitZoom
|
|
35
|
+
this._bindEvents()
|
|
36
|
+
L.Marker.prototype.initialize.call(this, latLng, this.options)
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
_bindEvents() {
|
|
40
|
+
this.on('add', e => {
|
|
41
|
+
this.targetMap = e.target._map
|
|
42
|
+
this.targetMap.on('zoomend', this._update, this)
|
|
43
|
+
this._update()
|
|
44
|
+
})
|
|
45
|
+
this.on('remove', () => {
|
|
46
|
+
this.targetMap.off('zoomend', this._update, this)
|
|
47
|
+
this.targetMap = null
|
|
48
|
+
})
|
|
49
|
+
this.on('tooltipopen', e => {
|
|
50
|
+
this._updateTooltip()
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
_update() {
|
|
55
|
+
// icon
|
|
56
|
+
if (this.options.elasticScale && this.targetMap) {
|
|
57
|
+
// 获取缩放值
|
|
58
|
+
const zoom = this.targetMap.getZoom()
|
|
59
|
+
let scale = 1.0 - (this.options.fitZoom - zoom) * this.options.scaleFactor * 0.1
|
|
60
|
+
scale = _.max([this.options.minScale, scale])
|
|
61
|
+
scale = _.min([this.options.maxScale, scale])
|
|
62
|
+
|
|
63
|
+
const markerIcon = this.getIcon()
|
|
64
|
+
// L.DivIcon
|
|
65
|
+
if (markerIcon instanceof L.DivIcon) {
|
|
66
|
+
const iconDom = jQuery(this._icon)
|
|
67
|
+
const innerIconDom = iconDom.contents()
|
|
68
|
+
// 调整鼠标事件响应范围
|
|
69
|
+
if (this.options.interactive) {
|
|
70
|
+
if (scale < 1) {
|
|
71
|
+
iconDom.css('pointer-events', 'none')
|
|
72
|
+
innerIconDom.css('pointer-events', 'auto')
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
innerIconDom.css('transform', `scale(${scale})`)
|
|
76
|
+
innerIconDom.css('transition', `0.2s`)
|
|
77
|
+
}
|
|
78
|
+
// L.Icon
|
|
79
|
+
else if (markerIcon instanceof L.Icon) {
|
|
80
|
+
const iconDom = jQuery(this._icon)
|
|
81
|
+
const shadowDom = jQuery(this._shadow)
|
|
82
|
+
let iconAnchor, shadowAnchor
|
|
83
|
+
// 默认图标
|
|
84
|
+
if (markerIcon instanceof L.Icon.Default) {
|
|
85
|
+
iconAnchor = shadowAnchor = L.Icon.Default.prototype.options.iconAnchor
|
|
86
|
+
}
|
|
87
|
+
// 自定义图标
|
|
88
|
+
else {
|
|
89
|
+
iconAnchor = markerIcon.options.iconAnchor
|
|
90
|
+
shadowAnchor = markerIcon.options.shadowAnchor
|
|
91
|
+
}
|
|
92
|
+
if (iconDom.length > 0) {
|
|
93
|
+
iconDom.css('transform', iconDom.css('transform') + ` scale(${scale})`)
|
|
94
|
+
if (iconAnchor && iconAnchor.length == 2) {
|
|
95
|
+
iconDom.css('transform-origin', `${iconAnchor[0] + 'px'} ${iconAnchor[1] + 'px'}`)
|
|
96
|
+
}
|
|
97
|
+
iconDom.css('transition', `0.2s`)
|
|
98
|
+
}
|
|
99
|
+
if (shadowDom.length > 0) {
|
|
100
|
+
shadowDom.css('transform', shadowDom.css('transform') + ` scale(${scale})`)
|
|
101
|
+
if (shadowAnchor && shadowAnchor.length == 2) {
|
|
102
|
+
shadowDom.css('transform-origin', `${shadowAnchor[0] + 'px'} ${shadowAnchor[1] + 'px'}`)
|
|
103
|
+
}
|
|
104
|
+
shadowDom.css('transition', `0.2s`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// opacity
|
|
110
|
+
if (this.options.elasticOpacity && this.targetMap) {
|
|
111
|
+
// 获取透明度
|
|
112
|
+
const zoom = this.targetMap.getZoom()
|
|
113
|
+
let opacity = 1.0
|
|
114
|
+
if (zoom < this.options.fitZoom) {
|
|
115
|
+
opacity = 1.0 - (this.options.fitZoom - zoom) * this.options.opacityFactor * 0.1
|
|
116
|
+
}
|
|
117
|
+
opacity = _.max([this.options.minOpacity, opacity])
|
|
118
|
+
|
|
119
|
+
const iconDom = jQuery(this._icon)
|
|
120
|
+
const shadowDom = jQuery(this._shadow)
|
|
121
|
+
if (iconDom.length > 0) {
|
|
122
|
+
iconDom.css('opacity', opacity)
|
|
123
|
+
}
|
|
124
|
+
if (shadowDom.length > 0) {
|
|
125
|
+
shadowDom.css('opacity', opacity)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this._updateTooltip()
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
_updateTooltip() {
|
|
133
|
+
if (this.options.elasticTooltip && this.targetMap) {
|
|
134
|
+
const markerTooltip = this.getTooltip()
|
|
135
|
+
if (markerTooltip) {
|
|
136
|
+
const zoom = this.targetMap.getZoom()
|
|
137
|
+
const tooltipDom = jQuery(markerTooltip._container)
|
|
138
|
+
if (zoom >= this.options.fitZoom) {
|
|
139
|
+
tooltipDom.css('display', '')
|
|
140
|
+
} else {
|
|
141
|
+
tooltipDom.css('display', 'none')
|
|
142
|
+
}
|
|
143
|
+
// 调整位置
|
|
144
|
+
_.delay(() => {
|
|
145
|
+
if (
|
|
146
|
+
this.isTooltipOpen() &&
|
|
147
|
+
markerTooltip._map &&
|
|
148
|
+
markerTooltip._latlng &&
|
|
149
|
+
markerTooltip._container
|
|
150
|
+
) {
|
|
151
|
+
markerTooltip._updatePosition()
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
L.elasticMarker = (latLng, options) => {
|
|
161
|
+
return new L.ElasticMarker(latLng, options)
|
|
162
|
+
}
|