xy-map 1.1.13 → 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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "xy-map",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "雄越地图",
5
5
  "main": "xy-map.umd.min.js",
6
6
  "scripts": {
7
7
  "pub": "npm publish"
8
8
  },
9
9
  "keywords": [],
10
- "author": "",
10
+ "author": "hanjing",
11
11
  "license": "ISC"
12
12
  }
package/xy-map.common.js CHANGED
@@ -48283,6 +48283,24 @@ const toGeoJson = (list, type, props = 'position') => {
48283
48283
  return data;
48284
48284
  };
48285
48285
 
48286
+ // 点坐标转geoJson
48287
+ const pointToGeoJson = (position = [0, 0]) => {
48288
+ let pointsData = {
48289
+ id: Date.now().toString(),
48290
+ type: 'Feature',
48291
+ geometry: {
48292
+ type: 'Point',
48293
+ coordinates: position
48294
+ },
48295
+ properties: {}
48296
+ };
48297
+ let data = {
48298
+ type: 'FeatureCollection',
48299
+ features: [pointsData]
48300
+ };
48301
+ return data;
48302
+ };
48303
+
48286
48304
  /**
48287
48305
  * 加载图片
48288
48306
  */
@@ -48453,6 +48471,7 @@ const Point_defaultOptions = {
48453
48471
  },
48454
48472
  click: null
48455
48473
  };
48474
+ let clock = null;
48456
48475
 
48457
48476
  /**
48458
48477
  * 添加点图层
@@ -48493,7 +48512,7 @@ const addLayerPoint = (option, layerId) => {
48493
48512
  }, layerId);
48494
48513
  if (opt.cluster.cluster) {
48495
48514
  let style = opt.cluster.style || {};
48496
- clusterLayer(id, style);
48515
+ clusterLayer(opt, style);
48497
48516
  }
48498
48517
  if (opt.click) {
48499
48518
  mapClick(id, opt.click);
@@ -48522,6 +48541,97 @@ const addLayerPoint = (option, layerId) => {
48522
48541
  }
48523
48542
  };
48524
48543
 
48544
+ /**
48545
+ * 添加闪烁点图层
48546
+ */
48547
+ const addFlashPoint = (option = {
48548
+ id: 'flash',
48549
+ position: [],
48550
+ timer: 3000,
48551
+ // 闪烁时间
48552
+ size: 140,
48553
+ // 大小
48554
+ layerId // 层级
48555
+ }) => {
48556
+ // 点
48557
+ let {
48558
+ map
48559
+ } = package_map;
48560
+ const size = option.size;
48561
+ const pulsingDot = {
48562
+ width: size,
48563
+ height: size,
48564
+ data: new Uint8Array(size * size * 4),
48565
+ onAdd: function () {
48566
+ const canvas = document.createElement('canvas');
48567
+ canvas.width = this.width;
48568
+ canvas.height = this.height;
48569
+ this.context = canvas.getContext('2d');
48570
+ },
48571
+ render: function () {
48572
+ const duration = 1000;
48573
+ const t = performance.now() % duration / duration;
48574
+ const radius = size / 2 * 0.3;
48575
+ const outerRadius = size / 2 * 0.5 * t + radius;
48576
+ const context = this.context;
48577
+
48578
+ // Draw the outer circle.
48579
+ context.clearRect(0, 0, this.width, this.height);
48580
+ context.beginPath();
48581
+ context.arc(this.width / 2, this.height / 2, outerRadius, 0, Math.PI * 2);
48582
+ context.fillStyle = `rgba(255, 255, 255, ${1 - t})`;
48583
+ context.fill();
48584
+
48585
+ // Draw the inner circle.
48586
+ context.beginPath();
48587
+ context.arc(this.width / 2, this.height / 2, radius, 0, Math.PI * 2);
48588
+ context.fillStyle = 'rgba(255, 100, 100, 1)';
48589
+ context.strokeStyle = 'white';
48590
+ context.lineWidth = 2 + 4 * (1 - t);
48591
+ context.fill();
48592
+ context.stroke();
48593
+
48594
+ // Update this image's data with data from the canvas.
48595
+ this.data = context.getImageData(0, 0, this.width, this.height).data;
48596
+ map.triggerRepaint();
48597
+ return true;
48598
+ }
48599
+ };
48600
+
48601
+ // 添加自定义图标
48602
+ const imgId = 'pulsing-dot-' + option.id;
48603
+ if (!map.hasImage(imgId)) {
48604
+ map.addImage(imgId, pulsingDot, {
48605
+ pixelRatio: 2
48606
+ }); // 2倍屏分辨率
48607
+ }
48608
+
48609
+ const opt = {
48610
+ id: option.id,
48611
+ data: option.data,
48612
+ style: {
48613
+ layout: {
48614
+ 'icon-image': imgId
48615
+ },
48616
+ paint: {
48617
+ 'text-opacity': 0
48618
+ }
48619
+ }
48620
+ };
48621
+ if (hasLayer(opt.id)) {
48622
+ setSource(opt.id, opt.data);
48623
+ } else {
48624
+ addDiyPoint(opt, option.layerId);
48625
+ }
48626
+ if (option.timer > 0) {
48627
+ window.clearInterval(clock);
48628
+ clock = window.setInterval(() => {
48629
+ map.removeImage(imgId);
48630
+ window.clearInterval(clock);
48631
+ }, option.timer);
48632
+ }
48633
+ };
48634
+
48525
48635
  /**
48526
48636
  * 添加自定义点图层
48527
48637
  */
@@ -48547,13 +48657,13 @@ const addDiyPoint = (option, layerId) => {
48547
48657
  // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
48548
48658
  'text-anchor': 'top',
48549
48659
  // 图标与锚点的位置关系
48550
- 'icon-allow-overlap': false,
48660
+ 'icon-allow-overlap': true,
48551
48661
  // 是否允许图标重叠
48552
- 'icon-ignore-placement': false,
48662
+ 'icon-ignore-placement': true,
48553
48663
  // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
48554
- 'text-allow-overlap': false,
48664
+ 'text-allow-overlap': true,
48555
48665
  // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
48556
- 'text-ignore-placement': false,
48666
+ 'text-ignore-placement': true,
48557
48667
  // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
48558
48668
  // 'text-max-width': 12, // 文本宽度
48559
48669
  'visibility': 'visible'
@@ -48584,7 +48694,7 @@ const addDiyPoint = (option, layerId) => {
48584
48694
  }, layerId);
48585
48695
  if (opt.cluster.cluster) {
48586
48696
  let style = opt.cluster.style || {};
48587
- clusterLayer(id, style);
48697
+ clusterLayer(opt, style);
48588
48698
  }
48589
48699
  if (opt.click) {
48590
48700
  mapClick(id, opt.click);
@@ -48681,7 +48791,7 @@ const addLayerImagePoint = async (option, layerId) => {
48681
48791
  }
48682
48792
  if (opt.cluster.cluster) {
48683
48793
  let style = opt.cluster.style || {};
48684
- clusterLayer(id, style);
48794
+ clusterLayer(opt, style);
48685
48795
  }
48686
48796
  if (opt.click) {
48687
48797
  mapClick(id, opt.click);
@@ -48726,10 +48836,6 @@ const clusterLayer = (option, style) => {
48726
48836
  map
48727
48837
  } = package_map;
48728
48838
  let id = option.id;
48729
- if (hasLayer(id)) {
48730
- setSource(id, option.data);
48731
- return;
48732
- }
48733
48839
  let layout = style ? style.layout : {};
48734
48840
  let layoutOpt = Object.assign({
48735
48841
  'text-field': '{point_count_abbreviated}',
@@ -48738,8 +48844,10 @@ const clusterLayer = (option, style) => {
48738
48844
  }, layout);
48739
48845
  let paint = style ? style.paint : {};
48740
48846
  let paintOpt = Object.assign({
48741
- 'circle-color': ['step', ['get', 'point_count'], '#51bbd6', 100, '#f1f075', 350, '#f28cb1'],
48742
- 'circle-radius': ['step', ['get', 'point_count'], 20, 100, 30, 750, 40]
48847
+ 'circle-color': ['step', ['get', 'point_count'], 'rgba(110, 204, 57, 0.7)', 20, 'rgba(240, 194, 12, 0.7)', 50, 'rgba(241, 128, 23, 0.7)', 100, 'rgba(241, 23, 23, 0.7)'],
48848
+ 'circle-stroke-color': ['step', ['get', 'point_count'], 'rgba(110, 204, 57, 0.3)', 20, 'rgba(240, 194, 12, 0.3)', 50, 'rgba(241, 128, 23, 0.3)', 100, 'rgba(241, 23, 23, 0.3)'],
48849
+ 'circle-stroke-width': ['step', ['get', 'point_count'], 5, 20, 6, 50, 7, 100, 7],
48850
+ 'circle-radius': ['step', ['get', 'point_count'], 16, 20, 18, 50, 20, 100, 21]
48743
48851
  }, paint);
48744
48852
  map.addLayer({
48745
48853
  id: id + '-clusters',
@@ -48753,9 +48861,12 @@ const clusterLayer = (option, style) => {
48753
48861
  type: 'symbol',
48754
48862
  source: option.id,
48755
48863
  filter: ['has', 'point_count'],
48756
- layout: layoutOpt
48864
+ layout: layoutOpt,
48865
+ paint: {
48866
+ 'text-color': '#ffffff'
48867
+ }
48757
48868
  });
48758
- mapClick(id + 'clusters', e => {
48869
+ mapClick(id + '-clusters', e => {
48759
48870
  package_map.zoom('in', e.position);
48760
48871
  });
48761
48872
  };
@@ -59401,6 +59512,7 @@ const mapDraw = {
59401
59512
  addLayerLineAnimation: addLayerLineAnimation,
59402
59513
  addLayerPoint: addLayerPoint,
59403
59514
  addDiyPoint: addDiyPoint,
59515
+ addFlashPoint: addFlashPoint,
59404
59516
  addLayerImagePoint: addLayerImagePoint,
59405
59517
  addLayerPolygon: addLayerPolygon,
59406
59518
  addLayerCircle: addLayerCircle,
@@ -59411,6 +59523,7 @@ const mapDraw = {
59411
59523
  // 地图工具
59412
59524
  const mapTools = {
59413
59525
  toGeoJson: toGeoJson,
59526
+ pointToGeoJson: pointToGeoJson,
59414
59527
  loadImage: loadImage,
59415
59528
  ranging: ranging,
59416
59529
  drawArea: drawArea,
package/xy-map.umd.js CHANGED
@@ -48301,6 +48301,24 @@ const toGeoJson = (list, type, props = 'position') => {
48301
48301
  return data;
48302
48302
  };
48303
48303
 
48304
+ // 点坐标转geoJson
48305
+ const pointToGeoJson = (position = [0, 0]) => {
48306
+ let pointsData = {
48307
+ id: Date.now().toString(),
48308
+ type: 'Feature',
48309
+ geometry: {
48310
+ type: 'Point',
48311
+ coordinates: position
48312
+ },
48313
+ properties: {}
48314
+ };
48315
+ let data = {
48316
+ type: 'FeatureCollection',
48317
+ features: [pointsData]
48318
+ };
48319
+ return data;
48320
+ };
48321
+
48304
48322
  /**
48305
48323
  * 加载图片
48306
48324
  */
@@ -48471,6 +48489,7 @@ const Point_defaultOptions = {
48471
48489
  },
48472
48490
  click: null
48473
48491
  };
48492
+ let clock = null;
48474
48493
 
48475
48494
  /**
48476
48495
  * 添加点图层
@@ -48511,7 +48530,7 @@ const addLayerPoint = (option, layerId) => {
48511
48530
  }, layerId);
48512
48531
  if (opt.cluster.cluster) {
48513
48532
  let style = opt.cluster.style || {};
48514
- clusterLayer(id, style);
48533
+ clusterLayer(opt, style);
48515
48534
  }
48516
48535
  if (opt.click) {
48517
48536
  mapClick(id, opt.click);
@@ -48540,6 +48559,97 @@ const addLayerPoint = (option, layerId) => {
48540
48559
  }
48541
48560
  };
48542
48561
 
48562
+ /**
48563
+ * 添加闪烁点图层
48564
+ */
48565
+ const addFlashPoint = (option = {
48566
+ id: 'flash',
48567
+ position: [],
48568
+ timer: 3000,
48569
+ // 闪烁时间
48570
+ size: 140,
48571
+ // 大小
48572
+ layerId // 层级
48573
+ }) => {
48574
+ // 点
48575
+ let {
48576
+ map
48577
+ } = package_map;
48578
+ const size = option.size;
48579
+ const pulsingDot = {
48580
+ width: size,
48581
+ height: size,
48582
+ data: new Uint8Array(size * size * 4),
48583
+ onAdd: function () {
48584
+ const canvas = document.createElement('canvas');
48585
+ canvas.width = this.width;
48586
+ canvas.height = this.height;
48587
+ this.context = canvas.getContext('2d');
48588
+ },
48589
+ render: function () {
48590
+ const duration = 1000;
48591
+ const t = performance.now() % duration / duration;
48592
+ const radius = size / 2 * 0.3;
48593
+ const outerRadius = size / 2 * 0.5 * t + radius;
48594
+ const context = this.context;
48595
+
48596
+ // Draw the outer circle.
48597
+ context.clearRect(0, 0, this.width, this.height);
48598
+ context.beginPath();
48599
+ context.arc(this.width / 2, this.height / 2, outerRadius, 0, Math.PI * 2);
48600
+ context.fillStyle = `rgba(255, 255, 255, ${1 - t})`;
48601
+ context.fill();
48602
+
48603
+ // Draw the inner circle.
48604
+ context.beginPath();
48605
+ context.arc(this.width / 2, this.height / 2, radius, 0, Math.PI * 2);
48606
+ context.fillStyle = 'rgba(255, 100, 100, 1)';
48607
+ context.strokeStyle = 'white';
48608
+ context.lineWidth = 2 + 4 * (1 - t);
48609
+ context.fill();
48610
+ context.stroke();
48611
+
48612
+ // Update this image's data with data from the canvas.
48613
+ this.data = context.getImageData(0, 0, this.width, this.height).data;
48614
+ map.triggerRepaint();
48615
+ return true;
48616
+ }
48617
+ };
48618
+
48619
+ // 添加自定义图标
48620
+ const imgId = 'pulsing-dot-' + option.id;
48621
+ if (!map.hasImage(imgId)) {
48622
+ map.addImage(imgId, pulsingDot, {
48623
+ pixelRatio: 2
48624
+ }); // 2倍屏分辨率
48625
+ }
48626
+
48627
+ const opt = {
48628
+ id: option.id,
48629
+ data: option.data,
48630
+ style: {
48631
+ layout: {
48632
+ 'icon-image': imgId
48633
+ },
48634
+ paint: {
48635
+ 'text-opacity': 0
48636
+ }
48637
+ }
48638
+ };
48639
+ if (hasLayer(opt.id)) {
48640
+ setSource(opt.id, opt.data);
48641
+ } else {
48642
+ addDiyPoint(opt, option.layerId);
48643
+ }
48644
+ if (option.timer > 0) {
48645
+ window.clearInterval(clock);
48646
+ clock = window.setInterval(() => {
48647
+ map.removeImage(imgId);
48648
+ window.clearInterval(clock);
48649
+ }, option.timer);
48650
+ }
48651
+ };
48652
+
48543
48653
  /**
48544
48654
  * 添加自定义点图层
48545
48655
  */
@@ -48565,13 +48675,13 @@ const addDiyPoint = (option, layerId) => {
48565
48675
  // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
48566
48676
  'text-anchor': 'top',
48567
48677
  // 图标与锚点的位置关系
48568
- 'icon-allow-overlap': false,
48678
+ 'icon-allow-overlap': true,
48569
48679
  // 是否允许图标重叠
48570
- 'icon-ignore-placement': false,
48680
+ 'icon-ignore-placement': true,
48571
48681
  // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
48572
- 'text-allow-overlap': false,
48682
+ 'text-allow-overlap': true,
48573
48683
  // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
48574
- 'text-ignore-placement': false,
48684
+ 'text-ignore-placement': true,
48575
48685
  // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
48576
48686
  // 'text-max-width': 12, // 文本宽度
48577
48687
  'visibility': 'visible'
@@ -48602,7 +48712,7 @@ const addDiyPoint = (option, layerId) => {
48602
48712
  }, layerId);
48603
48713
  if (opt.cluster.cluster) {
48604
48714
  let style = opt.cluster.style || {};
48605
- clusterLayer(id, style);
48715
+ clusterLayer(opt, style);
48606
48716
  }
48607
48717
  if (opt.click) {
48608
48718
  mapClick(id, opt.click);
@@ -48699,7 +48809,7 @@ const addLayerImagePoint = async (option, layerId) => {
48699
48809
  }
48700
48810
  if (opt.cluster.cluster) {
48701
48811
  let style = opt.cluster.style || {};
48702
- clusterLayer(id, style);
48812
+ clusterLayer(opt, style);
48703
48813
  }
48704
48814
  if (opt.click) {
48705
48815
  mapClick(id, opt.click);
@@ -48744,10 +48854,6 @@ const clusterLayer = (option, style) => {
48744
48854
  map
48745
48855
  } = package_map;
48746
48856
  let id = option.id;
48747
- if (hasLayer(id)) {
48748
- setSource(id, option.data);
48749
- return;
48750
- }
48751
48857
  let layout = style ? style.layout : {};
48752
48858
  let layoutOpt = Object.assign({
48753
48859
  'text-field': '{point_count_abbreviated}',
@@ -48756,8 +48862,10 @@ const clusterLayer = (option, style) => {
48756
48862
  }, layout);
48757
48863
  let paint = style ? style.paint : {};
48758
48864
  let paintOpt = Object.assign({
48759
- 'circle-color': ['step', ['get', 'point_count'], '#51bbd6', 100, '#f1f075', 350, '#f28cb1'],
48760
- 'circle-radius': ['step', ['get', 'point_count'], 20, 100, 30, 750, 40]
48865
+ 'circle-color': ['step', ['get', 'point_count'], 'rgba(110, 204, 57, 0.7)', 20, 'rgba(240, 194, 12, 0.7)', 50, 'rgba(241, 128, 23, 0.7)', 100, 'rgba(241, 23, 23, 0.7)'],
48866
+ 'circle-stroke-color': ['step', ['get', 'point_count'], 'rgba(110, 204, 57, 0.3)', 20, 'rgba(240, 194, 12, 0.3)', 50, 'rgba(241, 128, 23, 0.3)', 100, 'rgba(241, 23, 23, 0.3)'],
48867
+ 'circle-stroke-width': ['step', ['get', 'point_count'], 5, 20, 6, 50, 7, 100, 7],
48868
+ 'circle-radius': ['step', ['get', 'point_count'], 16, 20, 18, 50, 20, 100, 21]
48761
48869
  }, paint);
48762
48870
  map.addLayer({
48763
48871
  id: id + '-clusters',
@@ -48771,9 +48879,12 @@ const clusterLayer = (option, style) => {
48771
48879
  type: 'symbol',
48772
48880
  source: option.id,
48773
48881
  filter: ['has', 'point_count'],
48774
- layout: layoutOpt
48882
+ layout: layoutOpt,
48883
+ paint: {
48884
+ 'text-color': '#ffffff'
48885
+ }
48775
48886
  });
48776
- mapClick(id + 'clusters', e => {
48887
+ mapClick(id + '-clusters', e => {
48777
48888
  package_map.zoom('in', e.position);
48778
48889
  });
48779
48890
  };
@@ -59419,6 +59530,7 @@ const mapDraw = {
59419
59530
  addLayerLineAnimation: addLayerLineAnimation,
59420
59531
  addLayerPoint: addLayerPoint,
59421
59532
  addDiyPoint: addDiyPoint,
59533
+ addFlashPoint: addFlashPoint,
59422
59534
  addLayerImagePoint: addLayerImagePoint,
59423
59535
  addLayerPolygon: addLayerPolygon,
59424
59536
  addLayerCircle: addLayerCircle,
@@ -59429,6 +59541,7 @@ const mapDraw = {
59429
59541
  // 地图工具
59430
59542
  const mapTools = {
59431
59543
  toGeoJson: toGeoJson,
59544
+ pointToGeoJson: pointToGeoJson,
59432
59545
  loadImage: loadImage,
59433
59546
  ranging: ranging,
59434
59547
  drawArea: drawArea,