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
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {deepMerge, wgs84ToGcj02Format} from '../util'
|
|
2
|
+
|
|
3
|
+
export default (hnMap: any) => {
|
|
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: any = 'heatMap'
|
|
24
|
+
id: any = null
|
|
25
|
+
option: any = JSON.parse(JSON.stringify(defaultOption))
|
|
26
|
+
config: any = null
|
|
27
|
+
layerEntity: any = null
|
|
28
|
+
|
|
29
|
+
constructor(option: any) {
|
|
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: any) {
|
|
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: any) {
|
|
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: any) => 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: any) {
|
|
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: any = null
|
|
97
|
+
option: any = JSON.parse(JSON.stringify(defaultOption))
|
|
98
|
+
config: any = null
|
|
99
|
+
layerEntity: any = null
|
|
100
|
+
|
|
101
|
+
constructor(option: any) {
|
|
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: any) {
|
|
111
|
+
const data = option.position.map((v: any) => {
|
|
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: any) {
|
|
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: any) => v.id !== this.id)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
flyTo() {
|
|
144
|
+
let totalLng = 0;
|
|
145
|
+
let totalLat = 0;
|
|
146
|
+
this.config.data.map((item: any) => {
|
|
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: any = {
|
|
158
|
+
mars3d: mars3d_class,
|
|
159
|
+
gaode: gaode_class
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return fn[hnMap.mapType]
|
|
163
|
+
}
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import {deepMerge} from "../util";
|
|
2
|
+
|
|
3
|
+
export default (hnMap: any) => {
|
|
4
|
+
const defaultOption = {};
|
|
5
|
+
|
|
6
|
+
class mars3d_class {
|
|
7
|
+
type: any = "layer";
|
|
8
|
+
id: any = null;
|
|
9
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
10
|
+
config: any = null;
|
|
11
|
+
children: any = null;
|
|
12
|
+
layerEntity: any = null;
|
|
13
|
+
|
|
14
|
+
constructor(option: any) {
|
|
15
|
+
this.id = option.id;
|
|
16
|
+
this.children = [];
|
|
17
|
+
deepMerge(this.option, option);
|
|
18
|
+
this.config = this.formatConfig(this.option);
|
|
19
|
+
this.layerEntity = new mars3d.layer.GraphicLayer(this.config); // 创建图层
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
formatConfig(option: any) {
|
|
23
|
+
return option;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getEntity(id: any) {
|
|
27
|
+
return this.children.find((v: any) => v.id === id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
addEntity(entity: any) {
|
|
31
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
32
|
+
console.error("已存在同名图形" + entity.id);
|
|
33
|
+
} else {
|
|
34
|
+
this.children.push(entity);
|
|
35
|
+
this.layerEntity.addGraphic(entity.graphic); // 添加图形
|
|
36
|
+
if (entity.type == "route") {
|
|
37
|
+
entity.start();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
removeEntity(entityParam: any) {
|
|
43
|
+
const entity = this.getEntity(entityParam);
|
|
44
|
+
if (entity) {
|
|
45
|
+
this.layerEntity.removeGraphic(entity.graphic);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
clearEntity() {
|
|
50
|
+
this.children.forEach((v: any) => v.destroy());
|
|
51
|
+
this.children = [];
|
|
52
|
+
this.layerEntity.clear();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
destroy() {
|
|
56
|
+
this.clearEntity();
|
|
57
|
+
this.layerEntity.remove(true);
|
|
58
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
59
|
+
(v: any) => v.id !== this.id
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
show() {
|
|
64
|
+
this.layerEntity.show = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
hide() {
|
|
68
|
+
this.layerEntity.show = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
flyTo() {
|
|
72
|
+
this.layerEntity.flyTo();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 飞向指定的多个图形
|
|
77
|
+
* @param entities
|
|
78
|
+
*/
|
|
79
|
+
flyToCustomEntities(entities: any) {
|
|
80
|
+
// 计算所有线的最小最大坐标
|
|
81
|
+
let minLon = 180,
|
|
82
|
+
maxLon = -180,
|
|
83
|
+
minLat = 90,
|
|
84
|
+
maxLat = -90;
|
|
85
|
+
|
|
86
|
+
entities.forEach((line: any) => {
|
|
87
|
+
line.graphic.positions.forEach((pos: any) => {
|
|
88
|
+
const carto = mars3d.Cesium.Cartographic.fromCartesian(pos);
|
|
89
|
+
const lon = mars3d.Cesium.Math.toDegrees(carto.longitude);
|
|
90
|
+
const lat = mars3d.Cesium.Math.toDegrees(carto.latitude);
|
|
91
|
+
|
|
92
|
+
minLon = Math.min(minLon, lon);
|
|
93
|
+
maxLon = Math.max(maxLon, lon);
|
|
94
|
+
minLat = Math.min(minLat, lat);
|
|
95
|
+
maxLat = Math.max(maxLat, lat);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 飞到这个矩形范围
|
|
100
|
+
hnMap.map.map.flyToExtent({
|
|
101
|
+
xmin: minLon,
|
|
102
|
+
xmax: maxLon,
|
|
103
|
+
ymin: minLat,
|
|
104
|
+
ymax: maxLat,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 添加属性弹窗
|
|
109
|
+
addPopupByAttr() {
|
|
110
|
+
this.layerEntity.bindPopup((event: any) => {
|
|
111
|
+
console.log(event.graphic, "====event.graphic==");
|
|
112
|
+
if (event.graphic.attr) {
|
|
113
|
+
const data = event.graphic.attr;
|
|
114
|
+
return mars3d.Util.getTemplateHtml({
|
|
115
|
+
title: "详情",
|
|
116
|
+
template: "all",
|
|
117
|
+
attr: data,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 添加自定义dom弹窗
|
|
124
|
+
addCustomPopup(getCustomDom: any, option = {offsetY: -20}) {
|
|
125
|
+
this.layerEntity.bindPopup(async (event: any) => {
|
|
126
|
+
if (event.graphic.attr) {
|
|
127
|
+
const data = event.graphic.attr || {};
|
|
128
|
+
const dom = await getCustomDom(data);
|
|
129
|
+
if (dom) {
|
|
130
|
+
return dom;
|
|
131
|
+
} else {
|
|
132
|
+
hnMap.map.closePopup();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}, option);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class gaode_class {
|
|
140
|
+
id: any = null;
|
|
141
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
142
|
+
config: any = null;
|
|
143
|
+
children: any = null;
|
|
144
|
+
layerEntity: any = null;
|
|
145
|
+
// 创建全局信息窗口实例
|
|
146
|
+
propsInfoWindow: any = null;
|
|
147
|
+
customInfoWindow: any = null;
|
|
148
|
+
getCustomDom: any = null;
|
|
149
|
+
|
|
150
|
+
constructor(option: any) {
|
|
151
|
+
this.id = option.id;
|
|
152
|
+
this.children = [];
|
|
153
|
+
deepMerge(this.option, option);
|
|
154
|
+
this.config = this.formatConfig(this.option);
|
|
155
|
+
this.layerEntity = new AMap.OverlayGroup([]); // 创建图层
|
|
156
|
+
this.layerEntity.id = option.id;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
formatConfig(option: any) {
|
|
160
|
+
return option;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getEntity(entityParam: any) {
|
|
164
|
+
return this.children.find((v: any) => v.id === entityParam);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
addEntity(entity: any) {
|
|
168
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
169
|
+
console.error("已存在同名图形" + entity.id);
|
|
170
|
+
} else {
|
|
171
|
+
this.children.push(entity);
|
|
172
|
+
this.layerEntity.addOverlay(entity.graphic); // 添加图形
|
|
173
|
+
|
|
174
|
+
// 图层添加新图形后,需要重新调用绑定点击弹窗方法
|
|
175
|
+
if (this.propsInfoWindow) {
|
|
176
|
+
this.addPopupByAttr();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (this.customInfoWindow) {
|
|
180
|
+
// this.addCustomPopup()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
removeEntity(entityParam: any) {
|
|
186
|
+
const entity = this.getEntity(entityParam);
|
|
187
|
+
|
|
188
|
+
if (entity) {
|
|
189
|
+
this.children = this.children.filter((v: any): any => {
|
|
190
|
+
return v.id !== entity.id;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
this.layerEntity.removeOverlay(entity.graphic);
|
|
194
|
+
entity.destroy();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
clearEntity() {
|
|
199
|
+
this.children = [];
|
|
200
|
+
this.layerEntity.clearOverlays();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
destroy() {
|
|
204
|
+
this.clearEntity();
|
|
205
|
+
hnMap.map.map.remove(this.layerEntity);
|
|
206
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
207
|
+
(v: any) => v.id !== this.id
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 添加属性弹窗
|
|
212
|
+
addPopupByAttr() {
|
|
213
|
+
if (!this.propsInfoWindow) {
|
|
214
|
+
this.propsInfoWindow = new AMap.InfoWindow({
|
|
215
|
+
offset: new AMap.Pixel(0, -30),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const handleClick = (e: any) => {
|
|
219
|
+
const overlay = e.target; // 获取被点击的具体覆盖物
|
|
220
|
+
const data = overlay.getOptions().extData.data;
|
|
221
|
+
let content = "";
|
|
222
|
+
for (const key in data) {
|
|
223
|
+
content += `<div>${key}: ${data[key]}</div>`;
|
|
224
|
+
}
|
|
225
|
+
this.propsInfoWindow.setContent(content);
|
|
226
|
+
this.propsInfoWindow.open(hnMap.map.map, e.lnglat);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
this.layerEntity.off("click", handleClick);
|
|
230
|
+
this.layerEntity.on("click", handleClick);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 添加自定义dom弹窗
|
|
234
|
+
addCustomPopup(getCustomDom: any) {
|
|
235
|
+
if (!this.customInfoWindow) {
|
|
236
|
+
this.customInfoWindow = new AMap.InfoWindow({
|
|
237
|
+
offset: new AMap.Pixel(0, -30),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
if (getCustomDom) {
|
|
241
|
+
this.getCustomDom = getCustomDom;
|
|
242
|
+
}
|
|
243
|
+
const handleClick = (e: any) => {
|
|
244
|
+
const overlay = e.target; // 获取被点击的具体覆盖物
|
|
245
|
+
const data = overlay.getOptions().extData.data;
|
|
246
|
+
const dom = this.getCustomDom(data);
|
|
247
|
+
this.customInfoWindow.setContent(dom);
|
|
248
|
+
this.customInfoWindow.open(hnMap.map.map, e.lnglat);
|
|
249
|
+
};
|
|
250
|
+
this.layerEntity.off("click", handleClick);
|
|
251
|
+
this.layerEntity.on("click", handleClick);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
class siji_class {
|
|
256
|
+
id = null;
|
|
257
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
258
|
+
config: any = null;
|
|
259
|
+
children: any = null;
|
|
260
|
+
hideChildrenMap: any = null;
|
|
261
|
+
layerEntity: any = null;
|
|
262
|
+
infoWindow: any = null;
|
|
263
|
+
entity: any = null;
|
|
264
|
+
|
|
265
|
+
constructor(option: any) {
|
|
266
|
+
this.id = option.id;
|
|
267
|
+
this.children = [];
|
|
268
|
+
this.hideChildrenMap = {};
|
|
269
|
+
deepMerge(this.option, option);
|
|
270
|
+
this.config = this.formatConfig(this.option);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
formatConfig(option: any) {
|
|
274
|
+
return option;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
updateEntity(entity: any, viewPos: any) {
|
|
278
|
+
const isUpdateEntity = hnMap.map.level >= Number(entity.option.distanceDisplayCondition_far) && hnMap.map.level <= Number(entity.option.distanceDisplayCondition_near)
|
|
279
|
+
if (isUpdateEntity) {
|
|
280
|
+
if (!entity.show && this.isIncludesLabel(entity.option.position, viewPos)) {
|
|
281
|
+
this.addLevelEntity(entity);
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
if (entity.show) {
|
|
285
|
+
this.removeLevelEntity(entity);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 判断坐标是否在视口范围内
|
|
291
|
+
isIncludesLabel(p: any, viewPos: any) {
|
|
292
|
+
return p[0] > viewPos.xmin && p[0] < viewPos.xmax && p[1] > viewPos.ymin && p[1] < viewPos.ymax
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
getEntity(id: any) {
|
|
296
|
+
return this.children.find((v: any) => v.id === id);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
addEntity(entity: any) {
|
|
300
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
301
|
+
console.error("已存在同名图形" + entity.id);
|
|
302
|
+
} else {
|
|
303
|
+
this.children.push(entity);
|
|
304
|
+
const isUpdateEntity = hnMap.map.level >= Number(entity.option.distanceDisplayCondition_far) && hnMap.map.level <= Number(entity.option.distanceDisplayCondition_near)
|
|
305
|
+
if (!entity.option.distanceDisplayCondition || isUpdateEntity) {
|
|
306
|
+
this.addLevelEntity(entity)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
removeEntity(entityParam: any) {
|
|
312
|
+
const entity = this.getEntity(entityParam);
|
|
313
|
+
if (entity) {
|
|
314
|
+
this.children = this.children.filter((v: any) => {
|
|
315
|
+
return v.id !== entity.id;
|
|
316
|
+
});
|
|
317
|
+
this.removeLevelEntity(entity)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
addLevelEntity(entity: any) {
|
|
322
|
+
if (entity.type == "imagePoint") {
|
|
323
|
+
hnMap.map.map.loadImage(
|
|
324
|
+
entity.option.image,
|
|
325
|
+
function (error: any, image: any) {
|
|
326
|
+
hnMap.map.map.addImage(entity.id + "_image", image);
|
|
327
|
+
hnMap.map.map.addLayer(entity.config);
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
} else if (entity.type == "numPoint") {
|
|
331
|
+
hnMap.map.map.addLayer(entity.config);
|
|
332
|
+
hnMap.map.map.addLayer(entity.configLabel);
|
|
333
|
+
} else if (entity.type == "divPoint") {
|
|
334
|
+
entity.graphic.setLngLat(entity.option.position).addTo(hnMap.map.map);
|
|
335
|
+
} else if (entity.type == "circle") {
|
|
336
|
+
let featureArr = {
|
|
337
|
+
type: "Feature",
|
|
338
|
+
properties: {
|
|
339
|
+
centerPoint: entity.option.position,
|
|
340
|
+
radius: entity.option.radius,
|
|
341
|
+
},
|
|
342
|
+
geometry: {
|
|
343
|
+
type: "Polygon",
|
|
344
|
+
coordinates: [],
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
entity.graphic.addFeature(featureArr);
|
|
348
|
+
// entity.graphic = new SGMap.DrawCircleHandler(entity.config);
|
|
349
|
+
} else if (entity.type == "route") {
|
|
350
|
+
hnMap.map.map.addLayer(entity.config_routeline);
|
|
351
|
+
hnMap.map.map.addLayer(entity.config_routeplay);
|
|
352
|
+
entity.createCar();
|
|
353
|
+
entity.chunkData = entity.joinLinePoint();
|
|
354
|
+
entity.start();
|
|
355
|
+
} else {
|
|
356
|
+
|
|
357
|
+
hnMap.map.map.addLayer(entity.config);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
entity.show = true;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
removeLevelEntity(entity: any) {
|
|
364
|
+
|
|
365
|
+
if (entity) {
|
|
366
|
+
if (entity.type == "circle") {
|
|
367
|
+
entity.graphic.remove();
|
|
368
|
+
entity.graphic.clearData();
|
|
369
|
+
} else if (entity.type == "numPoint") {
|
|
370
|
+
hnMap.map.map.removeLayer(entity.config.id);
|
|
371
|
+
hnMap.map.map.removeSource(entity.config.id);
|
|
372
|
+
hnMap.map.map.removeLayer(entity.configLabel.id);
|
|
373
|
+
hnMap.map.map.removeSource(entity.configLabel.id);
|
|
374
|
+
} else if (entity.type == "divPoint") {
|
|
375
|
+
entity.graphic.remove();
|
|
376
|
+
} else if (entity.type == "route") {
|
|
377
|
+
hnMap.map.map.removeLayer(entity.config_routeline.id);
|
|
378
|
+
hnMap.map.map.removeSource(entity.config_routeline.id);
|
|
379
|
+
hnMap.map.map.removeLayer(entity.config_routeplay.id);
|
|
380
|
+
hnMap.map.map.removeSource(entity.config_routeplay.id);
|
|
381
|
+
entity.imgMarker.remove();
|
|
382
|
+
} else {
|
|
383
|
+
hnMap.map.map.removeLayer(entity.id);
|
|
384
|
+
hnMap.map.map.removeSource(entity.id);
|
|
385
|
+
}
|
|
386
|
+
entity.show = false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
clearEntity() {
|
|
391
|
+
this.children.forEach((v: any) => {
|
|
392
|
+
this.removeEntity(v.id)
|
|
393
|
+
});
|
|
394
|
+
this.children = [];
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
destroy() {
|
|
398
|
+
this.clearEntity();
|
|
399
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
400
|
+
(v: any) => v.id !== this.id
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// 添加属性弹窗
|
|
405
|
+
addPopupByAttr() {
|
|
406
|
+
// 如果已有弹窗,先关闭
|
|
407
|
+
this.removePopup();
|
|
408
|
+
this.infoWindow = new SGMap.Popup({
|
|
409
|
+
offset: {bottom: [0, 0]},
|
|
410
|
+
className: "my-attrPopup-class",
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const handleClick = (e: any) => {
|
|
414
|
+
let data = e.features[0].properties;
|
|
415
|
+
|
|
416
|
+
// 创建弹窗内容
|
|
417
|
+
let content = "";
|
|
418
|
+
for (const key in data) {
|
|
419
|
+
content += `<div>${key}: ${data[key]}</div>`;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.infoWindow.setHTML(content);
|
|
423
|
+
console.log("e.lngLat===", e.lngLat);
|
|
424
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 添加自定义dom弹窗
|
|
431
|
+
addCustomPopup(getCustomDom: any) {
|
|
432
|
+
// 如果已有弹窗,先关闭
|
|
433
|
+
this.removePopup();
|
|
434
|
+
this.infoWindow = new SGMap.Popup({
|
|
435
|
+
offset: {bottom: [0, 0]},
|
|
436
|
+
className: "my-customPopup-class",
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const handleClick = (e: any) => {
|
|
440
|
+
const data = e.features[0].properties;
|
|
441
|
+
const dom = getCustomDom(data);
|
|
442
|
+
this.infoWindow.setHTML(dom);
|
|
443
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 弹窗删除
|
|
450
|
+
removePopup() {
|
|
451
|
+
if (this.infoWindow) {
|
|
452
|
+
this.infoWindow.remove();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const fn: any = {
|
|
458
|
+
mars3d: mars3d_class,
|
|
459
|
+
gaode: gaode_class,
|
|
460
|
+
siji: siji_class,
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
return fn[hnMap.mapType];
|
|
464
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {deepMerge} from "../util";
|
|
2
|
+
|
|
3
|
+
export default (hnMap: any) => {
|
|
4
|
+
|
|
5
|
+
const defaultOption = {
|
|
6
|
+
id: "",
|
|
7
|
+
name: "",
|
|
8
|
+
url: "",
|
|
9
|
+
position: null,
|
|
10
|
+
scale: 1,
|
|
11
|
+
flyTo: false,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class mars3d_class {
|
|
15
|
+
type: any = 'pointCloud'
|
|
16
|
+
id: any = null
|
|
17
|
+
option: any = JSON.parse(JSON.stringify(defaultOption))
|
|
18
|
+
config: any = null
|
|
19
|
+
layerEntity: any = null
|
|
20
|
+
|
|
21
|
+
constructor(option: any) {
|
|
22
|
+
this.id = option.id
|
|
23
|
+
deepMerge(this.option, option)
|
|
24
|
+
this.config = this.formatConfig(this.option)
|
|
25
|
+
this.layerEntity = new mars3d.layer.TilesetLayer(this.config)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
formatConfig(option: any) {
|
|
29
|
+
return {
|
|
30
|
+
id: option.id,
|
|
31
|
+
name: option.name,
|
|
32
|
+
url: option.url,
|
|
33
|
+
position: option.position,
|
|
34
|
+
scale: option.scale,
|
|
35
|
+
attr: {
|
|
36
|
+
name: option.name,
|
|
37
|
+
},
|
|
38
|
+
flyTo: option.flyTo
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
set(option: any) {
|
|
43
|
+
deepMerge(this.option, option)
|
|
44
|
+
this.config = this.formatConfig(this.option)
|
|
45
|
+
this.layerEntity.setOptions(this.config)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
destroy() {
|
|
49
|
+
this.layerEntity.remove(true)
|
|
50
|
+
hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 添加属性弹窗
|
|
54
|
+
addPopupByAttr() {
|
|
55
|
+
this.layerEntity.bindPopup((event: any) => {
|
|
56
|
+
const data = {name: event.layer.name}
|
|
57
|
+
return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
flyTo() {
|
|
62
|
+
this.layerEntity.flyTo()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class gaode_class {
|
|
67
|
+
constructor(option: any) {
|
|
68
|
+
throw new Error("高德地图不支持点云功能")
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const fn: any = {
|
|
73
|
+
mars3d: mars3d_class,
|
|
74
|
+
gaode: gaode_class
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return fn[hnMap.mapType]
|
|
78
|
+
}
|