xy-map 1.1.14 → 1.1.16

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.14",
3
+ "version": "1.1.16",
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
  * 添加点图层
@@ -48522,6 +48541,96 @@ const addLayerPoint = (option, layerId) => {
48522
48541
  }
48523
48542
  };
48524
48543
 
48544
+ /**
48545
+ * 添加闪烁点图层
48546
+ */
48547
+ const addFlashPoint = (option = {
48548
+ id: 'flash',
48549
+ data: [],
48550
+ timer: 3000,
48551
+ // 闪烁时间
48552
+ size: 140 // 大小
48553
+ }, layerId) => {
48554
+ // 点
48555
+
48556
+ let {
48557
+ map
48558
+ } = package_map;
48559
+ const size = option.size;
48560
+ const pulsingDot = {
48561
+ width: size,
48562
+ height: size,
48563
+ data: new Uint8Array(size * size * 4),
48564
+ onAdd: function () {
48565
+ const canvas = document.createElement('canvas');
48566
+ canvas.width = this.width;
48567
+ canvas.height = this.height;
48568
+ this.context = canvas.getContext('2d');
48569
+ },
48570
+ render: function () {
48571
+ const duration = 1000;
48572
+ const t = performance.now() % duration / duration;
48573
+ const radius = size / 2 * 0.3;
48574
+ const outerRadius = size / 2 * 0.5 * t + radius;
48575
+ const context = this.context;
48576
+
48577
+ // Draw the outer circle.
48578
+ context.clearRect(0, 0, this.width, this.height);
48579
+ context.beginPath();
48580
+ context.arc(this.width / 2, this.height / 2, outerRadius, 0, Math.PI * 2);
48581
+ context.fillStyle = `rgba(255, 255, 255, ${1 - t})`;
48582
+ context.fill();
48583
+
48584
+ // Draw the inner circle.
48585
+ context.beginPath();
48586
+ context.arc(this.width / 2, this.height / 2, radius, 0, Math.PI * 2);
48587
+ context.fillStyle = 'rgba(255, 100, 100, 1)';
48588
+ context.strokeStyle = 'white';
48589
+ context.lineWidth = 2 + 4 * (1 - t);
48590
+ context.fill();
48591
+ context.stroke();
48592
+
48593
+ // Update this image's data with data from the canvas.
48594
+ this.data = context.getImageData(0, 0, this.width, this.height).data;
48595
+ map.triggerRepaint();
48596
+ return true;
48597
+ }
48598
+ };
48599
+
48600
+ // 添加自定义图标
48601
+ const imgId = 'pulsing-dot-' + option.id;
48602
+ if (!map.hasImage(imgId)) {
48603
+ map.addImage(imgId, pulsingDot, {
48604
+ pixelRatio: 2
48605
+ }); // 2倍屏分辨率
48606
+ }
48607
+
48608
+ const opt = {
48609
+ id: option.id,
48610
+ data: option.data,
48611
+ style: {
48612
+ layout: {
48613
+ 'icon-image': imgId
48614
+ },
48615
+ paint: {
48616
+ 'text-opacity': 0
48617
+ }
48618
+ }
48619
+ };
48620
+ if (hasLayer(opt.id)) {
48621
+ setSource(opt.id, opt.data);
48622
+ } else {
48623
+ addDiyPoint(opt, layerId);
48624
+ }
48625
+ if (option.timer > 0) {
48626
+ window.clearInterval(clock);
48627
+ clock = window.setInterval(() => {
48628
+ map.removeImage(imgId);
48629
+ window.clearInterval(clock);
48630
+ }, option.timer);
48631
+ }
48632
+ };
48633
+
48525
48634
  /**
48526
48635
  * 添加自定义点图层
48527
48636
  */
@@ -48547,13 +48656,13 @@ const addDiyPoint = (option, layerId) => {
48547
48656
  // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
48548
48657
  'text-anchor': 'top',
48549
48658
  // 图标与锚点的位置关系
48550
- 'icon-allow-overlap': false,
48659
+ 'icon-allow-overlap': true,
48551
48660
  // 是否允许图标重叠
48552
- 'icon-ignore-placement': false,
48661
+ 'icon-ignore-placement': true,
48553
48662
  // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
48554
- 'text-allow-overlap': false,
48663
+ 'text-allow-overlap': true,
48555
48664
  // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
48556
- 'text-ignore-placement': false,
48665
+ 'text-ignore-placement': true,
48557
48666
  // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
48558
48667
  // 'text-max-width': 12, // 文本宽度
48559
48668
  'visibility': 'visible'
@@ -59402,6 +59511,7 @@ const mapDraw = {
59402
59511
  addLayerLineAnimation: addLayerLineAnimation,
59403
59512
  addLayerPoint: addLayerPoint,
59404
59513
  addDiyPoint: addDiyPoint,
59514
+ addFlashPoint: addFlashPoint,
59405
59515
  addLayerImagePoint: addLayerImagePoint,
59406
59516
  addLayerPolygon: addLayerPolygon,
59407
59517
  addLayerCircle: addLayerCircle,
@@ -59412,6 +59522,7 @@ const mapDraw = {
59412
59522
  // 地图工具
59413
59523
  const mapTools = {
59414
59524
  toGeoJson: toGeoJson,
59525
+ pointToGeoJson: pointToGeoJson,
59415
59526
  loadImage: loadImage,
59416
59527
  ranging: ranging,
59417
59528
  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
  * 添加点图层
@@ -48540,6 +48559,96 @@ const addLayerPoint = (option, layerId) => {
48540
48559
  }
48541
48560
  };
48542
48561
 
48562
+ /**
48563
+ * 添加闪烁点图层
48564
+ */
48565
+ const addFlashPoint = (option = {
48566
+ id: 'flash',
48567
+ data: [],
48568
+ timer: 3000,
48569
+ // 闪烁时间
48570
+ size: 140 // 大小
48571
+ }, layerId) => {
48572
+ // 点
48573
+
48574
+ let {
48575
+ map
48576
+ } = package_map;
48577
+ const size = option.size;
48578
+ const pulsingDot = {
48579
+ width: size,
48580
+ height: size,
48581
+ data: new Uint8Array(size * size * 4),
48582
+ onAdd: function () {
48583
+ const canvas = document.createElement('canvas');
48584
+ canvas.width = this.width;
48585
+ canvas.height = this.height;
48586
+ this.context = canvas.getContext('2d');
48587
+ },
48588
+ render: function () {
48589
+ const duration = 1000;
48590
+ const t = performance.now() % duration / duration;
48591
+ const radius = size / 2 * 0.3;
48592
+ const outerRadius = size / 2 * 0.5 * t + radius;
48593
+ const context = this.context;
48594
+
48595
+ // Draw the outer circle.
48596
+ context.clearRect(0, 0, this.width, this.height);
48597
+ context.beginPath();
48598
+ context.arc(this.width / 2, this.height / 2, outerRadius, 0, Math.PI * 2);
48599
+ context.fillStyle = `rgba(255, 255, 255, ${1 - t})`;
48600
+ context.fill();
48601
+
48602
+ // Draw the inner circle.
48603
+ context.beginPath();
48604
+ context.arc(this.width / 2, this.height / 2, radius, 0, Math.PI * 2);
48605
+ context.fillStyle = 'rgba(255, 100, 100, 1)';
48606
+ context.strokeStyle = 'white';
48607
+ context.lineWidth = 2 + 4 * (1 - t);
48608
+ context.fill();
48609
+ context.stroke();
48610
+
48611
+ // Update this image's data with data from the canvas.
48612
+ this.data = context.getImageData(0, 0, this.width, this.height).data;
48613
+ map.triggerRepaint();
48614
+ return true;
48615
+ }
48616
+ };
48617
+
48618
+ // 添加自定义图标
48619
+ const imgId = 'pulsing-dot-' + option.id;
48620
+ if (!map.hasImage(imgId)) {
48621
+ map.addImage(imgId, pulsingDot, {
48622
+ pixelRatio: 2
48623
+ }); // 2倍屏分辨率
48624
+ }
48625
+
48626
+ const opt = {
48627
+ id: option.id,
48628
+ data: option.data,
48629
+ style: {
48630
+ layout: {
48631
+ 'icon-image': imgId
48632
+ },
48633
+ paint: {
48634
+ 'text-opacity': 0
48635
+ }
48636
+ }
48637
+ };
48638
+ if (hasLayer(opt.id)) {
48639
+ setSource(opt.id, opt.data);
48640
+ } else {
48641
+ addDiyPoint(opt, layerId);
48642
+ }
48643
+ if (option.timer > 0) {
48644
+ window.clearInterval(clock);
48645
+ clock = window.setInterval(() => {
48646
+ map.removeImage(imgId);
48647
+ window.clearInterval(clock);
48648
+ }, option.timer);
48649
+ }
48650
+ };
48651
+
48543
48652
  /**
48544
48653
  * 添加自定义点图层
48545
48654
  */
@@ -48565,13 +48674,13 @@ const addDiyPoint = (option, layerId) => {
48565
48674
  // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
48566
48675
  'text-anchor': 'top',
48567
48676
  // 图标与锚点的位置关系
48568
- 'icon-allow-overlap': false,
48677
+ 'icon-allow-overlap': true,
48569
48678
  // 是否允许图标重叠
48570
- 'icon-ignore-placement': false,
48679
+ 'icon-ignore-placement': true,
48571
48680
  // 是否忽略图标位置(可选,默认值为 false。当值为 true 时,其他符号即使与此图标触碰也会显示)
48572
- 'text-allow-overlap': false,
48681
+ 'text-allow-overlap': true,
48573
48682
  // 是否允许文本重叠(可选,默认值为 false。当值为 true 时,文本即使和其他符号触碰也会显示)
48574
- 'text-ignore-placement': false,
48683
+ 'text-ignore-placement': true,
48575
48684
  // 是否忽略文本位置(可选,默认值为 false。当值为 true 时,其他符号即使与此文本触碰也会显示)
48576
48685
  // 'text-max-width': 12, // 文本宽度
48577
48686
  'visibility': 'visible'
@@ -59420,6 +59529,7 @@ const mapDraw = {
59420
59529
  addLayerLineAnimation: addLayerLineAnimation,
59421
59530
  addLayerPoint: addLayerPoint,
59422
59531
  addDiyPoint: addDiyPoint,
59532
+ addFlashPoint: addFlashPoint,
59423
59533
  addLayerImagePoint: addLayerImagePoint,
59424
59534
  addLayerPolygon: addLayerPolygon,
59425
59535
  addLayerCircle: addLayerCircle,
@@ -59430,6 +59540,7 @@ const mapDraw = {
59430
59540
  // 地图工具
59431
59541
  const mapTools = {
59432
59542
  toGeoJson: toGeoJson,
59543
+ pointToGeoJson: pointToGeoJson,
59433
59544
  loadImage: loadImage,
59434
59545
  ranging: ranging,
59435
59546
  drawArea: drawArea,