hn-map 1.0.10 → 1.1.1
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 +5 -22
- package/dist/index.js +2313 -610
- package/package.json +11 -8
- package/src/base/gaode_entity.ts +61 -0
- package/src/base/mars3d_entity.ts +64 -0
- package/src/base/siji_entity.ts +118 -0
- package/src/graphic/circle.ts +218 -0
- package/src/graphic/divPoint.ts +133 -0
- package/src/graphic/imagePoint.ts +237 -0
- package/src/graphic/label.ts +330 -0
- package/src/graphic/line.ts +345 -0
- package/src/graphic/numPoint.ts +290 -0
- package/src/graphic/point.ts +234 -0
- package/src/graphic/polygon.ts +188 -0
- package/src/graphic/rectangle.ts +202 -0
- package/src/index.ts +213 -0
- package/src/layer/cluster.ts +276 -0
- package/src/layer/geoJson.ts +174 -0
- package/src/layer/heatMap.ts +163 -0
- package/src/layer/layer.ts +464 -0
- package/src/layer/pointCloud.ts +78 -0
- package/src/map.ts +433 -0
- package/src/other/route.ts +457 -0
- package/src/types/globals.d.ts +5 -0
- package/src/util.ts +216 -0
- package/src/base/gaode_entity.js +0 -59
- package/src/base/mars3d_entity.js +0 -50
- package/src/graphic/circle.js +0 -159
- package/src/graphic/divPoint.js +0 -86
- package/src/graphic/imagePoint.js +0 -163
- package/src/graphic/label.js +0 -176
- package/src/graphic/line.js +0 -203
- package/src/graphic/numPoint.js +0 -119
- package/src/graphic/point.js +0 -144
- package/src/graphic/polygon.js +0 -111
- package/src/graphic/rectangle.js +0 -115
- package/src/index.js +0 -105
- package/src/layer/cluster.js +0 -277
- package/src/layer/geoJson.js +0 -174
- package/src/layer/heatMap.js +0 -163
- package/src/layer/layer.js +0 -311
- package/src/layer/pointCloud.js +0 -78
- package/src/map.js +0 -303
- package/src/other/route.js +0 -217
- package/src/util.js +0 -103
package/src/index.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import map from './map.js'
|
|
2
|
-
import layer from './layer/layer.js'
|
|
3
|
-
import point from './graphic/point.js'
|
|
4
|
-
import numPoint from './graphic/numPoint.js'
|
|
5
|
-
import imagePoint from './graphic/imagePoint.js'
|
|
6
|
-
import divPoint from './graphic/divPoint.js'
|
|
7
|
-
import label from './graphic/label.js'
|
|
8
|
-
import line from './graphic/line.js'
|
|
9
|
-
import circle from './graphic/circle.js'
|
|
10
|
-
import rectangle from './graphic/rectangle.js'
|
|
11
|
-
import polygon from './graphic/polygon.js'
|
|
12
|
-
import route from './other/route.js'
|
|
13
|
-
import heatMap from './layer/heatMap.js'
|
|
14
|
-
import cluster from './layer/cluster.js'
|
|
15
|
-
import pointCloud from './layer/pointCloud.js'
|
|
16
|
-
import geoJson from './layer/geoJson.js'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export default class hnMap {
|
|
20
|
-
|
|
21
|
-
id = null
|
|
22
|
-
option = null
|
|
23
|
-
mapType = null
|
|
24
|
-
|
|
25
|
-
// 允许构造函数
|
|
26
|
-
static allowConstruction = false
|
|
27
|
-
|
|
28
|
-
constructor(id, option, mapType) {
|
|
29
|
-
if (!hnMap.allowConstruction) {
|
|
30
|
-
throw new Error('此构造方法不允许直接调用,请调用create方法进行实例化');
|
|
31
|
-
}
|
|
32
|
-
this.id = id
|
|
33
|
-
this.option = option
|
|
34
|
-
// 地图类型
|
|
35
|
-
this.mapType = mapType
|
|
36
|
-
|
|
37
|
-
// 获取及创建地图对象
|
|
38
|
-
const Map = map(this)
|
|
39
|
-
this.map = new Map(this.id, this.option)
|
|
40
|
-
this.Layer = layer(this)
|
|
41
|
-
|
|
42
|
-
// 添加地图矢量图形类
|
|
43
|
-
this.Point = point(this)
|
|
44
|
-
this.NumPoint = numPoint(this)
|
|
45
|
-
this.ImagePoint = imagePoint(this)
|
|
46
|
-
this.DivPoint = divPoint(this)
|
|
47
|
-
this.Label = label(this)
|
|
48
|
-
this.Line = line(this)
|
|
49
|
-
this.Circle = circle(this)
|
|
50
|
-
this.Rectangle = rectangle(this)
|
|
51
|
-
this.Polygon = polygon(this)
|
|
52
|
-
this.Route = route(this)
|
|
53
|
-
this.HeatMap = heatMap(this)
|
|
54
|
-
this.Cluster = cluster(this)
|
|
55
|
-
this.PointCloud = pointCloud(this)
|
|
56
|
-
this.GeoJson = geoJson(this)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static async create(id, option, mapType) {
|
|
60
|
-
hnMap.allowConstruction = true
|
|
61
|
-
|
|
62
|
-
switch (mapType) {
|
|
63
|
-
case 'mars3d':
|
|
64
|
-
const currentScriptUrl = new URL(import.meta.url).origin;
|
|
65
|
-
await loadResource(currentScriptUrl + '/lib/Cesium/Widgets/widgets.css', 'css')
|
|
66
|
-
await loadResource(currentScriptUrl + '/lib/Cesium/Cesium.js', 'js')
|
|
67
|
-
await loadResource(currentScriptUrl + '/lib/turf/turf.min.js', 'js')
|
|
68
|
-
await loadResource(currentScriptUrl + '/lib/mars3d/mars3d.css', 'css')
|
|
69
|
-
await loadResource(currentScriptUrl + '/lib/mars3d/mars3d.js', 'js')
|
|
70
|
-
await loadResource(currentScriptUrl + '/lib/mars3d/plugins/heatmap/heatmap.js', 'js')
|
|
71
|
-
await loadResource(currentScriptUrl + '/lib/mars3d/plugins/heatmap/mars3d-heatmap.js', 'js')
|
|
72
|
-
|
|
73
|
-
break
|
|
74
|
-
case 'gaode':
|
|
75
|
-
await loadResource(`https://webapi.amap.com/maps?v=2.0&key=${option.gaode_key}&plugin=AMap.HeatMap,AMap.MarkerCluster,AMap.MoveAnimation`, 'js')
|
|
76
|
-
await loadResource('https://a.amap.com/jsapi_demos/static/data3d/lib/three.117.js', 'js')
|
|
77
|
-
await loadResource('https://a.amap.com/jsapi_demos/static/data3d/lib/GLTFLoader.117.min.js', 'js')
|
|
78
|
-
break
|
|
79
|
-
case 'siji':
|
|
80
|
-
await loadResource('https://map.sgcc.com.cn/maps?v=3.0.0', 'js')
|
|
81
|
-
}
|
|
82
|
-
return new hnMap(id, option, mapType);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const loadResource = (path, type) => {
|
|
88
|
-
return new Promise((resolve, reject) => {
|
|
89
|
-
|
|
90
|
-
if (type === 'css') {
|
|
91
|
-
const link = document.createElement('link')
|
|
92
|
-
link.rel = 'stylesheet'
|
|
93
|
-
link.href = path
|
|
94
|
-
link.onload = resolve;
|
|
95
|
-
link.onerror = reject;
|
|
96
|
-
document.head.appendChild(link)
|
|
97
|
-
} else {
|
|
98
|
-
const script = document.createElement('script')
|
|
99
|
-
script.src = path
|
|
100
|
-
script.onload = resolve;
|
|
101
|
-
script.onerror = reject;
|
|
102
|
-
document.body.appendChild(script)
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
}
|
package/src/layer/cluster.js
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import {deepMerge, wgs84ToGcj02Format} from '../util.js'
|
|
2
|
-
import Layer from "./layer.js";
|
|
3
|
-
|
|
4
|
-
export default (hnMap) => {
|
|
5
|
-
|
|
6
|
-
const defaultOption = {
|
|
7
|
-
id: "",
|
|
8
|
-
position: [],
|
|
9
|
-
pixelRange: 20,
|
|
10
|
-
cluster: true,
|
|
11
|
-
image: '',
|
|
12
|
-
width: 20,
|
|
13
|
-
height: 20,
|
|
14
|
-
data: null
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class mars3d_class extends Layer {
|
|
18
|
-
type = 'cluster'
|
|
19
|
-
id = null
|
|
20
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
21
|
-
config_layer = null
|
|
22
|
-
config_label = null
|
|
23
|
-
children = null
|
|
24
|
-
layerEntity = null
|
|
25
|
-
|
|
26
|
-
constructor(option) {
|
|
27
|
-
super(option)
|
|
28
|
-
this.id = option.id
|
|
29
|
-
this.children = []
|
|
30
|
-
deepMerge(this.option, option)
|
|
31
|
-
this.config_layer = this.formatConfigLayer(this.option)
|
|
32
|
-
this.config_label = this.formatConfigLabel(this.option)
|
|
33
|
-
this.layerEntity = new mars3d.layer.GraphicLayer(this.config_layer)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 格式化layer配置
|
|
37
|
-
formatConfigLayer(option) {
|
|
38
|
-
return {
|
|
39
|
-
id: option.id,
|
|
40
|
-
cluster: {
|
|
41
|
-
enabled: option.cluster,
|
|
42
|
-
pixelRange: option.pixelRange
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 格式化点位配置
|
|
48
|
-
formatConfigLabel(option) {
|
|
49
|
-
return {
|
|
50
|
-
id: option.id,
|
|
51
|
-
image: option.image,
|
|
52
|
-
width: option.width,
|
|
53
|
-
height: option.height,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
clearEntity() {
|
|
58
|
-
this.children = []
|
|
59
|
-
this.layerEntity.clear()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
addEntity(entity) {
|
|
63
|
-
this.children.push(entity)
|
|
64
|
-
this.layerEntity.addGraphic(entity.graphic)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setPosition(data) {
|
|
68
|
-
this.clearEntity()
|
|
69
|
-
data.forEach((item, index) => {
|
|
70
|
-
let imagePointOption = {
|
|
71
|
-
id: this.config_label.id + '_point' + item.id,
|
|
72
|
-
position: item.position,
|
|
73
|
-
image: this.config_label.image,
|
|
74
|
-
height: this.config_label.height,
|
|
75
|
-
width: this.config_label.width,
|
|
76
|
-
data: item.data
|
|
77
|
-
}
|
|
78
|
-
const imagePoint = new hnMap.ImagePoint(imagePointOption);
|
|
79
|
-
this.addEntity(imagePoint)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
destroy() {
|
|
84
|
-
this.clearEntity()
|
|
85
|
-
this.layerEntity.remove(true)
|
|
86
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// 添加属性弹窗
|
|
90
|
-
addPopupByAttr() {
|
|
91
|
-
this.layerEntity.bindPopup((event) => {
|
|
92
|
-
const data = event.graphic.attr
|
|
93
|
-
return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 添加自定义dom弹窗
|
|
98
|
-
addCustomPopup(getCustomDom) {
|
|
99
|
-
this.layerEntity.bindPopup(async (event) => {
|
|
100
|
-
if (event.graphic.attr) {
|
|
101
|
-
const data = event.graphic.attr || {};
|
|
102
|
-
return await getCustomDom(data);
|
|
103
|
-
}
|
|
104
|
-
}, {offsetY: -20});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
flyTo() {
|
|
108
|
-
this.layerEntity.flyTo()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getEntity(entityParam) {
|
|
112
|
-
let entity
|
|
113
|
-
if (typeof entityParam == 'string') {
|
|
114
|
-
entity = this.children.find(v => v.id === entityParam)
|
|
115
|
-
} else {
|
|
116
|
-
entity = entityParam
|
|
117
|
-
}
|
|
118
|
-
if (!entity) {
|
|
119
|
-
return Promise.reject(new Error('未找到此图形'))
|
|
120
|
-
}
|
|
121
|
-
return entity
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 手动打开聚合功能
|
|
125
|
-
openCluster() {
|
|
126
|
-
deepMerge(this.option, {cluster: true,})
|
|
127
|
-
this.config_layer = this.formatConfigLayer(this.option)
|
|
128
|
-
this.layerEntity.clusterEnabled = true
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 手动关闭聚合功能
|
|
132
|
-
closeCluster() {
|
|
133
|
-
deepMerge(this.option, {cluster: false,})
|
|
134
|
-
this.config_layer = this.formatConfigLayer(this.option)
|
|
135
|
-
this.layerEntity.clusterEnabled = false
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
class gaode_class {
|
|
141
|
-
|
|
142
|
-
id = null
|
|
143
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
144
|
-
config = null
|
|
145
|
-
layerEntity = null
|
|
146
|
-
// 创建全局信息窗口实例
|
|
147
|
-
infoWindow = null
|
|
148
|
-
|
|
149
|
-
constructor(option) {
|
|
150
|
-
this.id = option.id
|
|
151
|
-
deepMerge(this.option, option)
|
|
152
|
-
this.config = this.formatConfig(this.option)
|
|
153
|
-
this.layerEntity = new AMap.MarkerCluster(hnMap.map.map, this.config.position, this.config);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
formatConfig(option) {
|
|
157
|
-
const position = option.position.map((item, index) => {
|
|
158
|
-
return {
|
|
159
|
-
lnglat: wgs84ToGcj02Format(item),
|
|
160
|
-
// 添加弹窗属性参数
|
|
161
|
-
extData: {
|
|
162
|
-
id: this.id + '_point' + index
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
const count = position.length;
|
|
167
|
-
const _renderClusterMarker = (context) => {
|
|
168
|
-
var factor = Math.pow(context.count / count, 1 / 18);
|
|
169
|
-
var div = document.createElement('div');
|
|
170
|
-
var Hue = 180 - factor * 180;
|
|
171
|
-
var bgColor = 'hsla(' + Hue + ',100%,40%,0.7)';
|
|
172
|
-
var fontColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
173
|
-
var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
|
|
174
|
-
var shadowColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
175
|
-
div.style.backgroundColor = bgColor;
|
|
176
|
-
var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
|
|
177
|
-
div.style.width = div.style.height = size + 'px';
|
|
178
|
-
div.style.border = 'solid 1px ' + borderColor;
|
|
179
|
-
div.style.borderRadius = size / 2 + 'px';
|
|
180
|
-
div.style.boxShadow = '0 0 5px ' + shadowColor;
|
|
181
|
-
div.innerHTML = context.count;
|
|
182
|
-
div.style.lineHeight = size + 'px';
|
|
183
|
-
div.style.color = fontColor;
|
|
184
|
-
div.style.fontSize = '14px';
|
|
185
|
-
div.style.textAlign = 'center';
|
|
186
|
-
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
|
|
187
|
-
context.marker.setContent(div)
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const _renderMarker = (context) => {
|
|
192
|
-
let icon = new AMap.Icon({
|
|
193
|
-
image: this.option.style.image,
|
|
194
|
-
imageSize: new AMap.Size(this.option.style.height, this.option.style.width),
|
|
195
|
-
size: new AMap.Size(this.option.style.height, this.option.style.width),
|
|
196
|
-
})
|
|
197
|
-
context.marker.setIcon(icon)
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
id: option.id,
|
|
201
|
-
position,
|
|
202
|
-
gridSize: option.pixelRange, // 设置网格像素大小
|
|
203
|
-
clusterByZoomChange: true,
|
|
204
|
-
renderClusterMarker: _renderClusterMarker, // 自定义聚合点样式
|
|
205
|
-
renderMarker: _renderMarker, // 自定义非聚合点样式
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
setPosition(position) {
|
|
210
|
-
deepMerge(this.option, {position: position})
|
|
211
|
-
this.config = this.formatConfig(this.option)
|
|
212
|
-
this.layerEntity.setData(this.config.position)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
destroy() {
|
|
217
|
-
this.layerEntity.setMap(null)
|
|
218
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
flyTo() {
|
|
222
|
-
let totalLng = 0;
|
|
223
|
-
let totalLat = 0;
|
|
224
|
-
this.config.position.map(item => {
|
|
225
|
-
totalLng += item.lnglat.lng;
|
|
226
|
-
totalLat += item.lnglat.lat;
|
|
227
|
-
})
|
|
228
|
-
const centerLng = totalLng / this.config.position.length;
|
|
229
|
-
const centerLat = totalLat / this.config.position.length;
|
|
230
|
-
hnMap.map.map.setCenter([centerLng, centerLat])
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// 添加属性弹窗
|
|
234
|
-
addPopupByAttr() {
|
|
235
|
-
if (!this.infoWindow) {
|
|
236
|
-
this.infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
this.layerEntity.on('click', (cluster) => {
|
|
240
|
-
if (cluster.clusterData.length === 1) {
|
|
241
|
-
let content = ''
|
|
242
|
-
const data = cluster.clusterData[0].extData
|
|
243
|
-
for (const key in data) {
|
|
244
|
-
content += `<div>${key}: ${data[key]}</div>`
|
|
245
|
-
}
|
|
246
|
-
this.infoWindow.setContent(content);
|
|
247
|
-
this.infoWindow.open(hnMap.map.map, cluster.marker._position);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
})
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 添加自定义dom弹窗
|
|
254
|
-
addCustomPopup(getCustomDom) {
|
|
255
|
-
if (!this.infoWindow) {
|
|
256
|
-
this.infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
this.layerEntity.on('click', (cluster) => {
|
|
260
|
-
if (cluster.clusterData.length === 1) {
|
|
261
|
-
let content = ''
|
|
262
|
-
const data = cluster.clusterData[0].extData
|
|
263
|
-
const dom = getCustomDom(data);
|
|
264
|
-
this.infoWindow.setContent(dom);
|
|
265
|
-
this.infoWindow.open(hnMap.map.map, cluster.marker._position);
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const fn = {
|
|
273
|
-
mars3d: mars3d_class,
|
|
274
|
-
gaode: gaode_class
|
|
275
|
-
}
|
|
276
|
-
return fn[hnMap.mapType]
|
|
277
|
-
}
|
package/src/layer/geoJson.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import {deepMerge, wgs84ToGcj02Format} from '../util.js'
|
|
2
|
-
|
|
3
|
-
let baseGeoData = {
|
|
4
|
-
type: 'FeatureCollection',
|
|
5
|
-
name: '',
|
|
6
|
-
crs: {},
|
|
7
|
-
features: [
|
|
8
|
-
{
|
|
9
|
-
type: 'Feature',
|
|
10
|
-
properties: {},
|
|
11
|
-
geometry: {
|
|
12
|
-
type: 'MultiPolygon',
|
|
13
|
-
coordinates: [[[]]]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
export default (hnMap) => {
|
|
19
|
-
|
|
20
|
-
const defaultOption = {
|
|
21
|
-
id: "",
|
|
22
|
-
data: baseGeoData,
|
|
23
|
-
opacity: 1,
|
|
24
|
-
line: {
|
|
25
|
-
show: true,
|
|
26
|
-
color: "#ff00ff",
|
|
27
|
-
opacity: 1,
|
|
28
|
-
width: 2,
|
|
29
|
-
},
|
|
30
|
-
area: {
|
|
31
|
-
show: false,
|
|
32
|
-
color: "#ffff00",
|
|
33
|
-
opacity: 1,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
class mars3d_class {
|
|
38
|
-
type = 'geoJson'
|
|
39
|
-
id = null
|
|
40
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
41
|
-
config = null
|
|
42
|
-
layerEntity = null
|
|
43
|
-
|
|
44
|
-
constructor(option) {
|
|
45
|
-
this.id = option.id
|
|
46
|
-
deepMerge(this.option, option)
|
|
47
|
-
this.config = this.formatConfig(this.option)
|
|
48
|
-
this.layerEntity = new mars3d.layer.GeoJsonLayer(this.config)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
formatConfig(option) {
|
|
52
|
-
return {
|
|
53
|
-
name: option.id,
|
|
54
|
-
id: option.id,
|
|
55
|
-
allowDrillPick: true,
|
|
56
|
-
data: option.data,
|
|
57
|
-
symbol: {
|
|
58
|
-
styleOptions: {
|
|
59
|
-
clampToGround: true,
|
|
60
|
-
fill: option.area.show,
|
|
61
|
-
randomColor: !!(option.area.show && option.area.color), // 随机色
|
|
62
|
-
outline: option.line.show,
|
|
63
|
-
opacity: option.opacity,
|
|
64
|
-
outlineStyle: {
|
|
65
|
-
color: option.line.color,
|
|
66
|
-
width: option.line.width,
|
|
67
|
-
opacity: option.line.opacity,
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
// flyTo: true,
|
|
72
|
-
// attr: option.data
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
set(option) {
|
|
77
|
-
deepMerge(this.option, option)
|
|
78
|
-
this.config = this.formatConfig(this.option)
|
|
79
|
-
this.layerEntity.setOptions(this.config)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
customStyle(callback) {
|
|
83
|
-
this.layerEntity.options.symbol.callback = (attr) => {
|
|
84
|
-
return callback(attr)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
destroy() {
|
|
89
|
-
this.layerEntity.remove(true)
|
|
90
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setData(data) {
|
|
94
|
-
this.layerEntity.loadGeoJSON(data, {clear: true})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
clear() {
|
|
98
|
-
this.layerEntity.clear()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
flyTo() {
|
|
102
|
-
this.layerEntity.flyTo()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 添加属性弹窗
|
|
106
|
-
addPopupByAttr() {
|
|
107
|
-
this.layerEntity.bindPopup((event) => {
|
|
108
|
-
if (event.graphic.attr) {
|
|
109
|
-
const data = event.graphic.attr
|
|
110
|
-
return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 添加自定义dom弹窗
|
|
116
|
-
addCustomPopup(getCustomDom) {
|
|
117
|
-
this.layerEntity.bindPopup(async (event) => {
|
|
118
|
-
if (event.graphic.attr) {
|
|
119
|
-
const data = event.graphic.attr || {};
|
|
120
|
-
return await getCustomDom(data);
|
|
121
|
-
}
|
|
122
|
-
}, {offsetY: -20});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class gaode_class {
|
|
128
|
-
|
|
129
|
-
id = null
|
|
130
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
131
|
-
config = null
|
|
132
|
-
layerEntity = null
|
|
133
|
-
|
|
134
|
-
constructor(option) {
|
|
135
|
-
this.id = option.id
|
|
136
|
-
deepMerge(this.option, option)
|
|
137
|
-
this.config = this.formatConfig(this.option)
|
|
138
|
-
this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
formatConfig(option) {
|
|
142
|
-
const data = option.position.map(v => {
|
|
143
|
-
return {lng: v.lng, lat: v.lat, count: v.value}
|
|
144
|
-
})
|
|
145
|
-
const amapData = wgs84ToGcj02Format(data)
|
|
146
|
-
|
|
147
|
-
return {}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
set(option) {
|
|
151
|
-
deepMerge(this.option, option)
|
|
152
|
-
this.config = this.formatConfig(this.option)
|
|
153
|
-
this.layerEntity.setOptions(this.config)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
destroy() {
|
|
157
|
-
this.layerEntity.setMap(null)
|
|
158
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
flyTo() {
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const fn = {
|
|
169
|
-
mars3d: mars3d_class,
|
|
170
|
-
gaode: gaode_class
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return fn[hnMap.mapType]
|
|
174
|
-
}
|
package/src/layer/heatMap.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {deepMerge, wgs84ToGcj02Format} from '../util.js'
|
|
2
|
-
|
|
3
|
-
export default (hnMap) => {
|
|
4
|
-
|
|
5
|
-
const defaultOption = {
|
|
6
|
-
id: "",
|
|
7
|
-
position: [],
|
|
8
|
-
allowDrillPick: true,
|
|
9
|
-
max: null,
|
|
10
|
-
min: null,
|
|
11
|
-
radius: 25,
|
|
12
|
-
minOpacity: 0.1,
|
|
13
|
-
maxOpacity: 0.8,
|
|
14
|
-
opacity: 1,
|
|
15
|
-
blur: 0.85,
|
|
16
|
-
gradient: {},
|
|
17
|
-
scaleByDistance: false,
|
|
18
|
-
clampToGround: true,
|
|
19
|
-
data: null
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class mars3d_class {
|
|
23
|
-
type = 'heatMap'
|
|
24
|
-
id = null
|
|
25
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
26
|
-
config = null
|
|
27
|
-
layerEntity = null
|
|
28
|
-
|
|
29
|
-
constructor(option) {
|
|
30
|
-
this.id = option.id
|
|
31
|
-
deepMerge(this.option, option)
|
|
32
|
-
this.config = this.formatConfig(this.option)
|
|
33
|
-
this.layerEntity = new mars3d.layer.HeatLayer(JSON.parse(JSON.stringify(this.config)))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
formatConfig(option) {
|
|
37
|
-
return {
|
|
38
|
-
id: option.id,
|
|
39
|
-
positions: option.position,
|
|
40
|
-
allowDrillPick: option.allowDrillPick,
|
|
41
|
-
max: option.max,
|
|
42
|
-
min: option.min,
|
|
43
|
-
heatStyle: {
|
|
44
|
-
radius: option.radius,
|
|
45
|
-
minOpacity: option.minOpacity,
|
|
46
|
-
maxOpacity: option.maxOpacity,
|
|
47
|
-
blur: option.blur,
|
|
48
|
-
gradient: option.gradient,
|
|
49
|
-
},
|
|
50
|
-
style: {
|
|
51
|
-
opacity: option.opacity,
|
|
52
|
-
scaleByDistance: option.scaleByDistance,
|
|
53
|
-
clampToGround: option.clampToGround,
|
|
54
|
-
},
|
|
55
|
-
redrawZoom: true,
|
|
56
|
-
attr: option.data
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
set(option) {
|
|
61
|
-
deepMerge(this.option, option)
|
|
62
|
-
this.config = this.formatConfig(this.option)
|
|
63
|
-
this.layerEntity.setOptions(this.config)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
destroy() {
|
|
67
|
-
this.layerEntity.remove(true)
|
|
68
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
flyTo() {
|
|
72
|
-
this.layerEntity.flyTo()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
clear() {
|
|
76
|
-
this.layerEntity.clear()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
setPosition(position) {
|
|
80
|
-
deepMerge(this.option, {position})
|
|
81
|
-
this.layerEntity.setPositions(position)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
show() {
|
|
85
|
-
this.layerEntity.show = true
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
hide() {
|
|
89
|
-
this.layerEntity.show = false
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
class gaode_class {
|
|
95
|
-
|
|
96
|
-
id = null
|
|
97
|
-
option = JSON.parse(JSON.stringify(defaultOption))
|
|
98
|
-
config = null
|
|
99
|
-
layerEntity = null
|
|
100
|
-
|
|
101
|
-
constructor(option) {
|
|
102
|
-
this.id = option.id
|
|
103
|
-
deepMerge(this.option, option)
|
|
104
|
-
this.config = this.formatConfig(this.option)
|
|
105
|
-
this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config)
|
|
106
|
-
this.layerEntity.setDataSet({data: this.config.data, max: this.config.max, min: this.config.min});
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
formatConfig(option) {
|
|
111
|
-
const data = option.position.map(v => {
|
|
112
|
-
return {lng: v.lng, lat: v.lat, count: v.value}
|
|
113
|
-
})
|
|
114
|
-
const amapData = wgs84ToGcj02Format(data)
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
id: option.id,
|
|
118
|
-
radius: option.radius,
|
|
119
|
-
max: option.max,
|
|
120
|
-
min: option.min,
|
|
121
|
-
opacity: [option.minOpacity, option.maxOpacity],
|
|
122
|
-
gradient: option.gradient,
|
|
123
|
-
data: amapData,
|
|
124
|
-
extData: {
|
|
125
|
-
id: option.id,
|
|
126
|
-
data: option.data,
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
set(option) {
|
|
132
|
-
deepMerge(this.option, option)
|
|
133
|
-
this.config = this.formatConfig(this.option)
|
|
134
|
-
this.layerEntity.setOptions(this.config)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
destroy() {
|
|
138
|
-
this.layerEntity.setMap(null)
|
|
139
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(v => v.id !== this.id)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
flyTo() {
|
|
144
|
-
let totalLng = 0;
|
|
145
|
-
let totalLat = 0;
|
|
146
|
-
this.config.data.map(item => {
|
|
147
|
-
totalLng += item.lng;
|
|
148
|
-
totalLat += item.lat;
|
|
149
|
-
})
|
|
150
|
-
const centerLng = totalLng / this.config.data.length;
|
|
151
|
-
const centerLat = totalLat / this.config.data.length;
|
|
152
|
-
hnMap.map.map.setCenter([centerLng, centerLat])
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const fn = {
|
|
158
|
-
mars3d: mars3d_class,
|
|
159
|
-
gaode: gaode_class
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return fn[hnMap.mapType]
|
|
163
|
-
}
|