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
@@ -1,217 +0,0 @@
1
- import {deepMerge, wgs84ToGcj02Format} from "../util.js";
2
-
3
- export default (hnMap) => {
4
-
5
- const defaultOption = {
6
- id: "",
7
- position: [],
8
- speed: 10,
9
- loop: false,
10
- image: {
11
- src: null,
12
- width: 10,
13
- height: 10,
14
- },
15
- camera: {
16
- type: '',
17
- pitch: -30,
18
- radius: 500,
19
- },
20
- polyline: {
21
- color: "#0000ff",
22
- width: 2
23
- },
24
- path: {
25
- color: "#ff0000",
26
- width: 2
27
- }
28
- }
29
-
30
- class mars3d_class {
31
- type = 'route'
32
- id = null
33
- option = JSON.parse(JSON.stringify(defaultOption))
34
- config = null
35
- graphic = null
36
-
37
- constructor(option) {
38
- this.id = option.id
39
- deepMerge(this.option, option)
40
- this.config = this.formatConfig(this.option)
41
- this.graphic = new mars3d.graphic.FixedRoute(this.config)
42
- }
43
-
44
- formatConfig(option) {
45
- return {
46
- id: option.id,
47
- speed: option.speed,
48
- positions: option.position,
49
- clockLoop: option.loop, // 是否循环播放
50
- camera: {
51
- type: option.camera.type,
52
- pitch: option.camera.pitch,
53
- radius: option.camera.radius,
54
- },
55
- billboard: {
56
- image: option.image.src,
57
- width: option.image.width,
58
- height: option.image.height,
59
- },
60
- polyline: {
61
- color: option.polyline.color,
62
- width: option.polyline.width,
63
- // showAll: true,
64
- },
65
- path: {
66
- color: option.path.color,
67
- width: option.path.width,
68
- // leadTime: 0,
69
- },
70
- }
71
- }
72
-
73
- set(option) {
74
- deepMerge(this.option, option)
75
- this.config = this.formatConfig(this.option)
76
- this.graphic.setOptions(this.config)
77
- }
78
-
79
- start() {
80
- this.graphic.start()
81
- }
82
-
83
- pause() {
84
- this.graphic.pause()
85
- }
86
-
87
- proceed() {
88
- this.graphic.proceed()
89
- }
90
-
91
- stop() {
92
- this.graphic.stop()
93
- }
94
-
95
- destroy() {
96
- this.graphic.destroy()
97
- }
98
-
99
- flyTo() {
100
- this.graphic.flyToPoint()
101
- }
102
-
103
- }
104
-
105
- class gaode_class {
106
- id = null
107
- option = JSON.parse(JSON.stringify(defaultOption))
108
- config_graphic = null
109
- config_path = null
110
- graphic = null
111
-
112
- constructor(option) {
113
- this.id = option.id
114
- deepMerge(this.option, option)
115
- this.config_graphic = this.formatConfigGraphic(this.option)
116
- this.config_path = this.formatConfigPath(this.option)
117
- this.graphic = new AMap.Marker(this.config_graphic);
118
- this.addPath()
119
-
120
- this.graphic.on('moving', (e) => {
121
- hnMap.map.map.setCenter(e.target.getPosition(), true)
122
- });
123
- hnMap.map.map.setFitView();
124
-
125
- }
126
-
127
- formatConfigGraphic(option) {
128
- const amapPosition = wgs84ToGcj02Format(option.position)
129
- return {
130
- position: amapPosition[0],
131
- speed: option.speed,
132
- icon: new AMap.Icon({
133
- image: option.image.src,
134
- imageSize: new AMap.Size(option.image.width, option.image.height),
135
- size: new AMap.Size(option.image.width, option.image.height),
136
- }),
137
- extData: {
138
- id: option.id
139
- },
140
- }
141
- }
142
-
143
- formatConfigPath(option) {
144
- const amapPosition = wgs84ToGcj02Format(option.position)
145
- return {
146
- id: option.id + '_path',
147
- position: amapPosition,
148
- width: option.polyline.width,
149
- color: option.polyline.color,
150
- data: {id: option.id + '_path',},
151
- }
152
- }
153
-
154
- set(option) {
155
- deepMerge(this.option, option)
156
- this.config_graphic = this.formatConfigGraphic(this.option)
157
- this.config_path = this.formatConfigPath(this.option)
158
- this.graphic.setOptions(this.config_graphic)
159
- this.stop()
160
- }
161
-
162
- addPath() {
163
- this.pathLayer = hnMap.map.addLayer(new hnMap.Layer({id: this.id + '_path_layer'}))
164
- if (this.pathLayer) {
165
- this.path = new hnMap.Line(this.config_path)
166
- this.pathLayer.addEntity(this.path)
167
- }
168
- }
169
-
170
- start() {
171
- this.config_path.position.reduce((prev, next) => {
172
- let t1 = turf.point(prev);
173
- let t2 = turf.point(next);
174
- let distance = turf.distance(t1, t2, {units: 'meters'});
175
- this.graphic.moveAlong(this.path.graphic._opts.path, {
176
- duration: Number(distance / this.config_graphic.speed).toFixed(0),
177
- autoRotation: true,
178
- circlable: true
179
- })
180
- return next
181
- })
182
- }
183
-
184
- pause() {
185
- this.graphic.pauseMove()
186
- }
187
-
188
- proceed() {
189
- this.graphic.resumeMove()
190
- }
191
-
192
- stop() {
193
- this.graphic.stopMove()
194
- }
195
-
196
- destroy() {
197
- this.stop()
198
- this.graphic.remove()
199
- this.pathLayer.destroy()
200
- }
201
-
202
- flyTo() {
203
-
204
- if (this.graphic.getBounds) {
205
- const bounds = this.graphic.getBounds();
206
- hnMap.map.map.setBounds(bounds);
207
- }
208
- }
209
- }
210
-
211
- const fn = {
212
- mars3d: mars3d_class,
213
- gaode: gaode_class
214
- }
215
-
216
- return fn[hnMap.mapType]
217
- }
package/src/util.js DELETED
@@ -1,103 +0,0 @@
1
- // import Vue from 'vue'
2
- //
3
- // // 渲染vue组件并获取dom结构
4
- // export function renderComponents(comp, params) {
5
- // const vNodeDom = document.createElement("div")
6
- // document.body.appendChild(vNodeDom)
7
- //
8
- // const SubVue = Vue.extend(comp)
9
- // const app = new SubVue({
10
- // el: vNodeDom,
11
- // propsData: params
12
- // })
13
- // return app.$el
14
- // }
15
-
16
- // 对象深度合并
17
- export function deepMerge(target, source) {
18
- for (let key of Object.keys(source)) {
19
- if (source[key] instanceof Object && !Array.isArray(source[key])) {
20
- if (!target[key]) Object.assign(target, { [key]: {} });
21
- deepMerge(target[key], source[key]);
22
- } else {
23
- Object.assign(target, { [key]: source[key] });
24
- }
25
- }
26
- return target;
27
- }
28
-
29
- // 递归格式化高德坐标系
30
- export function wgs84ToGcj02Format(position) {
31
- // 判断是否是数组
32
- if (position.every(item => Array.isArray(item))) {
33
- return position.map(item => {
34
- return wgs84ToGcj02Format(item)
35
- })
36
- } else if (position.every(item => typeof item === 'object')) {
37
- return position.map(item => {
38
- let data = wgs84ToGcj02Format([item.lng, item.lat])
39
- return {
40
- ...item,
41
- lng: data[0],
42
- lat: data[1]
43
- }
44
- })
45
- } else {
46
- return wgs84ToGcj02(position[0], position[1])
47
- }
48
- }
49
-
50
-
51
- /**
52
- * WGS-84 转 GCJ-02(高德坐标)
53
- * @param {number} wgsLat - WGS-84纬度
54
- * @param {number} wgsLng - WGS-84经度
55
- * @returns {[number, number]} GCJ-02经纬度数组
56
- */
57
- export function wgs84ToGcj02(wgsLng, wgsLat) {
58
- if (!isCorrectPosition(wgsLng, wgsLat)) {
59
- return [wgsLng, wgsLat];
60
- }
61
-
62
- const a = 6378245.0; // 长半轴
63
- const ee = 0.00669342162296594323; // 扁率
64
-
65
- function transformLat(x, y) {
66
- let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
67
- ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
68
- ret += (160.0 * Math.sin(y * Math.PI / 3.0) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
69
- return ret;
70
- }
71
-
72
- function transformLng(x, y) {
73
- let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
74
- ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(x * Math.PI)) * 2.0 / 3.0;
75
- ret += (150.0 * Math.sin(x * Math.PI / 3.0) + 300.0 * Math.sin(x * Math.PI / 15.0)) * 2.0 / 3.0;
76
- return ret;
77
- }
78
-
79
- let dLat = transformLat(wgsLng - 105.0, wgsLat - 35.0);
80
- let dLng = transformLng(wgsLng - 105.0, wgsLat - 35.0);
81
- const radLat = wgsLat / 180.0 * Math.PI;
82
- let magic = Math.sin(radLat);
83
- magic = 1 - ee * magic * magic;
84
- const sqrtMagic = Math.sqrt(magic);
85
- dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Math.PI);
86
- dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * Math.PI);
87
- const gcjLat = wgsLat + dLat;
88
- const gcjLng = wgsLng + dLng;
89
-
90
- return [gcjLng, gcjLat];
91
- }
92
-
93
- /**
94
- * 判断是否为正确的坐标
95
- * @param {number} lat - 纬度
96
- * @param {number} lng - 经度
97
- * @returns {boolean}
98
- */
99
- export function isCorrectPosition(lng, lat) {
100
- return (
101
- lng <= 180 && lng >= -180 && lat <= 90 && lat >= -90
102
- );
103
- }