hn-map 1.1.14 → 1.1.15

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
@@ -392,24 +392,6 @@
392
392
  return [leftTopPoint, rightTopPoint, rightBottomPoint, leftBottomPoint, leftTopPoint // 闭合矩形
393
393
  ];
394
394
  }
395
- function getMapRangeHeightByLevel(level) {
396
- // 输入校验:限制在 1~18
397
- level = Math.max(1, Math.min(18, Math.floor(level)));
398
- // 计算指定 level 对应的高度(level >= 2 时使用指数衰减)
399
- function getHeight(lvl) {
400
- if (lvl === 1) {
401
- return Infinity; // level=1 表示“最大高度”,逻辑上为无穷大
402
- } else {
403
- return 32000000 / Math.pow(2, lvl - 2);
404
- }
405
- }
406
- var endHeight = getHeight(level); // 当前 level 的“粗略”高度
407
- var startHeight = level < 18 ? getHeight(level + 1) : 0; // 下一级更细
408
- return {
409
- startHeight: startHeight,
410
- endHeight: endHeight
411
- };
412
- }
413
395
  /**
414
396
  * 根据 level 返回该层级的“中间高度”(几何平均值)
415
397
  *
@@ -417,16 +399,19 @@
417
399
  * @returns {number} 中间高度(米)
418
400
  */
419
401
  function getLevelMiddleHeight(level) {
420
- var _getMapRangeHeightByL = getMapRangeHeightByLevel(level),
421
- startHeight = _getMapRangeHeightByL.startHeight,
422
- endHeight = _getMapRangeHeightByL.endHeight;
423
- // 如果 startHeight 0(如 level=18),几何平均会为 0,不合理
424
- // 所以 level=18 特殊处理:返回 (0 + end)/2 或直接返回 end * 0.7 左右
425
- if (startHeight === 0) {
426
- return endHeight * 0.7; // 经验值,贴近“中间感知”
427
- }
428
- // 几何平均:√(start × end)
429
- return Math.sqrt(startHeight * endHeight);
402
+ // const { startHeight, endHeight } = getMapRangeHeightByLevel(level);
403
+ // // 如果 startHeight 为 0(如 level=18),几何平均会为 0,不合理
404
+ // // 所以 level=18 特殊处理:返回 (0 + end)/2 或直接返回 end * 0.7 左右
405
+ // if (startHeight === 0) {
406
+ // return endHeight * 0.7; // 经验值,贴近“中间感知”
407
+ // }
408
+ //
409
+ // // 几何平均:√(start × end)
410
+ // return Math.sqrt(startHeight * endHeight);
411
+ var EARTH_RADIUS = 6378137; // 赤道半径
412
+ var height = 2 * Math.PI * EARTH_RADIUS / (256 * Math.pow(2, level));
413
+ console.log(height);
414
+ return height;
430
415
  }
431
416
  /**
432
417
  * 根据高度反推 level(1~18)
@@ -538,6 +523,7 @@
538
523
  deepMerge(this.option, option);
539
524
  this.config = this.formatConfig(this.option);
540
525
  this.map = new mars3d.Map(id, this.config);
526
+ console.log(this.config);
541
527
  this.map.on("cameraMoveEnd", function (e) {
542
528
  var height = _this.map.getCameraView().alt;
543
529
  _this.level = getHeightToLevel(height);
@@ -904,7 +890,7 @@
904
890
  lng: event.lngLat.lng,
905
891
  lat: event.lngLat.lat,
906
892
  alt: event.lngLat.alt || 0
907
- });
893
+ }, event);
908
894
  };
909
895
  break;
910
896
  case "dblclick":
@@ -1001,9 +987,9 @@
1001
987
  }
1002
988
  //添加天空图层
1003
989
  instance.map.addLayer({
1004
- "id": "sky",
1005
- "type": "sky",
1006
- "paint": {
990
+ id: "sky",
991
+ type: "sky",
992
+ paint: {
1007
993
  "sky-type": "atmosphere",
1008
994
  "sky-atmosphere-sun": [0, 0],
1009
995
  "sky-atmosphere-sun-intensity": 15
@@ -1082,6 +1068,15 @@
1082
1068
  entity.start();
1083
1069
  } else if (entity.type == "pointCloud" || entity.type == "heatMap") {
1084
1070
  hnMap.map.map.addLayer(entity.layerEntity);
1071
+ } else if (entity.type == "cluster") {
1072
+ // 添加聚合图层到地图
1073
+ hnMap.map.map.addLayer(entity.layerEntity);
1074
+ // 如果已有位置数据,立即设置
1075
+ if (entity.option.position && entity.option.position.length > 0) {
1076
+ setTimeout(function () {
1077
+ entity.setPosition(entity.option.position);
1078
+ }, 100);
1079
+ }
1085
1080
  } else {
1086
1081
  this.layerEntity.addGraphic(entity.graphic); // 添加图形
1087
1082
  }
@@ -1096,9 +1091,7 @@
1096
1091
  return v.id !== entity.id;
1097
1092
  });
1098
1093
  if (entity.type === "pointCloud" || entity.type === "heatMap") {
1099
- alert(entity.id);
1100
1094
  hnMap.map.map.removeLayer(entity.id);
1101
- // entity.id.destroy();
1102
1095
  }
1103
1096
  this.layerEntity.removeGraphic(entity.graphic);
1104
1097
  }
@@ -1467,6 +1460,21 @@
1467
1460
  duration: 2000,
1468
1461
  essential: true
1469
1462
  });
1463
+ } else if (entity.type == "cluster") {
1464
+ console.log("cluster=======", entity);
1465
+ hnMap.map.map.addLayer(entity.config_layer);
1466
+ hnMap.map.map.addLayer(entity.config_label);
1467
+ hnMap.map.map.loadImage(entity.option.image, function (error, image) {
1468
+ console.log("image======", image);
1469
+ entity.config_Image.layout["icon-size"] = entity.option.width / image.width;
1470
+ hnMap.map.map.addImage(entity.id + "_poiImage", image);
1471
+ hnMap.map.map.addLayer(entity.config_Image);
1472
+ });
1473
+ hnMap.map.map.flyTo({
1474
+ center: entity.option.position[0].position,
1475
+ duration: 2000,
1476
+ essential: true
1477
+ });
1470
1478
  } else {
1471
1479
  hnMap.map.map.addLayer(entity.config);
1472
1480
  }
@@ -4079,7 +4087,7 @@
4079
4087
  type: "Feature",
4080
4088
  geometry: {
4081
4089
  type: "Polygon",
4082
- coordinates: convertPosition(option.position) //三层数组[[[0,0],[0,0]]]
4090
+ coordinates: convertPosition(this.option.position) //三层数组[[[0,0],[0,0]]]
4083
4091
  }
4084
4092
  }]
4085
4093
  });
@@ -4772,9 +4780,6 @@
4772
4780
  geometry: {
4773
4781
  type: "Point",
4774
4782
  coordinates: [v.lng, v.lat]
4775
- },
4776
- properties: {
4777
- value: v.value
4778
4783
  }
4779
4784
  };
4780
4785
  })
@@ -4879,7 +4884,7 @@
4879
4884
  position: [],
4880
4885
  pixelRange: 20,
4881
4886
  cluster: true,
4882
- image: '',
4887
+ image: "",
4883
4888
  width: 20,
4884
4889
  height: 20,
4885
4890
  data: null
@@ -4889,7 +4894,7 @@
4889
4894
  var _this;
4890
4895
  _classCallCheck(this, mars3d_class);
4891
4896
  _this = _callSuper(this, mars3d_class, [option]);
4892
- _this.type = 'cluster';
4897
+ _this.type = "cluster";
4893
4898
  _this.id = null;
4894
4899
  _this.option = JSON.parse(JSON.stringify(defaultOption));
4895
4900
  _this.config_layer = null;
@@ -4899,9 +4904,11 @@
4899
4904
  _this.id = option.id;
4900
4905
  _this.children = [];
4901
4906
  deepMerge(_this.option, option);
4907
+ console.log("option===", _this.option);
4902
4908
  _this.config_layer = _this.formatConfigLayer(_this.option);
4903
4909
  _this.config_label = _this.formatConfigLabel(_this.option);
4904
4910
  _this.layerEntity = new mars3d.layer.GraphicLayer(_this.config_layer);
4911
+ // this.graphic = new mars3d.graphic.BillboardEntity(this.config_label);
4905
4912
  return _this;
4906
4913
  }
4907
4914
  // 格式化layer配置
@@ -4912,8 +4919,37 @@
4912
4919
  return {
4913
4920
  id: option.id,
4914
4921
  cluster: {
4915
- enabled: option.cluster,
4916
- pixelRange: option.pixelRange
4922
+ enabled: option.cluster !== false,
4923
+ // 默认开启聚合
4924
+ pixelRange: option.pixelRange || 20,
4925
+ // 添加更多聚合样式配置
4926
+ styles: [{
4927
+ scale: 1,
4928
+ image: "img/marker/mark1.png",
4929
+ label: {
4930
+ text: "{count}",
4931
+ color: "#ffffff",
4932
+ font_size: 16,
4933
+ stroke: true,
4934
+ strokeColor: "#000000"
4935
+ }
4936
+ }, {
4937
+ scale: 1.5,
4938
+ image: "img/marker/mark2.png",
4939
+ label: {
4940
+ text: "{count}",
4941
+ color: "#ffffff",
4942
+ font_size: 18
4943
+ }
4944
+ }, {
4945
+ scale: 2,
4946
+ image: "img/marker/mark3.png",
4947
+ label: {
4948
+ text: "{count}",
4949
+ color: "#ffffff",
4950
+ font_size: 20
4951
+ }
4952
+ }]
4917
4953
  }
4918
4954
  };
4919
4955
  }
@@ -4922,7 +4958,7 @@
4922
4958
  key: "formatConfigLabel",
4923
4959
  value: function formatConfigLabel(option) {
4924
4960
  return {
4925
- id: option.id,
4961
+ id: "label_" + option.id,
4926
4962
  image: option.image,
4927
4963
  width: option.width,
4928
4964
  height: option.height
@@ -4944,10 +4980,11 @@
4944
4980
  key: "setPosition",
4945
4981
  value: function setPosition(data) {
4946
4982
  var _this2 = this;
4983
+ console.log("setPosition", data);
4947
4984
  this.clearEntity();
4948
4985
  data.forEach(function (item, index) {
4949
4986
  var imagePointOption = {
4950
- id: _this2.config_label.id + '_point' + item.id,
4987
+ id: _this2.config_label.id + "_point" + item.id,
4951
4988
  position: item.position,
4952
4989
  image: _this2.config_label.image,
4953
4990
  height: _this2.config_label.height,
@@ -4958,6 +4995,7 @@
4958
4995
  _this2.addEntity(imagePoint);
4959
4996
  });
4960
4997
  }
4998
+ // 修改 cluster.ts 中的 mars3d_class 类
4961
4999
  }, {
4962
5000
  key: "destroy",
4963
5001
  value: function destroy() {
@@ -5019,7 +5057,7 @@
5019
5057
  key: "getEntity",
5020
5058
  value: function getEntity(entityParam) {
5021
5059
  var entity;
5022
- if (typeof entityParam == 'string') {
5060
+ if (typeof entityParam == "string") {
5023
5061
  entity = this.children.find(function (v) {
5024
5062
  return v.id === entityParam;
5025
5063
  });
@@ -5027,7 +5065,7 @@
5027
5065
  entity = entityParam;
5028
5066
  }
5029
5067
  if (!entity) {
5030
- return Promise.reject(new Error('未找到此图形'));
5068
+ return Promise.reject(new Error("未找到此图形"));
5031
5069
  }
5032
5070
  return entity;
5033
5071
  }
@@ -5076,30 +5114,30 @@
5076
5114
  lnglat: wgs84ToGcj02Format(item),
5077
5115
  // 添加弹窗属性参数
5078
5116
  extData: {
5079
- id: _this5.id + '_point' + index
5117
+ id: _this5.id + "_point" + index
5080
5118
  }
5081
5119
  };
5082
5120
  });
5083
5121
  var count = position.length;
5084
5122
  var _renderClusterMarker = function _renderClusterMarker(context) {
5085
5123
  var factor = Math.pow(context.count / count, 1 / 18);
5086
- var div = document.createElement('div');
5124
+ var div = document.createElement("div");
5087
5125
  var Hue = 180 - factor * 180;
5088
- var bgColor = 'hsla(' + Hue + ',100%,40%,0.7)';
5089
- var fontColor = 'hsla(' + Hue + ',100%,90%,1)';
5090
- var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
5091
- var shadowColor = 'hsla(' + Hue + ',100%,90%,1)';
5126
+ var bgColor = "hsla(" + Hue + ",100%,40%,0.7)";
5127
+ var fontColor = "hsla(" + Hue + ",100%,90%,1)";
5128
+ var borderColor = "hsla(" + Hue + ",100%,40%,1)";
5129
+ var shadowColor = "hsla(" + Hue + ",100%,90%,1)";
5092
5130
  div.style.backgroundColor = bgColor;
5093
5131
  var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
5094
- div.style.width = div.style.height = size + 'px';
5095
- div.style.border = 'solid 1px ' + borderColor;
5096
- div.style.borderRadius = size / 2 + 'px';
5097
- div.style.boxShadow = '0 0 5px ' + shadowColor;
5132
+ div.style.width = div.style.height = size + "px";
5133
+ div.style.border = "solid 1px " + borderColor;
5134
+ div.style.borderRadius = size / 2 + "px";
5135
+ div.style.boxShadow = "0 0 5px " + shadowColor;
5098
5136
  div.innerHTML = context.count;
5099
- div.style.lineHeight = size + 'px';
5137
+ div.style.lineHeight = size + "px";
5100
5138
  div.style.color = fontColor;
5101
- div.style.fontSize = '14px';
5102
- div.style.textAlign = 'center';
5139
+ div.style.fontSize = "14px";
5140
+ div.style.textAlign = "center";
5103
5141
  context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
5104
5142
  context.marker.setContent(div);
5105
5143
  };
@@ -5163,9 +5201,9 @@
5163
5201
  offset: new AMap.Pixel(0, -30)
5164
5202
  });
5165
5203
  }
5166
- this.layerEntity.on('click', function (cluster) {
5204
+ this.layerEntity.on("click", function (cluster) {
5167
5205
  if (cluster.clusterData.length === 1) {
5168
- var content = '';
5206
+ var content = "";
5169
5207
  var data = cluster.clusterData[0].extData;
5170
5208
  for (var key in data) {
5171
5209
  content += "<div>".concat(key, ": ").concat(data[key], "</div>");
@@ -5185,7 +5223,7 @@
5185
5223
  offset: new AMap.Pixel(0, -30)
5186
5224
  });
5187
5225
  }
5188
- this.layerEntity.on('click', function (cluster) {
5226
+ this.layerEntity.on("click", function (cluster) {
5189
5227
  if (cluster.clusterData.length === 1) {
5190
5228
  var data = cluster.clusterData[0].extData;
5191
5229
  var dom = getCustomDom(data);
@@ -5196,9 +5234,111 @@
5196
5234
  }
5197
5235
  }]);
5198
5236
  }();
5237
+ var siji_class = /*#__PURE__*/function () {
5238
+ function siji_class(option) {
5239
+ _classCallCheck(this, siji_class);
5240
+ this.type = "cluster";
5241
+ this.id = null;
5242
+ this.option = JSON.parse(JSON.stringify(defaultOption));
5243
+ this.config_layer = null;
5244
+ this.config_label = null;
5245
+ this.config_Image = null;
5246
+ this.layerEntity = null;
5247
+ // 创建全局信息窗口实例
5248
+ this.infoWindow = null;
5249
+ this.id = option.id;
5250
+ deepMerge(this.option, option);
5251
+ console.log("lalallalalalla======this.option", this.option);
5252
+ hnMap.map.map.addSource("themeData", {
5253
+ type: "geojson",
5254
+ data: {
5255
+ type: "FeatureCollection",
5256
+ features: this.option.position.map(function (v) {
5257
+ return {
5258
+ type: "Feature",
5259
+ geometry: {
5260
+ type: "Point",
5261
+ coordinates: convertPosition(v.position)
5262
+ },
5263
+ properties: {
5264
+ name: v.data.name
5265
+ }
5266
+ };
5267
+ })
5268
+ },
5269
+ cluster: true,
5270
+ clusterMaxZoom: 12,
5271
+ // 最大聚类层级
5272
+ clusterRadius: 100 // 聚合点半径,默认50
5273
+ });
5274
+ this.config_layer = this.formatConfigLayer(this.option);
5275
+ this.config_label = this.formatConfigLabel(this.option);
5276
+ this.config_Image = this.formatConfigImage(this.option);
5277
+ }
5278
+ return _createClass(siji_class, [{
5279
+ key: "formatConfigLayer",
5280
+ value: function formatConfigLayer(option) {
5281
+ return {
5282
+ id: "clusters_" + option.id,
5283
+ type: "circle",
5284
+ source: "themeData",
5285
+ filter: ["has", "point_count"],
5286
+ paint: {
5287
+ // 使用step表达式,用于分段匹配圆点的颜色和半径
5288
+ // 根据当前"point_count"值匹配对应的内容
5289
+ // 默认为"#9faebf"
5290
+ // 当大于10小于30时,返回"#3583de"
5291
+ // 大于30小于55时,返回"#04b71e"
5292
+ "circle-color": ["step", ["get", "point_count"], "#9faebf", 10, "#3583de", 30, "#04b71e", 55, "#ff9800", 100, "#f61402", 300, "#f61402"],
5293
+ "circle-radius": ["step", ["get", "point_count"], 20, 50, 30, 100, 35, 500, 35, 2000, 40, 5000, 40],
5294
+ "circle-opacity": 0.7,
5295
+ "circle-stroke-width": 3,
5296
+ "circle-stroke-color": "#ffffff"
5297
+ }
5298
+ };
5299
+ }
5300
+ }, {
5301
+ key: "formatConfigLabel",
5302
+ value: function formatConfigLabel(option) {
5303
+ return {
5304
+ id: "clusterCount_" + option.id,
5305
+ type: "symbol",
5306
+ source: "themeData",
5307
+ filter: ["has", "point_count"],
5308
+ layout: {
5309
+ "text-field": "{point_count_abbreviated}",
5310
+ "text-font": ["Microsoft YaHei Regular"],
5311
+ "text-size": 14
5312
+ },
5313
+ paint: {
5314
+ "text-color": "#ffffff"
5315
+ }
5316
+ };
5317
+ }
5318
+ }, {
5319
+ key: "formatConfigImage",
5320
+ value: function formatConfigImage(option) {
5321
+ return {
5322
+ id: "choicePoi_" + option.id,
5323
+ type: "symbol",
5324
+ source: "themeData",
5325
+ filter: ["!has", "point_count"],
5326
+ layout: {
5327
+ "icon-image": option.id + "_poiImage"
5328
+ },
5329
+ paint: {
5330
+ "text-color": "#555252",
5331
+ "text-halo-color": "#FFFFFF",
5332
+ "text-halo-width": 1.33333
5333
+ }
5334
+ };
5335
+ }
5336
+ }]);
5337
+ }();
5199
5338
  var fn = {
5200
5339
  mars3d: mars3d_class,
5201
- gaode: gaode_class
5340
+ gaode: gaode_class,
5341
+ siji: siji_class
5202
5342
  };
5203
5343
  return fn[hnMap.mapType];
5204
5344
  });
@@ -5330,6 +5470,7 @@
5330
5470
  type: "custom",
5331
5471
  renderingMode: "3d",
5332
5472
  onAdd: function onAdd(map, gl) {
5473
+ console.log("map====", map);
5333
5474
  this.camera = new THREE.Camera();
5334
5475
  this.scene = new THREE.Scene();
5335
5476
  var directionalLight = new THREE.DirectionalLight(0xffffff);
@@ -5341,8 +5482,7 @@
5341
5482
  // var loader = new THREE.GLTFLoader();
5342
5483
  var loader = new THREE.ObjectLoader();
5343
5484
  var that = this;
5344
- loader.load(option.url,
5345
- // 'https://map.sgcc.com.cn/products/js-sdk/v3/assets/model/ZH-SZC3-42.gltf',
5485
+ loader.load('https://map.sgcc.com.cn/products/js-sdk/v3/assets/model/ZH-SZC3-42.gltf',
5346
5486
  // function (gltf: any) {
5347
5487
  function (object) {
5348
5488
  that.scene.add(object);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hn-map",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "description": "hn-map集成mars3d、高德、思极",
5
5
  "main": "dist/index.js",
6
6
  "author": "庞大仙",
@@ -1,5 +1,3 @@
1
- import {getMapRangeHeightByLevel} from "../util";
2
-
3
1
  export default class mars3d_entity {
4
2
  option: any = null;
5
3
  event: any = {};
@@ -166,7 +166,7 @@ export default (hnMap: any) => {
166
166
  type: "Feature",
167
167
  geometry: {
168
168
  type: "Polygon",
169
- coordinates: convertPosition(option.position), //三层数组[[[0,0],[0,0]]]
169
+ coordinates: convertPosition(this.option.position), //三层数组[[[0,0],[0,0]]]
170
170
  },
171
171
  },
172
172
  ],