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
@@ -1,59 +0,0 @@
1
- export default class gaode_entity {
2
- infoWindow = null
3
- hnMap = null
4
-
5
- constructor(hnMap) {
6
- this.hnMap = hnMap
7
- }
8
-
9
- // 添加属性弹窗
10
- addPopupByAttr() {
11
- this.infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
12
-
13
- const handleClick = (e) => {
14
- const data = this.config.extData.data
15
- let content = ''
16
- for (const key in data) {
17
- content += `<div>${key}: ${data[key]}</div>`
18
- }
19
- this.infoWindow.setContent(content);
20
- this.infoWindow.open(this.hnMap.map.map, e.lnglat);
21
- }
22
-
23
- this.graphic.on('click', handleClick)
24
- }
25
-
26
- // 添加自定义dom弹窗
27
- addCustomPopup(getCustomDom) {
28
- this.infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
29
-
30
- const handleClick = (e) => {
31
- const data = this.config.extData.data
32
- const dom = getCustomDom(data)
33
- this.infoWindow.setContent(dom);
34
- this.infoWindow.open(this.hnMap.map.map, e.lnglat);
35
- }
36
-
37
- this.graphic.on('click', handleClick)
38
- }
39
-
40
- flyTo() {
41
-
42
- if(this.graphic.getCenter){
43
- this.hnMap.map.map.setCenter(this.graphic.getCenter());
44
- }
45
-
46
- if(this.graphic.getPosition){
47
- this.hnMap.map.map.setCenter(this.graphic.getPosition());
48
- }
49
-
50
- if(this.graphic.getBounds){
51
- const bounds = this.graphic.getBounds();
52
- this.hnMap.map.map.setBounds(bounds);
53
- }
54
- }
55
-
56
- destroy() {
57
- this.graphic.remove()
58
- }
59
- }
@@ -1,50 +0,0 @@
1
- export default class mars3d_entity {
2
- constructor(hnMap) {
3
- this.event = {}
4
- }
5
-
6
- // 添加属性弹窗
7
- addPopupByAttr() {
8
- this.graphic.bindPopup((event) => {
9
- const data = event.graphic.attr
10
- return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
11
- })
12
- }
13
-
14
- // 添加自定义dom弹窗
15
- addCustomPopup(getCustomDom) {
16
- this.graphic.bindPopup(async (event) => {
17
- if (event.graphic.attr) {
18
- const data = event.graphic.attr || {};
19
- return await getCustomDom(data);
20
- }
21
- }, {offsetY: -20});
22
- }
23
-
24
- flyTo(option = {}) {
25
- this.graphic.flyTo(option);
26
- }
27
-
28
- destroy() {
29
- this.graphic.destroy()
30
- }
31
-
32
- on(eventType, callback) {
33
- this.off(eventType)
34
- switch (eventType) {
35
- case 'click':
36
- this.event[eventType] = () => {
37
- callback(event)
38
- }
39
- break;
40
- }
41
- this.graphic.on(eventType, this.event[eventType]);
42
- }
43
-
44
- off(eventType) {
45
- if (this.event[eventType]) {
46
- this.graphic.off(eventType, this.event[eventType]);
47
- delete this.event[eventType]
48
- }
49
- }
50
- }
@@ -1,159 +0,0 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util.js'
2
- import mars3d_entity from "../base/mars3d_entity.js";
3
- import gaode_entity from "../base/gaode_entity";
4
-
5
- export default (hnMap) => {
6
-
7
- const defaultOption = {
8
- id: "",
9
- position: [],
10
- type: 'color',
11
- radius: 20,
12
- color: "#ff0000",
13
- opacity: 1,
14
- waveCount: 2,
15
- waveSpeed: 5,
16
- outlineWidth: 0,
17
- outlineColor: "#ffffff",
18
- outlineOpacity: 1,
19
- outlineHighLight: false,
20
- outlineHighLightGlowPower: 0.1,
21
- outlineHighLightTaperPower: 1,
22
- scaleByDistance: true,
23
- distanceDisplayCondition: false,
24
- distanceDisplayCondition_far: Number.MAX_VALUE,
25
- distanceDisplayCondition_near: 0,
26
- data: null
27
- }
28
-
29
- class mars3d_class extends mars3d_entity {
30
- type = 'circle'
31
- id = null
32
- option = JSON.parse(JSON.stringify(defaultOption))
33
- config = null
34
- graphic = null
35
-
36
- constructor(option) {
37
- super()
38
- this.id = option.id
39
- deepMerge(this.option, option)
40
- this.config = this.formatConfig(this.option)
41
- this.graphic = new mars3d.graphic.CircleEntity(this.config)
42
- }
43
-
44
- formatConfig(option) {
45
- let config = {
46
- id: option.id,
47
- position: new mars3d.LngLatPoint(
48
- option.position[0],
49
- option.position[1],
50
- option.position[2] || 0,
51
- ),
52
- style: {
53
- radius: option.radius || 1,
54
- color: option.color,
55
- opacity: option.opacity,
56
- outline: !!option.outlineWidth,
57
- outlineColor: option.outlineColor,
58
- outlineWidth: option.outlineWidth,
59
- outlineOpacity: option.outlineOpacity,
60
- scaleByDistance: option.scaleByDistance,
61
- distanceDisplayCondition: option.distanceDisplayCondition,
62
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
63
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
64
- clampToGround: !option.position[2],
65
- },
66
- attr: option.data
67
- }
68
-
69
- switch (option.type) {
70
- case 'color':
71
- config.style.materialType = mars3d.MaterialType.Color
72
- break
73
- case 'wave':
74
- config.style.materialType = mars3d.MaterialType.CircleWave
75
- config.style.materialOptions = {
76
- color: option.color,
77
- count: option.waveCount,
78
- speed: option.waveSpeed,
79
- }
80
- break
81
- }
82
-
83
- if (option.outlineHighLight) {
84
- config.style.outlineStyle = {
85
- materialType: "PolylineGlow",
86
- materialOptions: {
87
- color: option.outlineColor,
88
- glowPower: option.outlineHighLightGlowPower,
89
- taperPower: option.outlineHighLightTaperPower,
90
- }
91
- }
92
- }
93
- return config
94
- }
95
-
96
- set(option) {
97
- deepMerge(this.option, option)
98
- this.config = this.formatConfig(this.option)
99
- this.graphic.setOptions(this.config)
100
- }
101
-
102
- // flyTo(option = {}) {
103
- // let config = {}
104
- // if(option.height){
105
- // config.scale = this.calculateScaleFromHeight(this.graphic, option.height)
106
- // }
107
- //
108
- // this.graphic.flyTo(config);
109
- // }
110
-
111
- }
112
-
113
- class gaode_class extends gaode_entity {
114
-
115
- id = null
116
- option = JSON.parse(JSON.stringify(defaultOption))
117
- config = null
118
- graphic = null
119
-
120
- constructor(option) {
121
- super()
122
- this.id = option.id
123
- deepMerge(this.option, option)
124
- this.config = this.formatConfig(this.option)
125
- this.graphic = new AMap.Circle(this.config)
126
- }
127
-
128
- formatConfig(option) {
129
- let amapPosition = wgs84ToGcj02Format(option.position)
130
- return {
131
- center: new AMap.LngLat(amapPosition[0], amapPosition[1]),
132
- radius: option.radius,
133
- fillColor: option.color,
134
- fillOpacity: option.opacity,
135
- strokeColor: option.outline.color,
136
- strokeOpacity: option.outline.show ? option.outline.opacity : 0,
137
- strokeWeight: option.outline.show ? option.outline.width : 0,
138
- extData: {
139
- id: option.id,
140
- data: option.data,
141
- },
142
- }
143
- }
144
-
145
- set(option) {
146
- deepMerge(this.option, option)
147
- this.config = this.formatConfig(this.option)
148
- this.graphic.setOptions(this.config)
149
- this.graphic.setCenter(this.config.center)
150
-
151
- }
152
- }
153
-
154
- const fn = {
155
- mars3d: mars3d_class,
156
- gaode: gaode_class
157
- }
158
- return fn[hnMap.mapType]
159
- }
@@ -1,86 +0,0 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util.js'
2
- import mars3d_entity from '../base/mars3d_entity.js'
3
- import gaode_entity from "../base/gaode_entity.js";
4
-
5
- const HorizontalOrigin = {
6
- center: 0,
7
- left: 1,
8
- right: -1
9
- }
10
-
11
- const VerticalOrigin = {
12
- center: 0,
13
- top: -1,
14
- bottom: 1
15
- }
16
-
17
- export default (hnMap) => {
18
-
19
- const defaultOption = {
20
- id: "",
21
- position: [],
22
- html: "",
23
- horizontalOrigin: "center",
24
- verticalOrigin: "center",
25
- offset: [0, 0],
26
- scaleByDistance: true,
27
- distanceDisplayCondition: false,
28
- distanceDisplayCondition_far: Number.MAX_VALUE,
29
- distanceDisplayCondition_near: 0,
30
- data: null
31
- }
32
-
33
- class mars3d_class extends mars3d_entity {
34
- type = 'divPoint'
35
- id = null
36
- option = JSON.parse(JSON.stringify(defaultOption))
37
- config = null
38
- graphic = null
39
-
40
- constructor(option) {
41
- super()
42
- this.id = option.id
43
- deepMerge(this.option, option)
44
- this.config = this.formatConfig(this.option)
45
- this.graphic = new mars3d.graphic.DivGraphic(this.config)
46
- }
47
-
48
- formatConfig(option) {
49
- return {
50
- id: option.id,
51
- position: option.position,
52
- style: {
53
- html: option.html,
54
- offsetX: option.offset[0],
55
- offsetY: option.offset[1],
56
- scaleByDistance: option.scaleByDistance,
57
- distanceDisplayCondition: option.distanceDisplayCondition,
58
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
59
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
60
- clampToGround: !option.position[2],
61
- horizontalOrigin: HorizontalOrigin[option.horizontalOrigin],
62
- verticalOrigin: VerticalOrigin[option.verticalOrigin],
63
- },
64
- attr: option.data
65
- }
66
- }
67
-
68
- set(option) {
69
- deepMerge(this.option, option)
70
- this.config = this.formatConfig(this.option)
71
- this.graphic.setOptions(this.config)
72
- }
73
-
74
- openPopup() {
75
- this.graphic.openPopup();
76
- }
77
-
78
- }
79
-
80
- const fn = {
81
- mars3d: mars3d_class,
82
- gaode: mars3d_class
83
- }
84
-
85
- return fn[hnMap.mapType]
86
- }
@@ -1,163 +0,0 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util.js'
2
- import mars3d_entity from '../base/mars3d_entity.js'
3
- import gaode_entity from "../base/gaode_entity.js";
4
-
5
- const HorizontalOrigin = {
6
- center: 0,
7
- left: 1,
8
- right: -1
9
- }
10
-
11
- const VerticalOrigin = {
12
- center: 0,
13
- top: -1,
14
- bottom: 1
15
- }
16
-
17
- export default (hnMap) => {
18
-
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: Number.MAX_VALUE,
35
- distanceDisplayCondition_near: 0,
36
- data: null
37
- }
38
-
39
- class mars3d_class extends mars3d_entity {
40
- id = null
41
- option = JSON.parse(JSON.stringify(defaultOption))
42
- config = null
43
- graphic = null
44
-
45
-
46
- constructor(option) {
47
- super()
48
- this.id = option.id
49
- deepMerge(this.option, option)
50
- this.config = this.formatConfig(this.option)
51
- this.graphic = new mars3d.graphic.BillboardEntity(this.config)
52
- }
53
-
54
- formatConfig(option) {
55
- return {
56
- id: option.id,
57
- position: option.position,
58
- style: {
59
- width: option.width,
60
- height: option.height,
61
- image: option.image,
62
- label: {
63
- text: option.text,
64
- font_size: option.fontSize,
65
- color: option.color,
66
- pixelOffset: option.offset,
67
- scaleByDistance: option.scaleByDistance,
68
- distanceDisplayCondition: option.distanceDisplayCondition,
69
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
70
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
71
- visibleDepth: false
72
- },
73
- scaleByDistance: option.scaleByDistance,
74
- distanceDisplayCondition: option.distanceDisplayCondition,
75
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
76
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
77
- clampToGround: !option.position[2],
78
- rotationDegree: option.rotation,
79
- horizontalOrigin: HorizontalOrigin[option.horizontalOrigin],
80
- verticalOrigin: VerticalOrigin[option.verticalOrigin],
81
- visibleDepth: true
82
- },
83
- attr: option.data
84
- }
85
- }
86
-
87
- set(option) {
88
- deepMerge(this.option, option)
89
- this.config = this.formatConfig(this.option)
90
- this.graphic.setOptions(this.config)
91
- }
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
-
109
- class gaode_class extends gaode_entity {
110
- type = 'imagePoint'
111
- id = null
112
- option = JSON.parse(JSON.stringify(defaultOption))
113
- config = null
114
- graphic = null
115
-
116
- constructor(option) {
117
- super()
118
- this.id = option.id
119
- deepMerge(this.option, option)
120
- this.config = this.formatConfig(this.option)
121
- this.graphic = new AMap.Marker(this.config)
122
- }
123
-
124
- formatConfig(option) {
125
- let amapPosition = wgs84ToGcj02Format(option.position)
126
- const content = `<div style="color:${option.color};font-size:${option.fontSize} ">${option.text}</div>`
127
- return {
128
- extData: {
129
- id: option.id,
130
- data: option.data,
131
- },
132
- position: new AMap.LngLat(amapPosition[0], amapPosition[1]),
133
- icon: new AMap.Icon({
134
- image: option.image,
135
- imageSize: new AMap.Size(option.height, option.width),
136
- size: new AMap.Size(option.height, option.width),
137
- }),
138
- angle: 360 - option.rotation,
139
- anchor: 'center',
140
- label: {
141
- direction: 'center',
142
- offset: new AMap.Pixel(option.offset[0], option.offset[1]), //设置文本标注偏移量
143
- content: content,
144
- }
145
- }
146
- }
147
-
148
- set(option) {
149
- deepMerge(this.option, option)
150
- this.config = this.formatConfig(this.option)
151
- this.graphic.setOptions(this.config)
152
- this.graphic.setAngle(this.config.angle)
153
-
154
- }
155
- }
156
-
157
- const fn = {
158
- mars3d: mars3d_class,
159
- gaode: gaode_class
160
- }
161
-
162
- return fn[hnMap.mapType]
163
- }
@@ -1,176 +0,0 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util.js'
2
- import mars3d_entity from '../base/mars3d_entity.js'
3
- import gaode_entity from "../base/gaode_entity.js";
4
-
5
- export default (hnMap) => {
6
-
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: Number.MAX_VALUE,
27
- distanceDisplayCondition_near: 0,
28
- data: null
29
- }
30
-
31
- class mars3d_class extends mars3d_entity {
32
- type = 'label'
33
- id = null
34
- option = JSON.parse(JSON.stringify(defaultOption))
35
- config = null
36
- graphic = null
37
-
38
- constructor(option) {
39
- super()
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) {
51
- if (option.type === 'label') {
52
-
53
- const position = new mars3d.LngLatPoint(
54
- option.position[0],
55
- option.position[1],
56
- option.position[2] || 0
57
- );
58
- return {
59
- id: option.id,
60
- position: position,
61
- style: {
62
- text: option.text,
63
- color: option.color,
64
- opacity: option.opacity,
65
- font_size: option.fontSize,
66
- font_family: option.fontFamily,
67
- outline: option.outline,
68
- outlineColor: option.outlineColor,
69
- outlineWidth: option.outlineWidth,
70
- outlineOpacity: option.outlineOpacity,
71
- pixelOffset: option.offset,
72
- scaleByDistance: option.scaleByDistance,
73
- clampToGround: !option.position[2],
74
- distanceDisplayCondition: option.distanceDisplayCondition,
75
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
76
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
77
- background: !!option.background,
78
- backgroundColor: option.background,
79
- },
80
- attr: option.data
81
- }
82
- } else if (option.type === 'mapLabel') {
83
- const p1 = new mars3d.LngLatPoint(option.position[0][0], option.position[0][1])
84
- const p2 = new mars3d.LngLatPoint(option.position[1][0], option.position[1][1])
85
- return {
86
- id: option.id,
87
- positions: [p1, p2],
88
- style: {
89
- clampToGround: !option.position[0][2],
90
- materialOptions: {
91
- text: option.text,
92
- font_family: '楷体',
93
- color: option.color,
94
- font_weight: option.fontWeight,
95
- font_size: option.fontSize,
96
- background: !!option.background,
97
- stroke: option.outline,
98
- strokeColor: option.outlineColor,
99
- strokeWidth: option.outlineWidth,
100
- opacity: option.opacity,
101
- },
102
- materialType: mars3d.MaterialType.Text,
103
- rotationDegree: option.angle,
104
- distanceDisplayCondition: option.distanceDisplayCondition,
105
- distanceDisplayCondition_far: option.distanceDisplayCondition_far,
106
- distanceDisplayCondition_near: option.distanceDisplayCondition_near,
107
- },
108
- attr: option.data
109
- }
110
- }
111
-
112
- }
113
-
114
- set(option) {
115
- deepMerge(this.option, option)
116
- this.config = this.formatConfig(this.option)
117
- this.graphic.setOptions(this.config)
118
- }
119
-
120
- }
121
-
122
- class gaode_class extends gaode_entity {
123
-
124
- id = null
125
- option = JSON.parse(JSON.stringify(defaultOption))
126
- config = null
127
- graphic = null
128
-
129
- constructor(option) {
130
- super()
131
- this.id = option.id
132
- deepMerge(this.option, option)
133
- this.config = this.formatConfig(this.option)
134
- this.graphic = new AMap.Text(this.config)
135
- }
136
-
137
- formatConfig(option) {
138
- let amapPosition = wgs84ToGcj02Format(option.position)
139
- return {
140
- extData: {
141
- id: option.id,
142
- data: option.data,
143
- },
144
- text: option.text,
145
- anchor: 'center', // 设置文本标记锚点
146
- draggable: true,
147
- cursor: 'pointer',
148
- style: {
149
- 'border': 0,
150
- 'text-align': 'center',
151
- 'font-size': option.fontSize,
152
- 'color': option.color,
153
- 'background-color': option.background,
154
- },
155
- position: [amapPosition[0], amapPosition[1]],
156
- offset: option.offset,
157
- }
158
- }
159
-
160
- set(option) {
161
- deepMerge(this.option, option)
162
- this.config = this.formatConfig(this.option)
163
- this.graphic.setText(this.config.text)
164
- this.graphic.setStyle(this.config.style)
165
- this.graphic.setPosition(this.config.position)
166
-
167
- }
168
- }
169
-
170
- const fn = {
171
- mars3d: mars3d_class,
172
- gaode: gaode_class
173
- }
174
-
175
- return fn[hnMap.mapType]
176
- }