hn-map 1.1.2 → 1.1.4

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/dist/index.js CHANGED
@@ -463,7 +463,7 @@
463
463
  // 思极key
464
464
  sj_app_key: "",
465
465
  sj_app_secret: "",
466
- style: "aegis://styles/aegis/Streets-Raster512"
466
+ sj_style: "aegis://styles/aegis/Streets-Raster512"
467
467
  };
468
468
  var mars3d_map = /*#__PURE__*/function () {
469
469
  function mars3d_map(id, option) {
@@ -477,7 +477,7 @@
477
477
  this.event = {};
478
478
  this.level = null;
479
479
  this.layerList = [];
480
- this.level = this.option.level;
480
+ this.level = 10;
481
481
  deepMerge(this.option, option);
482
482
  this.config = this.formatConfig(this.option);
483
483
  this.map = new mars3d.Map(id, this.config);
@@ -744,6 +744,7 @@
744
744
  _classCallCheck(this, siji_map);
745
745
  this.id = null;
746
746
  this.map = null;
747
+ this.geocodingTask = null;
747
748
  this.option = JSON.parse(JSON.stringify(defaultOption));
748
749
  this.config = null;
749
750
  // 图层集合
@@ -756,6 +757,7 @@
756
757
  deepMerge(this.option, option);
757
758
  this.config = this.formatConfig(this.option);
758
759
  this.map = new SGMap.Map(this.config);
760
+ this.geocodingTask = new SGMap.GeocodingTask();
759
761
  this.map.on("moveend", function (e) {
760
762
  return _this2.updateMapParams(e);
761
763
  }); // 地图移动完成
@@ -765,13 +767,20 @@
765
767
  this.map.on("pitchend", function (e) {
766
768
  return _this2.updateMapParams(e);
767
769
  }); // 地图俯仰角度完成
770
+ this.map.on("load", function (e) {
771
+ // 路况展示
772
+ var roadNetLayer = new SGMap.RoadNetLayer({
773
+ map: _this2.map
774
+ });
775
+ roadNetLayer.render();
776
+ });
768
777
  }
769
778
  return _createClass(siji_map, [{
770
779
  key: "formatConfig",
771
780
  value: function formatConfig(option) {
772
781
  return {
773
782
  container: this.id,
774
- style: "aegis://styles/aegis/Streets-v2",
783
+ style: option.sj_style || "aegis://styles/aegis/StreetsDark-v2",
775
784
  // 默认缩放层级
776
785
  zoom: option.level,
777
786
  // 地图中心点
@@ -841,7 +850,11 @@
841
850
  switch (eventType) {
842
851
  case "click":
843
852
  this.event[eventType] = function (event) {
844
- callback(event.lngLat);
853
+ callback({
854
+ lng: event.lngLat.lng,
855
+ lat: event.lngLat.lat,
856
+ alt: event.lngLat.alt || 0
857
+ });
845
858
  };
846
859
  break;
847
860
  case "dblclick":
@@ -1160,6 +1173,7 @@
1160
1173
  })) {
1161
1174
  console.error("已存在同名图形" + entity.id);
1162
1175
  } else {
1176
+ alert(entity.id);
1163
1177
  this.children.push(entity);
1164
1178
  this.layerEntity.addOverlay(entity.graphic); // 添加图形
1165
1179
  // 图层添加新图形后,需要重新调用绑定点击弹窗方法
@@ -1325,6 +1339,7 @@
1325
1339
  value: function addLevelEntity(entity) {
1326
1340
  if (entity.type == "imagePoint") {
1327
1341
  hnMap.map.map.loadImage(entity.option.image, function (error, image) {
1342
+ entity.config.layout["icon-size"] = entity.option.width / image.width;
1328
1343
  hnMap.map.map.addImage(entity.id + "_image", image);
1329
1344
  hnMap.map.map.addLayer(entity.config);
1330
1345
  });
@@ -1385,6 +1400,14 @@
1385
1400
  entity.show = false;
1386
1401
  }
1387
1402
  }
1403
+ // 控制图层层高
1404
+ }, {
1405
+ key: "moveEntity",
1406
+ value: function moveEntity(layerIds) {
1407
+ // 数组转字符串
1408
+ var s = layerIds.join(",");
1409
+ hnMap.map.map.moveLayer(s);
1410
+ }
1388
1411
  }, {
1389
1412
  key: "clearEntity",
1390
1413
  value: function clearEntity() {
@@ -1641,9 +1664,6 @@
1641
1664
  key: "addPopupByAttr",
1642
1665
  value: function addPopupByAttr() {
1643
1666
  var _this = this;
1644
- alert("添加属性弹窗");
1645
- console.log(this.config);
1646
- console.log(this.graphic);
1647
1667
  // 如果已有弹窗,先关闭
1648
1668
  this.removePopup();
1649
1669
  this.infoWindow = new SGMap.Popup({
@@ -1653,7 +1673,6 @@
1653
1673
  className: "my-popupAttr-class"
1654
1674
  });
1655
1675
  var handleClick = function handleClick(e) {
1656
- alert("添加属性弹窗111");
1657
1676
  // const data = e.features[0].properties;
1658
1677
  var data = _this.option.data;
1659
1678
  // 创建弹窗内容
@@ -1681,8 +1700,8 @@
1681
1700
  var handleClick = function handleClick(e) {
1682
1701
  var data = _this2.option.data;
1683
1702
  // const data = e.features[0].properties;
1684
- var dom = getCustomDom(data);
1685
- _this2.infoWindow.setHTML(dom);
1703
+ getCustomDom(data);
1704
+ _this2.infoWindow.setHTML("<image-preview>");
1686
1705
  _this2.infoWindow.setLngLat(e.lngLat).addTo(_this2.hnMap.map.map);
1687
1706
  };
1688
1707
  this.hnMap.map.map.on("click", this.config.id, handleClick);
@@ -1698,12 +1717,27 @@
1698
1717
  }, {
1699
1718
  key: "flyTo",
1700
1719
  value: function flyTo() {
1720
+ var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1721
+ deepMerge(this.option, option);
1722
+ console.log(this.option, "=====flyTo");
1701
1723
  var zoom = this.hnMap.map.map.getZoom();
1724
+ var center;
1725
+ if (this.option.center) {
1726
+ center = this.option.center;
1727
+ } else {
1728
+ if (this.type == "line" || this.type == "dash" || this.type == "flicker" || this.type == "flow" || this.type == "arrow" || this.type == "mapLabel" || this.type == "polygon" || this.type == "rectangle") {
1729
+ center = this.option.position[0];
1730
+ } else if (this.type == "route") {
1731
+ center = [this.option.position[0][0], this.option.position[0][1]];
1732
+ } else {
1733
+ center = this.option.position;
1734
+ }
1735
+ }
1702
1736
  this.hnMap.map.map.flyTo({
1703
1737
  duration: 1000,
1704
1738
  // 持续时间
1705
- zoom: zoom,
1706
- center: this.type == "line" || this.type == "dash" || this.type == "flicker" || this.type == "flow" || this.type == "arrow" || this.type == "mapLabel" || this.type == "polygon" || this.type == "rectangle" ? this.option.position[0] : this.type == "route" ? [this.option.position[0][0], this.option.position[0][1]] : this.option.position
1739
+ zoom: this.option.zoom || zoom,
1740
+ center: center
1707
1741
  });
1708
1742
  }
1709
1743
  }, {
@@ -1908,7 +1942,9 @@
1908
1942
  type: "Feature",
1909
1943
  geometry: {
1910
1944
  type: "Point",
1911
- coordinates: option.position
1945
+ coordinates: option.position.map(function (num) {
1946
+ return Number(num);
1947
+ })
1912
1948
  },
1913
1949
  properties: Object.assign({
1914
1950
  id: option.id
@@ -1943,7 +1979,9 @@
1943
1979
  },
1944
1980
  geometry: {
1945
1981
  type: "Point",
1946
- coordinates: this.option.position
1982
+ coordinates: this.option.position.map(function (num) {
1983
+ return Number(num);
1984
+ })
1947
1985
  }
1948
1986
  }]
1949
1987
  });
@@ -2111,7 +2149,9 @@
2111
2149
  type: "Feature",
2112
2150
  geometry: {
2113
2151
  type: "Point",
2114
- coordinates: option.position
2152
+ coordinates: option.position.map(function (num) {
2153
+ return Number(num);
2154
+ })
2115
2155
  },
2116
2156
  properties: {
2117
2157
  name: option.text
@@ -2142,7 +2182,9 @@
2142
2182
  type: "Feature",
2143
2183
  geometry: {
2144
2184
  type: "Point",
2145
- coordinates: option.position
2185
+ coordinates: option.position.map(function (num) {
2186
+ return Number(num);
2187
+ })
2146
2188
  },
2147
2189
  properties: {
2148
2190
  name: option.num
@@ -2153,6 +2195,7 @@
2153
2195
  layout: {
2154
2196
  "icon-anchor": "center",
2155
2197
  "text-field": "{name}",
2198
+ // 文本
2156
2199
  "text-size": Number(option.size),
2157
2200
  "text-anchor": "center" // 顶部对齐
2158
2201
  },
@@ -2179,7 +2222,9 @@
2179
2222
  },
2180
2223
  geometry: {
2181
2224
  type: "Point",
2182
- coordinates: this.option.position
2225
+ coordinates: this.option.position.map(function (num) {
2226
+ return Number(num);
2227
+ })
2183
2228
  }
2184
2229
  }]
2185
2230
  });
@@ -2206,7 +2251,9 @@
2206
2251
  },
2207
2252
  geometry: {
2208
2253
  type: "Point",
2209
- coordinates: this.option.position
2254
+ coordinates: this.option.position.map(function (num) {
2255
+ return Number(num);
2256
+ })
2210
2257
  }
2211
2258
  }]
2212
2259
  });
@@ -2426,15 +2473,26 @@
2426
2473
  })
2427
2474
  },
2428
2475
  properties: {
2429
- name: ""
2476
+ name: option.text
2430
2477
  }
2431
2478
  }]
2432
2479
  }
2433
2480
  },
2434
2481
  layout: {
2435
2482
  "icon-image": option.id + "_image",
2436
- "icon-size": Number(option.width) / Number(option.height)
2437
- }
2483
+ "icon-size": 1,
2484
+ "icon-ignore-placement": true,
2485
+ "text-ignore-placement": true,
2486
+ "text-field": "{name}",
2487
+ // 文本
2488
+ "text-size": option.fontSize,
2489
+ "text-anchor": "top",
2490
+ "icon-anchor": "center",
2491
+ "text-offset": option.offset
2492
+ },
2493
+ paint: {
2494
+ "text-color": option.color
2495
+ } // 填充样式
2438
2496
  };
2439
2497
  return config;
2440
2498
  }
@@ -2468,6 +2526,18 @@
2468
2526
  }
2469
2527
  }
2470
2528
  }
2529
+ for (var _key in this.config) {
2530
+ if (this.config.hasOwnProperty(_key)) {
2531
+ if (_key == "paint") {
2532
+ for (var _key2 in this.config[_key]) {
2533
+ if (this.config[_key].hasOwnProperty(_key2)) {
2534
+ // 遍历 paint 属性
2535
+ hnMap.map.map.setPaintProperty(this.config.id, _key2, this.config[_key][_key2]);
2536
+ }
2537
+ }
2538
+ }
2539
+ }
2540
+ }
2471
2541
  }
2472
2542
  }]);
2473
2543
  }(siji_entity);
@@ -5197,7 +5267,6 @@
5197
5267
  if (!HnMap.allowConstruction) {
5198
5268
  throw new Error("请使用 HnMap.create() 创建实例");
5199
5269
  }
5200
- console.log(11111111111);
5201
5270
  this.id = id;
5202
5271
  this.option = option;
5203
5272
  this.mapType = mapType;
@@ -5285,7 +5354,7 @@
5285
5354
  return SGMap.tokenTask.login(option.sj_app_key, option.sj_app_secret);
5286
5355
  case 15:
5287
5356
  _context.n = 16;
5288
- return SGMap.plugin(["SGMap.DrawPolygonHandler", "SGMap.DrawCircleHandler", "SGMap.DrawRectangleHandler", "SGMap.GeocodingTask"]);
5357
+ return SGMap.plugin(["SGMap.DrawPolygonHandler", "SGMap.DrawCircleHandler", "SGMap.DrawRectangleHandler", "SGMap.GeocodingTask", "SGMap.RoadNetLayer"]);
5289
5358
  case 16:
5290
5359
  return _context.a(3, 17);
5291
5360
  case 17:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hn-map",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "hn-map集成mars3d、高德、思极",
5
5
  "main": "dist/index.js",
6
6
  "author": "庞大仙",
@@ -1,3 +1,4 @@
1
+ import { deepMerge } from "../util";
1
2
  export default class siji_entity {
2
3
  event: any = {};
3
4
  infoWindow: any = null;
@@ -6,7 +7,7 @@ export default class siji_entity {
6
7
  graphic: any = null;
7
8
  option: any = null;
8
9
  type: any = null;
9
- show:boolean = false;
10
+ show: boolean = false;
10
11
 
11
12
  constructor(hnMap: any) {
12
13
  this.hnMap = hnMap;
@@ -16,9 +17,6 @@ export default class siji_entity {
16
17
 
17
18
  // 添加属性弹窗
18
19
  addPopupByAttr() {
19
- alert("添加属性弹窗");
20
- console.log(this.config);
21
- console.log(this.graphic);
22
20
  // 如果已有弹窗,先关闭
23
21
  this.removePopup();
24
22
 
@@ -28,7 +26,6 @@ export default class siji_entity {
28
26
  });
29
27
 
30
28
  const handleClick = (e: any) => {
31
- alert("添加属性弹窗111");
32
29
  // const data = e.features[0].properties;
33
30
  const data = this.option.data;
34
31
  // 创建弹窗内容
@@ -47,7 +44,6 @@ export default class siji_entity {
47
44
  // 添加自定义dom弹窗
48
45
  addCustomPopup(getCustomDom: any) {
49
46
  this.removePopup();
50
-
51
47
  this.infoWindow = new SGMap.Popup({
52
48
  offset: { bottom: [0, 0] },
53
49
  className: "my-customPopup-class",
@@ -57,7 +53,7 @@ export default class siji_entity {
57
53
  const data = this.option.data;
58
54
  // const data = e.features[0].properties;
59
55
  const dom = getCustomDom(data);
60
- this.infoWindow.setHTML(dom);
56
+ this.infoWindow.setHTML("<image-preview>");
61
57
  this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
62
58
  };
63
59
 
@@ -71,12 +67,15 @@ export default class siji_entity {
71
67
  }
72
68
  }
73
69
 
74
- flyTo() {
70
+ flyTo(option: any = {}) {
71
+ deepMerge(this.option, option);
72
+ console.log(this.option, "=====flyTo");
75
73
  let zoom = this.hnMap.map.map.getZoom();
76
- this.hnMap.map.map.flyTo({
77
- duration: 1000, // 持续时间
78
- zoom: zoom,
79
- center:
74
+ let center;
75
+ if (this.option.center) {
76
+ center = this.option.center;
77
+ } else {
78
+ if (
80
79
  this.type == "line" ||
81
80
  this.type == "dash" ||
82
81
  this.type == "flicker" ||
@@ -85,10 +84,18 @@ export default class siji_entity {
85
84
  this.type == "mapLabel" ||
86
85
  this.type == "polygon" ||
87
86
  this.type == "rectangle"
88
- ? this.option.position[0]
89
- : this.type == "route"
90
- ? [this.option.position[0][0], this.option.position[0][1]]
91
- : this.option.position,
87
+ ) {
88
+ center = this.option.position[0];
89
+ } else if (this.type == "route") {
90
+ center = [this.option.position[0][0], this.option.position[0][1]];
91
+ } else {
92
+ center = this.option.position;
93
+ }
94
+ }
95
+ this.hnMap.map.map.flyTo({
96
+ duration: 1000, // 持续时间
97
+ zoom: this.option.zoom || zoom,
98
+ center: center,
92
99
  });
93
100
  }
94
101
 
@@ -1,4 +1,4 @@
1
- import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
1
+ import { deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format } from "../util";
2
2
  import mars3d_entity from "../base/mars3d_entity";
3
3
  import gaode_entity from "../base/gaode_entity";
4
4
  import siji_entity from "../base/siji_entity";
@@ -42,8 +42,12 @@ export default (hnMap: any) => {
42
42
  }
43
43
 
44
44
  formatConfig(option: any) {
45
- const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
46
- const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
45
+ const distanceDisplayCondition_far = getLevelMiddleHeight(
46
+ option.distanceDisplayCondition_far
47
+ );
48
+ const distanceDisplayCondition_near = getLevelMiddleHeight(
49
+ option.distanceDisplayCondition_near
50
+ );
47
51
  let config: any = {
48
52
  id: option.id,
49
53
  position: new mars3d.LngLatPoint(
@@ -1,4 +1,4 @@
1
- import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
1
+ import { deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format } from "../util";
2
2
  import mars3d_entity from "../base/mars3d_entity";
3
3
  import gaode_entity from "../base/gaode_entity";
4
4
  import siji_entity from "../base/siji_entity";
@@ -51,8 +51,12 @@ export default (hnMap: any) => {
51
51
  }
52
52
 
53
53
  formatConfig(option: any) {
54
- const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
55
- const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
54
+ const distanceDisplayCondition_far = getLevelMiddleHeight(
55
+ option.distanceDisplayCondition_far
56
+ );
57
+ const distanceDisplayCondition_near = getLevelMiddleHeight(
58
+ option.distanceDisplayCondition_near
59
+ );
56
60
  return {
57
61
  id: option.id,
58
62
  position: option.position,
@@ -174,10 +178,10 @@ export default (hnMap: any) => {
174
178
  type: "Feature",
175
179
  geometry: {
176
180
  type: "Point",
177
- coordinates: option.position.map((num:any)=>Number(num)),
181
+ coordinates: option.position.map((num: any) => Number(num)),
178
182
  },
179
183
  properties: {
180
- name: "",
184
+ name: option.text,
181
185
  },
182
186
  },
183
187
  ],
@@ -185,8 +189,18 @@ export default (hnMap: any) => {
185
189
  },
186
190
  layout: {
187
191
  "icon-image": option.id + "_image",
188
- "icon-size": Number(option.width) / Number(option.height),
192
+ "icon-size": 1,
193
+ "icon-ignore-placement": true,
194
+ "text-ignore-placement": true,
195
+ "text-field": "{name}", // 文本
196
+ "text-size": option.fontSize,
197
+ "text-anchor": "top",
198
+ "icon-anchor": "center",
199
+ "text-offset": option.offset,
189
200
  },
201
+ paint: {
202
+ "text-color": option.color,
203
+ }, // 填充样式
190
204
  };
191
205
  return config;
192
206
  }
@@ -202,7 +216,7 @@ export default (hnMap: any) => {
202
216
  type: "Feature",
203
217
  geometry: {
204
218
  type: "Point",
205
- coordinates: this.option.position.map((num:any)=>Number(num)),
219
+ coordinates: this.option.position.map((num: any) => Number(num)),
206
220
  },
207
221
  },
208
222
  ],
@@ -224,6 +238,23 @@ export default (hnMap: any) => {
224
238
  }
225
239
  }
226
240
  }
241
+
242
+ for (let key in this.config) {
243
+ if (this.config.hasOwnProperty(key)) {
244
+ if (key == "paint") {
245
+ for (let key2 in this.config[key]) {
246
+ if (this.config[key].hasOwnProperty(key2)) {
247
+ // 遍历 paint 属性
248
+ hnMap.map.map.setPaintProperty(
249
+ this.config.id,
250
+ key2,
251
+ this.config[key][key2]
252
+ );
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
227
258
  }
228
259
  }
229
260
 
@@ -1,4 +1,4 @@
1
- import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
1
+ import { deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format } from "../util";
2
2
  import mars3d_entity from "../base/mars3d_entity";
3
3
  import gaode_entity from "../base/gaode_entity";
4
4
  import siji_entity from "../base/siji_entity";
@@ -35,8 +35,12 @@ export default (hnMap: any) => {
35
35
  }
36
36
 
37
37
  formatConfig(option: any) {
38
- const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
39
- const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
38
+ const distanceDisplayCondition_far = getLevelMiddleHeight(
39
+ option.distanceDisplayCondition_far
40
+ );
41
+ const distanceDisplayCondition_near = getLevelMiddleHeight(
42
+ option.distanceDisplayCondition_near
43
+ );
40
44
  return {
41
45
  id: option.id,
42
46
  position: option.position,
@@ -140,7 +144,7 @@ export default (hnMap: any) => {
140
144
  type: "Feature",
141
145
  geometry: {
142
146
  type: "Point",
143
- coordinates: option.position,
147
+ coordinates: option.position.map((num: any) => Number(num)),
144
148
  },
145
149
  properties: {
146
150
  name: option.text,
@@ -173,7 +177,7 @@ export default (hnMap: any) => {
173
177
  type: "Feature",
174
178
  geometry: {
175
179
  type: "Point",
176
- coordinates: option.position,
180
+ coordinates: option.position.map((num: any) => Number(num)),
177
181
  },
178
182
  properties: {
179
183
  name: option.num,
@@ -184,7 +188,7 @@ export default (hnMap: any) => {
184
188
  },
185
189
  layout: {
186
190
  "icon-anchor": "center",
187
- "text-field": "{name}",
191
+ "text-field": "{name}", // 文本
188
192
  "text-size": Number(option.size),
189
193
  "text-anchor": "center", // 顶部对齐
190
194
  }, // 文本样式
@@ -209,7 +213,7 @@ export default (hnMap: any) => {
209
213
  properties: { name: this.option.text },
210
214
  geometry: {
211
215
  type: "Point",
212
- coordinates: this.option.position,
216
+ coordinates: this.option.position.map((num: any) => Number(num)),
213
217
  },
214
218
  },
215
219
  ],
@@ -242,7 +246,7 @@ export default (hnMap: any) => {
242
246
  properties: { name: this.option.num },
243
247
  geometry: {
244
248
  type: "Point",
245
- coordinates: this.option.position,
249
+ coordinates: this.option.position.map((num: any) => Number(num)),
246
250
  },
247
251
  },
248
252
  ],
@@ -162,7 +162,7 @@ export default (hnMap: any) => {
162
162
  type: "Feature",
163
163
  geometry: {
164
164
  type: "Point",
165
- coordinates: option.position,
165
+ coordinates: option.position.map((num:any)=>Number(num)),
166
166
  },
167
167
  properties: {
168
168
  id: option.id,
@@ -198,7 +198,7 @@ export default (hnMap: any) => {
198
198
  properties: { name: this.option.text },
199
199
  geometry: {
200
200
  type: "Point",
201
- coordinates: this.option.position,
201
+ coordinates: this.option.position.map((num:any)=>Number(num)),
202
202
  },
203
203
  },
204
204
  ],