hn-map 1.0.9 → 1.1.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.
Files changed (45) hide show
  1. package/README.md +5 -22
  2. package/dist/index.js +2317 -609
  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 +202 -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 +217 -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 -104
  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,234 @@
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
+ position: [],
10
+ color: "#ffffff",
11
+ opacity: 1,
12
+ size: 6,
13
+ text: "",
14
+ fontSize: 12,
15
+ fontColor: "#ffffff",
16
+ fontOpacity: 1,
17
+ fontOffset: [0, 0],
18
+ outline: false,
19
+ outlineColor: "#ffffff",
20
+ outlineWidth: 20,
21
+ outlineOpacity: 0.5,
22
+ textOutline: false,
23
+ textOutlineColor: "#000000",
24
+ textOutlineOpacity: 0.6,
25
+ textOutlineWidth: 2,
26
+ textBackgroundColor: "",
27
+ textBackgroundOpacity: 0.5,
28
+ scaleByDistance: true,
29
+ distanceDisplayCondition: false,
30
+ distanceDisplayCondition_far: 1,
31
+ distanceDisplayCondition_near: 18,
32
+ data: null,
33
+ };
34
+
35
+ class mars3d_class extends mars3d_entity {
36
+ type: any = "point";
37
+ id: any = null;
38
+ option: any = JSON.parse(JSON.stringify(defaultOption));
39
+ config: any = null;
40
+ graphic: any = null;
41
+
42
+ constructor(option: any) {
43
+ super(hnMap);
44
+ this.id = option.id;
45
+ deepMerge(this.option, option);
46
+ this.config = this.formatConfig(this.option);
47
+ this.graphic = new mars3d.graphic.PointEntity(this.config);
48
+ }
49
+
50
+ formatConfig(option: any) {
51
+ const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
52
+ const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
53
+ return {
54
+ id: option.id,
55
+ position: option.position,
56
+ style: {
57
+ color: option.color,
58
+ opacity: option.opacity,
59
+ pixelSize: option.size,
60
+ outline: option.outline,
61
+ outlineColor: option.outlineColor,
62
+ outlineWidth: option.outlineWidth,
63
+ outlineOpacity: option.outlineOpacity,
64
+ clampToGround: !option.position[2],
65
+ scaleByDistance: option.scaleByDistance,
66
+ distanceDisplayCondition: option.distanceDisplayCondition,
67
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
68
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
69
+ label: {
70
+ text: option.text,
71
+ font_size: option.fontSize,
72
+ color: option.fontColor,
73
+ opacity: option.fontOpacity,
74
+ outline: option.textOutline,
75
+ outlineColor: option.textOutlineColor,
76
+ outlineOpacity: option.textOutlineOpacity,
77
+ outlineWidth: option.textOutlineWidth,
78
+ background: !!option.textBackgroundColor,
79
+ backgroundColor: option.textBackgroundColor,
80
+ backgroundOpacity: option.textBackgroundOpacity,
81
+ pixelOffset: option.fontOffset,
82
+ scaleByDistance: option.fontScaleByDistance,
83
+ distanceDisplayCondition: option.fontDistanceDisplayCondition,
84
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
85
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
86
+ },
87
+ },
88
+ attr: option.data,
89
+ };
90
+ }
91
+
92
+ set(option: any) {
93
+ deepMerge(this.option, option);
94
+ this.config = this.formatConfig(this.option);
95
+ this.graphic.setOptions(this.config);
96
+ }
97
+ }
98
+
99
+ class gaode_class extends gaode_entity {
100
+ id: any = null;
101
+ option: any = JSON.parse(JSON.stringify(defaultOption));
102
+ config: any = null;
103
+ graphic: any = null;
104
+
105
+ constructor(option: any) {
106
+ super(hnMap);
107
+ this.id = option.id;
108
+ deepMerge(this.option, option);
109
+ this.config = this.formatConfig(this.option);
110
+ this.graphic = new AMap.CircleMarker(this.config);
111
+ }
112
+
113
+ formatConfig(option: any) {
114
+ let amapPosition = wgs84ToGcj02Format(option.position);
115
+ return {
116
+ center: amapPosition,
117
+ radius: option.size / 2,
118
+ strokeColor: option.outlineColor,
119
+ strokeOpacity: option.outlineOpacity,
120
+ strokeWeight: option.outlineWidth,
121
+ fillColor: option.color,
122
+ fillOpacity: option.opacity,
123
+ extData: {
124
+ id: option.id,
125
+ data: option.data,
126
+ },
127
+ };
128
+ }
129
+
130
+ set(option: any) {
131
+ deepMerge(this.option, option);
132
+ this.config = this.formatConfig(this.option);
133
+ this.graphic.setOptions(this.config);
134
+ this.graphic.setCenter(this.config.center);
135
+ }
136
+ }
137
+
138
+ class siji_class extends siji_entity {
139
+ type: any = "point";
140
+ id: any = null;
141
+ option: any = JSON.parse(JSON.stringify(defaultOption));
142
+ config: any = null;
143
+
144
+ constructor(option: any) {
145
+ super(hnMap);
146
+ this.id = option.id;
147
+ deepMerge(this.option, option);
148
+ this.config = this.formatConfig(this.option);
149
+ }
150
+
151
+ formatConfig(option: any) {
152
+ let config: any = {};
153
+ config = {
154
+ id: option.id,
155
+ type: "circle",
156
+ source: {
157
+ type: "geojson",
158
+ data: {
159
+ type: "FeatureCollection",
160
+ features: [
161
+ {
162
+ type: "Feature",
163
+ geometry: {
164
+ type: "Point",
165
+ coordinates: option.position,
166
+ },
167
+ properties: {
168
+ id: option.id,
169
+ ...option.data,
170
+ },
171
+ },
172
+ ],
173
+ },
174
+ },
175
+ paint: {
176
+ "circle-opacity": Number(option.opacity),
177
+ "circle-radius": Number(option.size),
178
+ "circle-color": option.color,
179
+ "circle-stroke-color": option.outlineColor,
180
+ "circle-stroke-width": option.outlineWidth,
181
+ "circle-stroke-opacity": Number(option.outlineOpacity), // 边框样式
182
+ }, // 填充样式
183
+ };
184
+
185
+ return config;
186
+ }
187
+
188
+ set(option: any) {
189
+ console.log("=====set point====", option);
190
+ deepMerge(this.option, option);
191
+ this.config = this.formatConfig(this.option);
192
+ let mySource = hnMap.map.map.getSource(this.config.id);
193
+ mySource.setData({
194
+ type: "FeatureCollection",
195
+ features: [
196
+ {
197
+ type: "Feature",
198
+ properties: { name: this.option.text },
199
+ geometry: {
200
+ type: "Point",
201
+ coordinates: this.option.position,
202
+ },
203
+ },
204
+ ],
205
+ });
206
+ for (let key in this.config) {
207
+ if (this.config.hasOwnProperty(key)) {
208
+ if (key == "paint") {
209
+ for (let key2 in this.config[key]) {
210
+ if (this.config[key].hasOwnProperty(key2)) {
211
+ // 遍历 paint 属性
212
+ hnMap.map.map.setPaintProperty(
213
+ this.config.id,
214
+ key2,
215
+ key2 == "circle-opacity" || key2 == "circle-stroke-opacity"
216
+ ? Number(this.config[key][key2])
217
+ : this.config[key][key2]
218
+ );
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ const fn: any = {
228
+ mars3d: mars3d_class,
229
+ gaode: gaode_class,
230
+ siji: siji_class,
231
+ };
232
+
233
+ return fn[hnMap.mapType];
234
+ };
@@ -0,0 +1,188 @@
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
+ export default (hnMap: any) => {
6
+ const defaultOption = {
7
+ id: "",
8
+ position: [],
9
+ color: "#ff0000",
10
+ opacity: 1,
11
+ outline: false,
12
+ outlineWidth: 2,
13
+ outlineColor: "#ffffff",
14
+ outlineOpacity: 1,
15
+ scaleByDistance: true,
16
+ distanceDisplayCondition: false,
17
+ distanceDisplayCondition_far: 1,
18
+ distanceDisplayCondition_near: 18,
19
+ data: null,
20
+ };
21
+
22
+ class mars3d_class extends mars3d_entity {
23
+ type: any = "polygon";
24
+ id: any = null;
25
+ option: any = JSON.parse(JSON.stringify(defaultOption));
26
+ config: any = null;
27
+ graphic: any = null;
28
+
29
+ constructor(option: any) {
30
+ super(hnMap);
31
+ this.id = option.id;
32
+ deepMerge(this.option, option);
33
+ this.config = this.formatConfig(this.option);
34
+ this.graphic = new mars3d.graphic.PolygonEntity(this.config);
35
+ }
36
+
37
+ formatConfig(option: any) {
38
+ const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
39
+ const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
40
+ return {
41
+ id: option.id,
42
+ positions: option.position,
43
+ style: {
44
+ color: option.color,
45
+ opacity: option.opacity,
46
+ outline: option.outline,
47
+ outlineColor: option.outlineColor,
48
+ outlineWidth: option.outlineWidth,
49
+ outlineOpacity: option.outlineOpacity,
50
+ scaleByDistance: option.scaleByDistance,
51
+ distanceDisplayCondition: option.distanceDisplayCondition,
52
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
53
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
54
+ clampToGround: option.position[0] && !option.position[0][2],
55
+ },
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.graphic.setOptions(this.config);
64
+ }
65
+ }
66
+
67
+ class gaode_class extends gaode_entity {
68
+ id: any = null;
69
+ option: any = JSON.parse(JSON.stringify(defaultOption));
70
+ config: any = null;
71
+ graphic: any = null;
72
+
73
+ constructor(option: any) {
74
+ super(hnMap);
75
+ this.id = option.id;
76
+ deepMerge(this.option, option);
77
+ this.config = this.formatConfig(this.option);
78
+ this.graphic = new AMap.Polygon(this.config);
79
+ }
80
+
81
+ formatConfig(option: any) {
82
+ const amapPosition = wgs84ToGcj02Format(option.position);
83
+ return {
84
+ path: amapPosition,
85
+ fillColor: option.color,
86
+ fillOpacity: option.opacity,
87
+ strokeColor: option.outlineColor,
88
+ strokeOpacity: option.outline ? option.outlineOpacity : 0,
89
+ strokeWeight: option.outline ? option.outlineWidth : 0,
90
+ extData: {
91
+ id: option.id,
92
+ data: option.data,
93
+ },
94
+ };
95
+ }
96
+
97
+ set(option: any) {
98
+ deepMerge(this.option, option);
99
+ this.config = this.formatConfig(this.option);
100
+ this.graphic.setOptions(this.config);
101
+ this.graphic.setPath(this.config.path);
102
+ }
103
+ }
104
+
105
+ class siji_class extends siji_entity {
106
+ type: any = "polygon";
107
+ id: any = null;
108
+ option: any = JSON.parse(JSON.stringify(defaultOption));
109
+ config: any = null;
110
+ graphic: any = null;
111
+
112
+ constructor(option: any) {
113
+ super(hnMap);
114
+ this.id = option.id;
115
+ deepMerge(this.option, option);
116
+ this.config = this.formatConfig(this.option);
117
+ }
118
+
119
+ formatConfig(option: any) {
120
+ let config = {
121
+ id: option.id,
122
+ type: "fill",
123
+ source: {
124
+ type: "geojson",
125
+ data: {
126
+ type: "FeatureCollection",
127
+ features: [
128
+ {
129
+ type: "Feature",
130
+ geometry: {
131
+ type: "Polygon",
132
+ coordinates: option.position,
133
+ },
134
+ },
135
+ ],
136
+ },
137
+ },
138
+
139
+ paint: {
140
+ "fill-color": option.color, // 填充颜色覆盖drawColor设置的颜色,呈现绿色
141
+ "fill-opacity": Number(option.opacity),
142
+ },
143
+ };
144
+ return config;
145
+ }
146
+
147
+ set(option: any) {
148
+ deepMerge(this.option, option);
149
+ this.config = this.formatConfig(this.option);
150
+ let mySource = hnMap.map.map.getSource(this.config.id);
151
+ mySource.setData({
152
+ type: "FeatureCollection",
153
+ features: [
154
+ {
155
+ type: "Feature",
156
+ geometry: {
157
+ type: "Polygon",
158
+ coordinates: [option.position], //三层数组[[[0,0],[0,0]]]
159
+ },
160
+ },
161
+ ],
162
+ });
163
+ for (let key in this.config) {
164
+ if (this.config.hasOwnProperty(key)) {
165
+ if (key == "paint") {
166
+ for (let key2 in this.config[key]) {
167
+ if (this.config[key].hasOwnProperty(key2)) {
168
+ // 遍历 paint 属性
169
+ hnMap.map.map.setPaintProperty(
170
+ this.config.id,
171
+ key2,
172
+ this.config[key][key2]
173
+ );
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ const fn: any = {
182
+ mars3d: mars3d_class,
183
+ gaode: gaode_class,
184
+ siji: siji_class,
185
+ };
186
+
187
+ return fn[hnMap.mapType];
188
+ };
@@ -0,0 +1,202 @@
1
+ import {
2
+ deepMerge,
3
+ wgs84ToGcj02Format,
4
+ createRectangleCoordinates, getLevelMiddleHeight,
5
+ } from "../util";
6
+ import mars3d_entity from "../base/mars3d_entity";
7
+ import gaode_entity from "../base/gaode_entity";
8
+ import siji_entity from "../base/siji_entity";
9
+ export default (hnMap: any) => {
10
+ const defaultOption = {
11
+ id: "",
12
+ position: [],
13
+ color: "#ff0000",
14
+ opacity: 1,
15
+ outline: false,
16
+ outlineWidth: 2,
17
+ outlineColor: "#ffffff",
18
+ outlineOpacity: 1,
19
+ scaleByDistance: true,
20
+ distanceDisplayCondition: false,
21
+ distanceDisplayCondition_far: 1,
22
+ distanceDisplayCondition_near: 18,
23
+ data: null,
24
+ };
25
+
26
+ class mars3d_class extends mars3d_entity {
27
+ type: any = "retangle";
28
+ id: any = null;
29
+ option: any = JSON.parse(JSON.stringify(defaultOption));
30
+ config: any = null;
31
+ graphic: any = null;
32
+
33
+ constructor(option: any) {
34
+ super(hnMap);
35
+ this.id = option.id;
36
+ deepMerge(this.option, option);
37
+ this.config = this.formatConfig(this.option);
38
+ this.graphic = new mars3d.graphic.RectangleEntity(this.config);
39
+ }
40
+
41
+ formatConfig(option: any) {
42
+ const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
43
+ const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
44
+ return {
45
+ id: option.id,
46
+ positions: option.position,
47
+ style: {
48
+ color: option.color,
49
+ opacity: option.opacity,
50
+ outline: option.outline,
51
+ outlineColor: option.outlineColor,
52
+ outlineWidth: option.outlineWidth,
53
+ outlineOpacity: option.outlineOpacity,
54
+ scaleByDistance: option.scaleByDistance,
55
+ distanceDisplayCondition: option.distanceDisplayCondition,
56
+ distanceDisplayCondition_far: distanceDisplayCondition_far,
57
+ distanceDisplayCondition_near: distanceDisplayCondition_near,
58
+ clampToGround: !option.position[0][2],
59
+ },
60
+ attr: option.data,
61
+ };
62
+ }
63
+
64
+ set(option: any) {
65
+ deepMerge(this.option, option);
66
+ this.config = this.formatConfig(this.option);
67
+ this.graphic.setOptions(this.config);
68
+ }
69
+ }
70
+
71
+ class gaode_class extends gaode_entity {
72
+ id: any = null;
73
+ option: any = JSON.parse(JSON.stringify(defaultOption));
74
+ config: any = null;
75
+ graphic: any = null;
76
+
77
+ constructor(option: any) {
78
+ super(hnMap);
79
+ this.id = option.id;
80
+ deepMerge(this.option, option);
81
+ this.config = this.formatConfig(this.option);
82
+ this.graphic = new AMap.Rectangle(this.config); //创建矩形
83
+ }
84
+
85
+ formatConfig(option: any) {
86
+ const amapPosition = wgs84ToGcj02Format(option.position); //坐标转换
87
+ const southWest = new AMap.LngLat(amapPosition[0][0], amapPosition[0][1]); //
88
+ const northEast = new AMap.LngLat(amapPosition[1][0], amapPosition[1][1]); //
89
+ const bounds = new AMap.Bounds(southWest, northEast); // 创建矩形
90
+ return {
91
+ bounds: bounds,
92
+ fillColor: option.color,
93
+ fillOpacity: option.opacity,
94
+ strokeColor: option.outlineColor,
95
+ strokeOpacity: option.outline ? option.outlineOpacity : 0,
96
+ strokeWeight: option.outline ? option.outlineWidth : 0,
97
+ extData: {
98
+ id: option.id,
99
+ data: option.data,
100
+ },
101
+ };
102
+ }
103
+
104
+ set(option: any) {
105
+ deepMerge(this.option, option);
106
+ this.config = this.formatConfig(this.option);
107
+ this.graphic.setOptions(this.config);
108
+ this.graphic.setBounds(this.config.bounds);
109
+ }
110
+ }
111
+ class siji_class extends siji_entity {
112
+ type: any = "rectangle";
113
+ id: any = null;
114
+ option: any = JSON.parse(JSON.stringify(defaultOption));
115
+ config: any = null;
116
+ graphic: any = null;
117
+
118
+ constructor(option: any) {
119
+ super(hnMap);
120
+ this.id = option.id;
121
+ deepMerge(this.option, option);
122
+ this.config = this.formatConfig(this.option);
123
+ }
124
+
125
+ formatConfig(option: any) {
126
+ let RectanglePosition = createRectangleCoordinates(
127
+ option.position[0],
128
+ option.position[1]
129
+ );
130
+ console.log([RectanglePosition], "========RectanglePosition=======");
131
+ let config = {
132
+ id: option.id,
133
+ type: "fill",
134
+ source: {
135
+ type: "geojson",
136
+ data: {
137
+ type: "FeatureCollection",
138
+ features: [
139
+ {
140
+ type: "Feature",
141
+ geometry: {
142
+ type: "Polygon",
143
+ coordinates: [RectanglePosition],
144
+ },
145
+ },
146
+ ],
147
+ },
148
+ },
149
+
150
+ paint: {
151
+ "fill-color": option.color, // 填充颜色覆盖drawColor设置的颜色,呈现绿色
152
+ "fill-opacity": Number(option.opacity),
153
+ },
154
+ };
155
+ return config;
156
+ }
157
+
158
+ set(option: any) {
159
+ deepMerge(this.option, option);
160
+ this.config = this.formatConfig(this.option);
161
+ let RectanglePosition = createRectangleCoordinates(
162
+ option.position[0],
163
+ option.position[1]
164
+ );
165
+ let mySource = hnMap.map.map.getSource(this.config.id);
166
+ mySource.setData({
167
+ type: "FeatureCollection",
168
+ features: [
169
+ {
170
+ type: "Feature",
171
+ geometry: {
172
+ type: "Polygon",
173
+ coordinates: [RectanglePosition], //三层数组[[0,0],[0,0]]
174
+ },
175
+ },
176
+ ],
177
+ });
178
+ for (let key in this.config) {
179
+ if (this.config.hasOwnProperty(key)) {
180
+ if (key == "paint") {
181
+ for (let key2 in this.config[key]) {
182
+ if (this.config[key].hasOwnProperty(key2)) {
183
+ // 遍历 paint 属性
184
+ hnMap.map.map.setPaintProperty(
185
+ this.config.id,
186
+ key2,
187
+ this.config[key][key2]
188
+ );
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ const fn: any = {
197
+ mars3d: mars3d_class,
198
+ gaode: gaode_class,
199
+ siji: siji_class,
200
+ };
201
+ return fn[hnMap.mapType];
202
+ };