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.
Files changed (45) hide show
  1. package/README.md +5 -22
  2. package/dist/index.js +2313 -610
  3. package/package.json +11 -8
  4. package/src/base/gaode_entity.ts +61 -0
  5. package/src/base/mars3d_entity.ts +64 -0
  6. package/src/base/siji_entity.ts +118 -0
  7. package/src/graphic/circle.ts +218 -0
  8. package/src/graphic/divPoint.ts +133 -0
  9. package/src/graphic/imagePoint.ts +237 -0
  10. package/src/graphic/label.ts +330 -0
  11. package/src/graphic/line.ts +345 -0
  12. package/src/graphic/numPoint.ts +290 -0
  13. package/src/graphic/point.ts +234 -0
  14. package/src/graphic/polygon.ts +188 -0
  15. package/src/graphic/rectangle.ts +202 -0
  16. package/src/index.ts +213 -0
  17. package/src/layer/cluster.ts +276 -0
  18. package/src/layer/geoJson.ts +174 -0
  19. package/src/layer/heatMap.ts +163 -0
  20. package/src/layer/layer.ts +464 -0
  21. package/src/layer/pointCloud.ts +78 -0
  22. package/src/map.ts +433 -0
  23. package/src/other/route.ts +457 -0
  24. package/src/types/globals.d.ts +5 -0
  25. package/src/util.ts +216 -0
  26. package/src/base/gaode_entity.js +0 -59
  27. package/src/base/mars3d_entity.js +0 -50
  28. package/src/graphic/circle.js +0 -159
  29. package/src/graphic/divPoint.js +0 -86
  30. package/src/graphic/imagePoint.js +0 -163
  31. package/src/graphic/label.js +0 -176
  32. package/src/graphic/line.js +0 -203
  33. package/src/graphic/numPoint.js +0 -119
  34. package/src/graphic/point.js +0 -144
  35. package/src/graphic/polygon.js +0 -111
  36. package/src/graphic/rectangle.js +0 -115
  37. package/src/index.js +0 -105
  38. package/src/layer/cluster.js +0 -277
  39. package/src/layer/geoJson.js +0 -174
  40. package/src/layer/heatMap.js +0 -163
  41. package/src/layer/layer.js +0 -311
  42. package/src/layer/pointCloud.js +0 -78
  43. package/src/map.js +0 -303
  44. package/src/other/route.js +0 -217
  45. package/src/util.js +0 -103
@@ -0,0 +1,237 @@
1
+ import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
2
+ import mars3d_entity from "../base/mars3d_entity";
3
+ import gaode_entity from "../base/gaode_entity";
4
+ import siji_entity from "../base/siji_entity";
5
+
6
+ const HorizontalOrigin: any = {
7
+ center: 0,
8
+ left: 1,
9
+ right: -1,
10
+ };
11
+
12
+ const VerticalOrigin: any = {
13
+ center: 0,
14
+ top: -1,
15
+ bottom: 1,
16
+ };
17
+
18
+ export default (hnMap: any) => {
19
+ const defaultOption = {
20
+ id: "",
21
+ position: [],
22
+ image: "",
23
+ height: 30,
24
+ width: 30,
25
+ rotation: 0,
26
+ horizontalOrigin: "center",
27
+ verticalOrigin: "center",
28
+ text: "",
29
+ fontSize: 12,
30
+ color: "#000000",
31
+ offset: [0, 0],
32
+ scaleByDistance: true,
33
+ distanceDisplayCondition: false,
34
+ distanceDisplayCondition_far: 1,
35
+ distanceDisplayCondition_near: 18,
36
+ data: null,
37
+ };
38
+
39
+ class mars3d_class extends mars3d_entity {
40
+ id: any = null;
41
+ option: any = JSON.parse(JSON.stringify(defaultOption));
42
+ config: any = null;
43
+ graphic: any = null;
44
+
45
+ constructor(option: any) {
46
+ super(hnMap);
47
+ this.id = option.id;
48
+ deepMerge(this.option, option);
49
+ this.config = this.formatConfig(this.option);
50
+ this.graphic = new mars3d.graphic.BillboardEntity(this.config);
51
+ }
52
+
53
+ formatConfig(option: any) {
54
+ const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
55
+ const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
56
+ return {
57
+ id: option.id,
58
+ position: option.position,
59
+ style: {
60
+ width: option.width,
61
+ height: option.height,
62
+ image: option.image,
63
+ label: {
64
+ text: option.text,
65
+ font_size: option.fontSize,
66
+ color: option.color,
67
+ pixelOffset: option.offset,
68
+ scaleByDistance: option.scaleByDistance,
69
+ distanceDisplayCondition: option.distanceDisplayCondition,
70
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
71
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
72
+ visibleDepth: false,
73
+ },
74
+ scaleByDistance: option.scaleByDistance,
75
+ distanceDisplayCondition: option.distanceDisplayCondition,
76
+ distanceDisplayCondition_far: option.distanceDisplayCondition_far,
77
+ distanceDisplayCondition_near: option.distanceDisplayCondition_near,
78
+ clampToGround: !option.position[2],
79
+ rotationDegree: option.rotation,
80
+ horizontalOrigin: HorizontalOrigin[option.horizontalOrigin],
81
+ verticalOrigin: VerticalOrigin[option.verticalOrigin],
82
+ visibleDepth: true,
83
+ },
84
+ attr: option.data,
85
+ };
86
+ }
87
+
88
+ set(option: any) {
89
+ deepMerge(this.option, option);
90
+ this.config = this.formatConfig(this.option);
91
+ this.graphic.setOptions(this.config);
92
+ }
93
+
94
+ // flyTo(option = {}) {
95
+ // let config = {}
96
+ // if(option.height){
97
+ // config.radius = option.height
98
+ // }
99
+ //
100
+ // this.graphic.flyTo(config);
101
+ // }
102
+
103
+ openPopup() {
104
+ this.graphic.openPopup();
105
+ }
106
+ }
107
+
108
+ class gaode_class extends gaode_entity {
109
+ type: any = "imagePoint";
110
+ id: any = null;
111
+ option: any = JSON.parse(JSON.stringify(defaultOption));
112
+ config: any = null;
113
+ graphic: any = null;
114
+
115
+ constructor(option: any) {
116
+ super(hnMap);
117
+ this.id = option.id;
118
+ deepMerge(this.option, option);
119
+ this.config = this.formatConfig(this.option);
120
+ this.graphic = new AMap.Marker(this.config);
121
+ }
122
+
123
+ formatConfig(option: any) {
124
+ let amapPosition = wgs84ToGcj02Format(option.position);
125
+ const content = `<div style="color:${option.color};font-size:${option.fontSize} ">${option.text}</div>`;
126
+ return {
127
+ extData: {
128
+ id: option.id,
129
+ data: option.data,
130
+ },
131
+ position: new AMap.LngLat(amapPosition[0], amapPosition[1]),
132
+ icon: new AMap.Icon({
133
+ image: option.image,
134
+ imageSize: new AMap.Size(option.height, option.width),
135
+ size: new AMap.Size(option.height, option.width),
136
+ }),
137
+ angle: 360 - option.rotation,
138
+ anchor: "center",
139
+ label: {
140
+ direction: "center",
141
+ offset: new AMap.Pixel(option.offset[0], option.offset[1]), //设置文本标注偏移量
142
+ content: content,
143
+ },
144
+ };
145
+ }
146
+ }
147
+
148
+ class siji_class extends siji_entity {
149
+ type: any = "imagePoint";
150
+ id: any = null;
151
+ option: any = JSON.parse(JSON.stringify(defaultOption));
152
+ config: any = null;
153
+ graphic: any = null;
154
+
155
+ constructor(option: any) {
156
+ super(hnMap);
157
+ this.id = option.id;
158
+ deepMerge(this.option, option);
159
+ this.config = this.formatConfig(this.option);
160
+ }
161
+
162
+ formatConfig(option: any) {
163
+ let config: any = {};
164
+
165
+ config = {
166
+ id: option.id,
167
+ type: "symbol",
168
+ source: {
169
+ type: "geojson",
170
+ data: {
171
+ type: "FeatureCollection",
172
+ features: [
173
+ {
174
+ type: "Feature",
175
+ geometry: {
176
+ type: "Point",
177
+ coordinates: option.position.map((num:any)=>Number(num)),
178
+ },
179
+ properties: {
180
+ name: "",
181
+ },
182
+ },
183
+ ],
184
+ },
185
+ },
186
+ layout: {
187
+ "icon-image": option.id + "_image",
188
+ "icon-size": Number(option.width) / Number(option.height),
189
+ },
190
+ };
191
+ return config;
192
+ }
193
+
194
+ set(option: any) {
195
+ deepMerge(this.option, option);
196
+ this.config = this.formatConfig(this.option);
197
+ let mySource = hnMap.map.map.getSource(this.config.id);
198
+ mySource.setData({
199
+ type: "FeatureCollection",
200
+ features: [
201
+ {
202
+ type: "Feature",
203
+ geometry: {
204
+ type: "Point",
205
+ coordinates: this.option.position.map((num:any)=>Number(num)),
206
+ },
207
+ },
208
+ ],
209
+ });
210
+
211
+ for (let key in this.config) {
212
+ if (this.config.hasOwnProperty(key)) {
213
+ if (key == "layout") {
214
+ for (let key2 in this.config[key]) {
215
+ if (this.config[key].hasOwnProperty(key2)) {
216
+ // 遍历 layout 属性
217
+ hnMap.map.map.setLayoutProperty(
218
+ this.config.id,
219
+ key2,
220
+ this.config[key][key2]
221
+ );
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+
230
+ const fn: any = {
231
+ mars3d: mars3d_class,
232
+ gaode: gaode_class,
233
+ siji: siji_class,
234
+ };
235
+
236
+ return fn[hnMap.mapType];
237
+ };
@@ -0,0 +1,330 @@
1
+ import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
2
+ import mars3d_entity from "../base/mars3d_entity";
3
+ import gaode_entity from "../base/gaode_entity";
4
+ import siji_entity from "../base/siji_entity";
5
+
6
+ export default (hnMap: any) => {
7
+ const defaultOption = {
8
+ id: "",
9
+ type: "label",
10
+ position: [],
11
+ text: "",
12
+ fontSize: 16,
13
+ fontWeight: "normal",
14
+ fontFamily: "楷体",
15
+ color: "#000000",
16
+ background: "",
17
+ opacity: 1,
18
+ outline: false,
19
+ outlineColor: "#ffffff",
20
+ outlineWidth: 2,
21
+ outlineOpacity: 1,
22
+ offset: [0, 0],
23
+ angle: 0,
24
+ scaleByDistance: true,
25
+ distanceDisplayCondition: false,
26
+ distanceDisplayCondition_far: 1,
27
+ distanceDisplayCondition_near: 18,
28
+ data: null,
29
+ };
30
+
31
+ class mars3d_class extends mars3d_entity {
32
+ type: any = "label";
33
+ id: any = null;
34
+ option: any = JSON.parse(JSON.stringify(defaultOption));
35
+ config: any = null;
36
+ graphic: any = null;
37
+
38
+ constructor(option: any) {
39
+ super(hnMap);
40
+ this.id = option.id;
41
+ deepMerge(this.option, option);
42
+ this.config = this.formatConfig(this.option);
43
+ if (this.option.type === "label") {
44
+ this.graphic = new mars3d.graphic.LabelEntity(this.config);
45
+ } else if (this.option.type === "mapLabel") {
46
+ this.graphic = new mars3d.graphic.RectangleEntity(this.config);
47
+ }
48
+ }
49
+
50
+ formatConfig(option: any) {
51
+ if (option.type === "label") {
52
+ const position = new mars3d.LngLatPoint(
53
+ option.position[0],
54
+ option.position[1],
55
+ option.position[2] || 0
56
+ );
57
+ const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
58
+ const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
59
+ return {
60
+ id: option.id,
61
+ position: position,
62
+ style: {
63
+ text: option.text,
64
+ color: option.color,
65
+ opacity: option.opacity,
66
+ font_size: option.fontSize,
67
+ font_family: option.fontFamily,
68
+ outline: option.outline,
69
+ outlineColor: option.outlineColor,
70
+ outlineWidth: option.outlineWidth,
71
+ outlineOpacity: option.outlineOpacity,
72
+ pixelOffset: option.offset,
73
+ scaleByDistance: option.scaleByDistance,
74
+ clampToGround: !option.position[2],
75
+ distanceDisplayCondition: option.distanceDisplayCondition,
76
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
77
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
78
+ background: !!option.background,
79
+ backgroundColor: option.background,
80
+ },
81
+ attr: option.data,
82
+ };
83
+ } else if (option.type === "mapLabel") {
84
+ const p1 = new mars3d.LngLatPoint(
85
+ option.position[0][0],
86
+ option.position[0][1]
87
+ );
88
+ const p2 = new mars3d.LngLatPoint(
89
+ option.position[1][0],
90
+ option.position[1][1]
91
+ );
92
+ return {
93
+ id: option.id,
94
+ positions: [p1, p2],
95
+ style: {
96
+ clampToGround: !option.position[0][2],
97
+ materialOptions: {
98
+ text: option.text,
99
+ font_family: "楷体",
100
+ color: option.color,
101
+ font_weight: option.fontWeight,
102
+ font_size: option.fontSize,
103
+ background: !!option.background,
104
+ stroke: option.outline,
105
+ strokeColor: option.outlineColor,
106
+ strokeWidth: option.outlineWidth,
107
+ opacity: option.opacity,
108
+ },
109
+ materialType: mars3d.MaterialType.Text,
110
+ rotationDegree: option.angle,
111
+ distanceDisplayCondition: option.distanceDisplayCondition,
112
+ distanceDisplayCondition_far: option.distanceDisplayCondition_far,
113
+ distanceDisplayCondition_near: option.distanceDisplayCondition_near,
114
+ },
115
+ attr: option.data,
116
+ };
117
+ }
118
+ }
119
+
120
+ set(option: any) {
121
+ deepMerge(this.option, option);
122
+ this.config = this.formatConfig(this.option);
123
+ this.graphic.setOptions(this.config);
124
+ }
125
+ }
126
+
127
+ class gaode_class extends gaode_entity {
128
+ id: any = null;
129
+ option: any = JSON.parse(JSON.stringify(defaultOption));
130
+ config: any = null;
131
+ graphic: any = null;
132
+
133
+ constructor(option: any) {
134
+ super(hnMap);
135
+ this.id = option.id;
136
+ deepMerge(this.option, option);
137
+ this.config = this.formatConfig(this.option);
138
+ this.graphic = new AMap.Text(this.config);
139
+ }
140
+
141
+ formatConfig(option: any) {
142
+ let amapPosition = wgs84ToGcj02Format(option.position);
143
+ return {
144
+ extData: {
145
+ id: option.id,
146
+ data: option.data,
147
+ },
148
+ text: option.text,
149
+ anchor: "center", // 设置文本标记锚点
150
+ draggable: true,
151
+ cursor: "pointer",
152
+ style: {
153
+ border: 0,
154
+ "text-align": "center",
155
+ "font-size": option.fontSize,
156
+ color: option.color,
157
+ "background-color": option.background,
158
+ },
159
+ position: [amapPosition[0], amapPosition[1]],
160
+ offset: option.offset,
161
+ };
162
+ }
163
+
164
+ set(option: any) {
165
+ deepMerge(this.option, option);
166
+ this.config = this.formatConfig(this.option);
167
+ this.graphic.setText(this.config.text);
168
+ this.graphic.setStyle(this.config.style);
169
+ this.graphic.setPosition(this.config.position);
170
+ }
171
+ }
172
+
173
+ class siji_class extends siji_entity {
174
+ type: any = "label";
175
+ id: any = null;
176
+ option: any = JSON.parse(JSON.stringify(defaultOption));
177
+ config: any = null;
178
+
179
+ constructor(option: any) {
180
+ super(hnMap);
181
+ this.id = option.id;
182
+ deepMerge(this.option, option);
183
+ this.config = this.formatConfig(this.option);
184
+ }
185
+
186
+ formatConfig(option: any) {
187
+ let config: any = {};
188
+ config = {
189
+ id: option.id,
190
+ type: "symbol",
191
+ source: {
192
+ type: "geojson",
193
+ data: {
194
+ type: "FeatureCollection",
195
+ features: [],
196
+ },
197
+ },
198
+ layout: {
199
+ "text-field": "{name}",
200
+ "text-size": Number(option.fontSize),
201
+ "text-anchor": "top", // 顶部对齐
202
+ "text-offset": this.pixelOffsetToTextOffset(option.offset,option.fontSize),
203
+ "text-max-width": 8,
204
+ "text-font": ["Microsoft YaHei Regular"],
205
+ }, // 文本样式
206
+ paint: {
207
+ "text-color": option.color,
208
+ "text-halo-color": option.outlineColor, // 文字外边线颜色
209
+ "text-halo-width": option.outlineWidth, // 文字外边线宽度
210
+ }, // 填充样式
211
+ };
212
+ if (option.type === "label") {
213
+ config.source.data.features[0] = {
214
+ type: "Feature",
215
+ geometry: {
216
+ type: "Point",
217
+ coordinates: option.position.map((num:any)=>Number(num)),
218
+ },
219
+ properties: {
220
+ name: option.text,
221
+ },
222
+ };
223
+ } else if (option.type === "mapLabel") {
224
+ option.position.forEach((item: any) => {
225
+ config.source.data.features.push({
226
+ type: "Feature",
227
+ properties: { name: option.text },
228
+ geometry: {
229
+ type: "Point",
230
+ coordinates: item,
231
+ },
232
+ });
233
+ });
234
+ }
235
+
236
+ return config;
237
+ }
238
+
239
+ /**
240
+ * 将 pixelOffset 转换为 text-offset (ems)
241
+ * @param {Array<number>} pixelOffset - [x, y] 像素偏移
242
+ * @param {number} textSizePx - 字体大小(px)
243
+ * @returns {Array<number>} text-offset in ems
244
+ */
245
+ pixelOffsetToTextOffset(pixelOffset:any, textSizePx:any): Array<number> {
246
+ return [
247
+ pixelOffset[0] / textSizePx,
248
+ pixelOffset[1] / textSizePx
249
+ ];
250
+ }
251
+
252
+ set(option: any) {
253
+ deepMerge(this.option, option);
254
+ this.config = this.formatConfig(this.option);
255
+ let mySource = hnMap.map.map.getSource(this.config.id);
256
+ if (this.option.type == "label") {
257
+ mySource.setData({
258
+ type: "FeatureCollection",
259
+ features: [
260
+ {
261
+ type: "Feature",
262
+ properties: { name: this.option.text },
263
+ geometry: {
264
+ type: "Point",
265
+ coordinates: this.option.position.map((num:any)=>Number(num)),
266
+ },
267
+ },
268
+ ],
269
+ });
270
+ } else if (this.option.type == "mapLabel") {
271
+ // 构建新的数据源对象
272
+ const sourceObj = {
273
+ type: "FeatureCollection",
274
+ features: this.option.position.map((item: any) => ({
275
+ type: "Feature",
276
+ properties: { name: this.option.text },
277
+ geometry: {
278
+ type: "Point",
279
+ coordinates: item,
280
+ },
281
+ })),
282
+ };
283
+
284
+ // 更新数据源
285
+ mySource.setData(sourceObj);
286
+ }
287
+
288
+ for (let key in this.config) {
289
+ if (this.config.hasOwnProperty(key)) {
290
+ if (key == "paint") {
291
+ for (let key2 in this.config[key]) {
292
+ if (this.config[key].hasOwnProperty(key2)) {
293
+ // 遍历 paint 属性
294
+ hnMap.map.map.setPaintProperty(
295
+ this.config.id,
296
+ key2,
297
+ key2 == "text-halo-width"
298
+ ? Number(this.config[key][key2])
299
+ : this.config[key][key2]
300
+ );
301
+ }
302
+ }
303
+ }
304
+ if (key == "layout") {
305
+ for (let key2 in this.config[key]) {
306
+ if (this.config[key].hasOwnProperty(key2)) {
307
+ // 遍历 layout 属性
308
+ hnMap.map.map.setLayoutProperty(
309
+ this.config.id,
310
+ key2,
311
+ key2 === "text-size"
312
+ ? Number(this.config[key][key2])
313
+ : this.config[key][key2]
314
+ );
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ const fn: any = {
324
+ mars3d: mars3d_class,
325
+ gaode: gaode_class,
326
+ siji: siji_class,
327
+ };
328
+
329
+ return fn[hnMap.mapType];
330
+ };