my-openlayer 2.4.10 → 2.5.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 (119) hide show
  1. package/CHANGELOG.md +167 -265
  2. package/MyOl.d.ts +9 -9
  3. package/MyOl.js +17 -16
  4. package/README.md +217 -156
  5. package/core/line/Line.d.ts +40 -0
  6. package/core/line/Line.js +144 -0
  7. package/core/line/LineFeatureFactory.d.ts +17 -0
  8. package/core/line/LineFeatureFactory.js +75 -0
  9. package/core/line/LineFlowAnimator.d.ts +53 -0
  10. package/core/line/LineFlowAnimator.js +297 -0
  11. package/core/line/LineStyleFactory.d.ts +43 -0
  12. package/core/line/LineStyleFactory.js +135 -0
  13. package/core/{RiverLayerManager.d.ts → line/RiverLayerManager.d.ts} +2 -2
  14. package/core/{RiverLayerManager.js → line/RiverLayerManager.js} +3 -5
  15. package/core/line/index.d.ts +6 -0
  16. package/core/line/index.js +5 -0
  17. package/core/{ConfigManager.d.ts → map/ConfigManager.d.ts} +25 -1
  18. package/core/{ConfigManager.js → map/ConfigManager.js} +22 -1
  19. package/core/{EventManager.d.ts → map/EventManager.d.ts} +1 -1
  20. package/core/{EventManager.js → map/EventManager.js} +2 -2
  21. package/core/{MapBaseLayers.d.ts → map/MapBaseLayers.d.ts} +1 -1
  22. package/core/{MapBaseLayers.js → map/MapBaseLayers.js} +10 -12
  23. package/core/{MapTools.d.ts → map/MapTools.d.ts} +5 -2
  24. package/core/{MapTools.js → map/MapTools.js} +11 -5
  25. package/core/{MeasureHandler.d.ts → map/MeasureHandler.d.ts} +1 -1
  26. package/core/{MeasureHandler.js → map/MeasureHandler.js} +41 -41
  27. package/core/map/index.d.ts +5 -0
  28. package/core/map/index.js +5 -0
  29. package/core/{Point.d.ts → point/Point.d.ts} +13 -4
  30. package/core/{Point.js → point/Point.js} +24 -112
  31. package/core/point/PointClusterLayer.d.ts +10 -0
  32. package/core/point/PointClusterLayer.js +52 -0
  33. package/core/point/PointOverlay.d.ts +13 -0
  34. package/core/point/PointOverlay.js +57 -0
  35. package/core/point/PointPulseLayer.d.ts +13 -0
  36. package/core/point/PointPulseLayer.js +207 -0
  37. package/core/point/index.d.ts +4 -0
  38. package/core/point/index.js +4 -0
  39. package/core/{Polygon.d.ts → polygon/Polygon.d.ts} +4 -50
  40. package/core/polygon/Polygon.js +248 -0
  41. package/core/polygon/PolygonHeatmapLayer.d.ts +11 -0
  42. package/core/polygon/PolygonHeatmapLayer.js +40 -0
  43. package/core/polygon/PolygonImageLayer.d.ts +9 -0
  44. package/core/polygon/PolygonImageLayer.js +61 -0
  45. package/core/polygon/PolygonMaskLayer.d.ts +20 -0
  46. package/core/polygon/PolygonMaskLayer.js +107 -0
  47. package/core/polygon/PolygonStyleFactory.d.ts +12 -0
  48. package/core/polygon/PolygonStyleFactory.js +100 -0
  49. package/core/polygon/index.d.ts +5 -0
  50. package/core/polygon/index.js +5 -0
  51. package/core/{SelectHandler.d.ts → select/SelectHandler.d.ts} +2 -3
  52. package/core/{SelectHandler.js → select/SelectHandler.js} +4 -4
  53. package/core/select/index.d.ts +1 -0
  54. package/core/select/index.js +1 -0
  55. package/core/{VueTemplatePoint.d.ts → vue-template-point/VueTemplatePoint.d.ts} +1 -1
  56. package/core/{VueTemplatePoint.js → vue-template-point/VueTemplatePoint.js} +4 -4
  57. package/core/vue-template-point/index.d.ts +1 -0
  58. package/core/vue-template-point/index.js +1 -0
  59. package/docs/.vitepress/config.mts +57 -57
  60. package/docs/ConfigManager.md +71 -71
  61. package/docs/ErrorHandler.md +106 -106
  62. package/docs/EventManager.md +142 -142
  63. package/docs/Line.md +215 -187
  64. package/docs/MapBaseLayers.md +198 -198
  65. package/docs/MapTools.md +172 -172
  66. package/docs/MeasureHandler.md +87 -87
  67. package/docs/MyOl.md +247 -247
  68. package/docs/Point.md +233 -165
  69. package/docs/Polygon.md +241 -241
  70. package/docs/RiverLayerManager.md +187 -187
  71. package/docs/SelectHandler.md +147 -147
  72. package/docs/ValidationUtils.md +83 -83
  73. package/docs/VueTemplatePoint.md +214 -214
  74. package/docs/index.md +79 -78
  75. package/index.d.ts +11 -16
  76. package/index.js +7 -13
  77. package/package.json +11 -1
  78. package/types/base.d.ts +47 -0
  79. package/types/base.js +1 -0
  80. package/types/common.d.ts +59 -0
  81. package/types/common.js +1 -0
  82. package/types/index.d.ts +9 -0
  83. package/types/index.js +1 -0
  84. package/types/line.d.ts +41 -0
  85. package/types/line.js +1 -0
  86. package/types/map.d.ts +77 -0
  87. package/types/map.js +1 -0
  88. package/types/point.d.ts +54 -0
  89. package/types/point.js +1 -0
  90. package/types/polygon.d.ts +8 -0
  91. package/types/polygon.js +1 -0
  92. package/types/select.d.ts +25 -0
  93. package/types/select.js +1 -0
  94. package/types/vue-template-point.d.ts +54 -0
  95. package/{types.js → types/vue-template-point.js} +0 -3
  96. package/utils/ProjectionUtils.d.ts +28 -0
  97. package/utils/ProjectionUtils.js +34 -0
  98. package/utils/ValidationUtils.d.ts +33 -86
  99. package/utils/ValidationUtils.js +60 -165
  100. package/core/DomPoint.d.ts +0 -21
  101. package/core/DomPoint.js +0 -36
  102. package/core/Line.d.ts +0 -49
  103. package/core/Line.js +0 -114
  104. package/core/Polygon.js +0 -646
  105. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  106. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  107. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  108. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js +0 -12542
  109. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js.map +0 -7
  110. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js +0 -9719
  111. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js.map +0 -7
  112. package/docs/.vitepress/cache/deps/package.json +0 -3
  113. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4505
  114. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  115. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  116. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  117. package/docs/.vitepress/cache/deps/vue.js +0 -343
  118. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  119. package/types.d.ts +0 -372
@@ -10,9 +10,9 @@ import { TileWMS } from "ol/source";
10
10
  import WMTSTileGrid from "ol/tilegrid/WMTS";
11
11
  import XYZ from "ol/source/XYZ";
12
12
  import MapTools from "./MapTools";
13
- import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
14
- import { ValidationUtils } from "../utils/ValidationUtils";
15
- import { ConfigManager } from "./ConfigManager";
13
+ import { ErrorHandler, ErrorType } from "../../utils/ErrorHandler";
14
+ import ValidationUtils from "../../utils/ValidationUtils";
15
+ import ConfigManager from "./ConfigManager";
16
16
  const TIANDITU_TYPES = ['vec_c', 'img_c', 'ter_c'];
17
17
  const CUSTOM_LAYER_KEY = '__custom__';
18
18
  /**
@@ -69,20 +69,18 @@ export default class MapBaseLayers {
69
69
  */
70
70
  initializeLayers() {
71
71
  const { layers, token, annotation } = this.options;
72
+ this.layers = {};
73
+ if (token) {
74
+ this.initTiandituLayers();
75
+ }
72
76
  // 初始化底图配置
73
77
  if (Array.isArray(layers)) {
74
- this.layers = { [CUSTOM_LAYER_KEY]: layers };
78
+ this.layers[CUSTOM_LAYER_KEY] = layers;
75
79
  }
76
80
  else if (layers && Object.keys(layers).length > 0) {
77
- this.layers = layers;
78
- }
79
- else if (token) {
80
- // 如果没有提供layers但提供了token,则初始化标准天地图
81
- this.initTiandituLayers();
82
- }
83
- else {
84
- this.layers = {};
81
+ this.layers = { ...this.layers, ...layers };
85
82
  }
83
+ // 如果没有提供layers但提供了token,则初始化标准天地图
86
84
  // 初始化注记配置
87
85
  if (annotation) {
88
86
  this.initAnnotationLayer();
@@ -1,5 +1,5 @@
1
1
  import Map from "ol/Map";
2
- import { MapJSONData } from "../types";
2
+ import { MapJSONData } from "../../types";
3
3
  import VectorLayer from "ol/layer/Vector";
4
4
  import VectorSource from "ol/source/Vector";
5
5
  import BaseLayer from "ol/layer/Base";
@@ -70,7 +70,10 @@ export default class MapTools {
70
70
  * @param duration 动画时长
71
71
  * @returns 定位是否成功
72
72
  */
73
- locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number): boolean;
73
+ locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number, projection?: {
74
+ dataProjection?: string;
75
+ featureProjection?: string;
76
+ }): boolean;
74
77
  /**
75
78
  * 获取地图实例
76
79
  * @returns 地图实例
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  import VectorSource from "ol/source/Vector";
3
3
  import GeoJSON from "ol/format/GeoJSON";
4
- import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
5
- import { ValidationUtils } from "../utils/ValidationUtils";
4
+ import { ErrorHandler, ErrorType } from "../../utils/ErrorHandler";
5
+ import ValidationUtils from "../../utils/ValidationUtils";
6
+ import ProjectionUtils from "../../utils/ProjectionUtils";
6
7
  import { createEmpty, extend, isEmpty } from "ol/extent";
7
8
  /**
8
9
  * 地图工具类
@@ -181,15 +182,20 @@ class MapTools {
181
182
  * @param duration 动画时长
182
183
  * @returns 定位是否成功
183
184
  */
184
- locationAction(lgtd, lttd, zoom = 20, duration = 3000) {
185
+ locationAction(lgtd, lttd, zoom = 20, duration = 3000, projection) {
185
186
  if (!this.map) {
186
187
  throw new Error('Map instance is not available');
187
188
  }
188
- if (!ValidationUtils.validateLngLat(lgtd, lttd)) {
189
+ const hasProjection = !!projection?.dataProjection || !!projection?.featureProjection;
190
+ const isValidCoordinate = hasProjection
191
+ ? typeof lgtd === 'number' && typeof lttd === 'number' && Number.isFinite(lgtd) && Number.isFinite(lttd)
192
+ : ValidationUtils.validateLngLat(lgtd, lttd);
193
+ if (!isValidCoordinate) {
189
194
  return false;
190
195
  }
191
196
  try {
192
- this.map.getView().animate({ center: [lgtd, lttd], zoom, duration });
197
+ const center = ProjectionUtils.transformCoordinate([lgtd, lttd], projection);
198
+ this.map.getView().animate({ center, zoom, duration });
193
199
  return true;
194
200
  }
195
201
  catch (error) {
@@ -1,5 +1,5 @@
1
1
  import Map from "ol/Map";
2
- import { MeasureHandlerType } from "../types";
2
+ import { MeasureHandlerType } from "../../types";
3
3
  /**
4
4
  * 测量工具处理类
5
5
  * 提供距离和面积测量功能
@@ -6,8 +6,8 @@ import { Vector as VectorSource } from 'ol/source.js';
6
6
  import { Vector as VectorLayer } from 'ol/layer.js';
7
7
  import { getArea, getLength } from 'ol/sphere.js';
8
8
  import { unByKey } from 'ol/Observable.js';
9
- import { ValidationUtils } from '../utils/ValidationUtils';
10
- import { ErrorHandler } from '../utils/ErrorHandler';
9
+ import ValidationUtils from '../../utils/ValidationUtils';
10
+ import { ErrorHandler } from '../../utils/ErrorHandler';
11
11
  /**
12
12
  * 测量工具处理类
13
13
  * 提供距离和面积测量功能
@@ -322,45 +322,45 @@ export default class MeasureHandler {
322
322
  }
323
323
  const style = document.createElement('style');
324
324
  style.id = styleId;
325
- style.innerHTML = `
326
- .ol-tooltip {
327
- position: relative;
328
- background: rgba(0, 0, 0, 0.5);
329
- border-radius: 4px;
330
- color: white;
331
- padding: 4px 8px;
332
- opacity: 0.7;
333
- white-space: nowrap;
334
- font-size: 12px;
335
- cursor: default;
336
- user-select: none;
337
- border: 1px solid #cccccc;
338
- text-shadow: 1px 1px 2px #000;
339
- }
340
- .ol-tooltip-measure {
341
- opacity: 1;
342
- font-weight: bold;
343
- }
344
- .ol-tooltip-static {
345
- background-color: #ffcc33;
346
- color: black;
347
- border: 1px solid white;
348
- text-shadow: none;
349
- }
350
- .ol-tooltip-measure:before,
351
- .ol-tooltip-static:before {
352
- border-top: 6px solid rgba(0, 0, 0, 0.5);
353
- border-right: 6px solid transparent;
354
- border-left: 6px solid transparent;
355
- content: "";
356
- position: absolute;
357
- bottom: -6px;
358
- margin-left: -7px;
359
- left: 50%;
360
- }
361
- .ol-tooltip-static:before {
362
- border-top-color: #ffcc33;
363
- }
325
+ style.innerHTML = `
326
+ .ol-tooltip {
327
+ position: relative;
328
+ background: rgba(0, 0, 0, 0.5);
329
+ border-radius: 4px;
330
+ color: white;
331
+ padding: 4px 8px;
332
+ opacity: 0.7;
333
+ white-space: nowrap;
334
+ font-size: 12px;
335
+ cursor: default;
336
+ user-select: none;
337
+ border: 1px solid #cccccc;
338
+ text-shadow: 1px 1px 2px #000;
339
+ }
340
+ .ol-tooltip-measure {
341
+ opacity: 1;
342
+ font-weight: bold;
343
+ }
344
+ .ol-tooltip-static {
345
+ background-color: #ffcc33;
346
+ color: black;
347
+ border: 1px solid white;
348
+ text-shadow: none;
349
+ }
350
+ .ol-tooltip-measure:before,
351
+ .ol-tooltip-static:before {
352
+ border-top: 6px solid rgba(0, 0, 0, 0.5);
353
+ border-right: 6px solid transparent;
354
+ border-left: 6px solid transparent;
355
+ content: "";
356
+ position: absolute;
357
+ bottom: -6px;
358
+ margin-left: -7px;
359
+ left: 50%;
360
+ }
361
+ .ol-tooltip-static:before {
362
+ border-top-color: #ffcc33;
363
+ }
364
364
  `;
365
365
  document.head.appendChild(style);
366
366
  }
@@ -0,0 +1,5 @@
1
+ export { default as MapTools } from './MapTools';
2
+ export { default as MapBaseLayers } from './MapBaseLayers';
3
+ export { default as MeasureHandler } from './MeasureHandler';
4
+ export { default as EventManager } from './EventManager';
5
+ export { default as ConfigManager } from './ConfigManager';
@@ -0,0 +1,5 @@
1
+ export { default as MapTools } from './MapTools';
2
+ export { default as MapBaseLayers } from './MapBaseLayers';
3
+ export { default as MeasureHandler } from './MeasureHandler';
4
+ export { default as EventManager } from './EventManager';
5
+ export { default as ConfigManager } from './ConfigManager';
@@ -1,8 +1,7 @@
1
1
  import Map from "ol/Map";
2
- import Overlay from 'ol/Overlay';
3
2
  import VectorLayer from "ol/layer/Vector";
4
3
  import VectorSource from "ol/source/Vector";
5
- import { PointOptions, ClusterOptions, PointData, VueTemplatePointInstance, TwinkleItem } from '../types';
4
+ import { PointOptions, ClusterOptions, PointData, VueTemplatePointInstance, TwinkleItem, PulsePointOptions, PulsePointLayerHandle } from '../../types';
6
5
  export default class Point {
7
6
  private map;
8
7
  constructor(map: Map);
@@ -55,13 +54,20 @@ export default class Point {
55
54
  */
56
55
  addPoint(pointData: PointData[], options: PointOptions): VectorLayer<VectorSource> | null;
57
56
  addClusterPoint(pointData: PointData[], options: ClusterOptions): VectorLayer<VectorSource> | null;
57
+ /**
58
+ * 添加高性能闪烁点图层。
59
+ *
60
+ * 与 addDomPoint 不同,该方法使用 VectorLayer 批量渲染点位,并通过单个
61
+ * requestAnimationFrame 驱动闪烁圈,适合村庄预警等大量点位场景。
62
+ */
63
+ addPulsePointLayer(pointData: PointData[], options: PulsePointOptions): PulsePointLayerHandle | null;
58
64
  /**
59
65
  * 添加闪烁点
60
66
  * @param twinkleList 闪烁点数据
61
67
  * @param callback
62
68
  */
63
69
  addDomPoint(twinkleList: TwinkleItem[], callback?: Function): {
64
- anchors: Overlay[];
70
+ anchors: import('ol/Overlay').default[];
65
71
  remove: () => void;
66
72
  setVisible: (visible: boolean) => void;
67
73
  };
@@ -90,5 +96,8 @@ export default class Point {
90
96
  * @param zoom 缩放级别
91
97
  * @param duration 动画时长
92
98
  */
93
- locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number): boolean;
99
+ locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number, projection?: {
100
+ dataProjection?: string;
101
+ featureProjection?: string;
102
+ }): boolean;
94
103
  }
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
- import Overlay from 'ol/Overlay';
3
2
  import Feature from "ol/Feature";
4
3
  import { Point as olPoint } from "ol/geom";
5
4
  import { Text, Style, Fill, Stroke, Icon } from "ol/style";
6
5
  import VectorLayer from "ol/layer/Vector";
7
6
  import VectorSource from "ol/source/Vector";
8
- import { Cluster } from 'ol/source';
9
- import VueTemplatePoint from './VueTemplatePoint';
10
- import { ValidationUtils } from '../utils/ValidationUtils';
11
- import MapTools from './MapTools';
12
- import { ConfigManager } from "./ConfigManager";
7
+ import { VueTemplatePoint } from '../vue-template-point';
8
+ import ValidationUtils from '../../utils/ValidationUtils';
9
+ import ProjectionUtils from '../../utils/ProjectionUtils';
10
+ import { ConfigManager, MapTools } from "../map";
11
+ import PointClusterLayer from './PointClusterLayer';
12
+ import PointOverlay from './PointOverlay';
13
+ import PointPulseLayer from './PointPulseLayer';
13
14
  export default class Point {
14
15
  constructor(map) {
15
16
  this.map = map;
@@ -118,7 +119,7 @@ export default class Point {
118
119
  rawData: item,
119
120
  type: options.layerName,
120
121
  layerName: options.layerName,
121
- geometry: new olPoint([item.lgtd, item.lttd])
122
+ geometry: new olPoint(ProjectionUtils.transformCoordinate([item.lgtd, item.lttd], options))
122
123
  });
123
124
  if (options.style) {
124
125
  if (typeof options.style === 'function') {
@@ -147,47 +148,19 @@ export default class Point {
147
148
  if (!ValidationUtils.validatePointData(pointData)) {
148
149
  return null;
149
150
  }
150
- const pointFeatureList = [];
151
- pointData.forEach(item => {
152
- if (!ValidationUtils.validateCoordinates(item)) {
153
- return;
154
- }
155
- const pointFeature = new Feature({
156
- type: options.layerName,
157
- layerName: options.layerName,
158
- geometry: new olPoint([item.lgtd, item.lttd]),
159
- name: options.textKey ? item[options.textKey] : '',
160
- rawData: item,
161
- });
162
- pointFeatureList.push(pointFeature);
163
- });
164
- const source = new VectorSource({
165
- features: pointFeatureList,
166
- });
167
- const clusterSource = new Cluster({
168
- distance: options.distance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.distance, // The distance for clustering in pixels
169
- minDistance: options.minDistance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.minDistance,
170
- source: source,
171
- });
172
- const clusterLayer = new VectorLayer({
173
- layerName: options.layerName,
174
- source: clusterSource,
175
- style: (feature) => {
176
- if (options.style) {
177
- if (typeof options.style === 'function') {
178
- return options.style(feature);
179
- }
180
- else {
181
- return options.style;
182
- }
183
- }
184
- const name = feature.get('features')[0].get('name');
185
- return this.createClusterStyle(options, name);
186
- },
187
- zIndex: options.zIndex || ConfigManager.DEFAULT_CLUSTER_OPTIONS.zIndex,
188
- });
189
- this.configureLayer(clusterLayer, options);
190
- return clusterLayer;
151
+ return PointClusterLayer.create(this.map, pointData, options, this.createClusterStyle.bind(this));
152
+ }
153
+ /**
154
+ * 添加高性能闪烁点图层。
155
+ *
156
+ * addDomPoint 不同,该方法使用 VectorLayer 批量渲染点位,并通过单个
157
+ * requestAnimationFrame 驱动闪烁圈,适合村庄预警等大量点位场景。
158
+ */
159
+ addPulsePointLayer(pointData, options) {
160
+ if (!ValidationUtils.validatePointData(pointData)) {
161
+ return null;
162
+ }
163
+ return PointPulseLayer.create(this.map, pointData, options);
191
164
  }
192
165
  // // 在流域中心添加闪烁点位
193
166
  // addTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: MapJSONData, options?: PolygonOptions) {
@@ -260,68 +233,7 @@ export default class Point {
260
233
  * @param callback
261
234
  */
262
235
  addDomPoint(twinkleList, callback) {
263
- let anchors = [];
264
- twinkleList.forEach(twinkleItem => {
265
- let element;
266
- // 创建或获取DOM元素
267
- if (twinkleItem.element) {
268
- if (typeof twinkleItem.element === 'function') {
269
- element = twinkleItem.element(twinkleItem);
270
- }
271
- else {
272
- element = twinkleItem.element;
273
- }
274
- // 如果有className,追加到自定义元素
275
- if (twinkleItem.className) {
276
- const classes = twinkleItem.className.split(/\s+/).filter(Boolean);
277
- if (classes.length > 0) {
278
- element.classList.add(...classes);
279
- }
280
- }
281
- }
282
- else {
283
- element = document.createElement('div');
284
- element.className = twinkleItem.className || '';
285
- }
286
- // 添加点击事件
287
- if (callback) {
288
- element.addEventListener('click', () => {
289
- callback(twinkleItem);
290
- });
291
- }
292
- // 创建一个覆盖物
293
- const anchor = new Overlay({
294
- element: element,
295
- positioning: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.positioning,
296
- stopEvent: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.stopEvent // 允许事件穿透,但我们在上面阻止了冒泡
297
- });
298
- // 关键的一点,需要设置附加到地图上的位置
299
- anchor.setPosition([twinkleItem.lgtd, twinkleItem.lttd]);
300
- // 然后添加到map上
301
- this.map.addOverlay(anchor);
302
- anchors.push(anchor);
303
- });
304
- return {
305
- anchors,
306
- remove: () => {
307
- anchors.forEach(anchor => {
308
- const element = anchor.getElement();
309
- if (element) {
310
- element.remove();
311
- }
312
- this.map.removeOverlay(anchor);
313
- });
314
- anchors = [];
315
- },
316
- setVisible: (visible) => {
317
- anchors.forEach(anchor => {
318
- const element = anchor.getElement();
319
- if (element) {
320
- element.style.display = visible ? '' : 'none';
321
- }
322
- });
323
- }
324
- };
236
+ return PointOverlay.create(this.map, twinkleList, callback);
325
237
  }
326
238
  /**
327
239
  * 添加vue组件为点位
@@ -354,7 +266,7 @@ export default class Point {
354
266
  * @param zoom 缩放级别
355
267
  * @param duration 动画时长
356
268
  */
357
- locationAction(lgtd, lttd, zoom = 20, duration = 3000) {
358
- return new MapTools(this.map).locationAction(lgtd, lttd, zoom, duration);
269
+ locationAction(lgtd, lttd, zoom = 20, duration = 3000, projection) {
270
+ return new MapTools(this.map).locationAction(lgtd, lttd, zoom, duration, projection);
359
271
  }
360
272
  }
@@ -0,0 +1,10 @@
1
+ import Map from "ol/Map";
2
+ import VectorLayer from "ol/layer/Vector";
3
+ import VectorSource from "ol/source/Vector";
4
+ import type { ClusterOptions, PointData } from "../../types";
5
+ /**
6
+ * 点聚合图层构建器。
7
+ */
8
+ export default class PointClusterLayer {
9
+ static create(map: Map, pointData: PointData[], options: ClusterOptions, createClusterStyle: (options: ClusterOptions, name: string) => any): VectorLayer<VectorSource>;
10
+ }
@@ -0,0 +1,52 @@
1
+ import Feature from "ol/Feature";
2
+ import { Point as OlPoint } from "ol/geom";
3
+ import VectorLayer from "ol/layer/Vector";
4
+ import VectorSource from "ol/source/Vector";
5
+ import { Cluster } from "ol/source";
6
+ import ProjectionUtils from "../../utils/ProjectionUtils";
7
+ import ValidationUtils from "../../utils/ValidationUtils";
8
+ import { ConfigManager } from "../map";
9
+ /**
10
+ * 点聚合图层构建器。
11
+ */
12
+ export default class PointClusterLayer {
13
+ static create(map, pointData, options, createClusterStyle) {
14
+ const pointFeatureList = [];
15
+ pointData.forEach(item => {
16
+ if (!ValidationUtils.validateCoordinates(item)) {
17
+ return;
18
+ }
19
+ pointFeatureList.push(new Feature({
20
+ type: options.layerName,
21
+ layerName: options.layerName,
22
+ geometry: new OlPoint(ProjectionUtils.transformCoordinate([item.lgtd, item.lttd], options)),
23
+ name: options.textKey ? item[options.textKey] : '',
24
+ rawData: item,
25
+ }));
26
+ });
27
+ const source = new VectorSource({ features: pointFeatureList });
28
+ const clusterSource = new Cluster({
29
+ distance: options.distance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.distance,
30
+ minDistance: options.minDistance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.minDistance,
31
+ source,
32
+ });
33
+ const clusterLayer = new VectorLayer({
34
+ layerName: options.layerName,
35
+ source: clusterSource,
36
+ style: (feature) => {
37
+ if (options.style) {
38
+ if (typeof options.style === 'function') {
39
+ return options.style(feature);
40
+ }
41
+ return options.style;
42
+ }
43
+ const name = feature.get('features')[0].get('name');
44
+ return createClusterStyle(options, name);
45
+ },
46
+ zIndex: options.zIndex || ConfigManager.DEFAULT_CLUSTER_OPTIONS.zIndex,
47
+ });
48
+ clusterLayer.setVisible(options.visible === undefined ? true : options.visible);
49
+ map.addLayer(clusterLayer);
50
+ return clusterLayer;
51
+ }
52
+ }
@@ -0,0 +1,13 @@
1
+ import Overlay from 'ol/Overlay';
2
+ import Map from 'ol/Map';
3
+ import type { TwinkleItem } from '../../types';
4
+ /**
5
+ * DOM 点位覆盖物构建器。
6
+ */
7
+ export default class PointOverlay {
8
+ static create(map: Map, twinkleList: TwinkleItem[], callback?: Function): {
9
+ anchors: Overlay[];
10
+ remove: () => void;
11
+ setVisible: (visible: boolean) => void;
12
+ };
13
+ }
@@ -0,0 +1,57 @@
1
+ import Overlay from 'ol/Overlay';
2
+ import { ConfigManager } from '../map';
3
+ /**
4
+ * DOM 点位覆盖物构建器。
5
+ */
6
+ export default class PointOverlay {
7
+ static create(map, twinkleList, callback) {
8
+ let anchors = [];
9
+ twinkleList.forEach(twinkleItem => {
10
+ let element;
11
+ if (twinkleItem.element) {
12
+ element = typeof twinkleItem.element === 'function'
13
+ ? twinkleItem.element(twinkleItem)
14
+ : twinkleItem.element;
15
+ if (twinkleItem.className) {
16
+ const classes = twinkleItem.className.split(/\s+/).filter(Boolean);
17
+ if (classes.length > 0) {
18
+ element.classList.add(...classes);
19
+ }
20
+ }
21
+ }
22
+ else {
23
+ element = document.createElement('div');
24
+ element.className = twinkleItem.className || '';
25
+ }
26
+ if (callback) {
27
+ element.addEventListener('click', () => callback(twinkleItem));
28
+ }
29
+ const anchor = new Overlay({
30
+ element,
31
+ positioning: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.positioning,
32
+ stopEvent: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.stopEvent
33
+ });
34
+ anchor.setPosition([twinkleItem.lgtd, twinkleItem.lttd]);
35
+ map.addOverlay(anchor);
36
+ anchors.push(anchor);
37
+ });
38
+ return {
39
+ anchors,
40
+ remove: () => {
41
+ anchors.forEach(anchor => {
42
+ anchor.getElement()?.remove();
43
+ map.removeOverlay(anchor);
44
+ });
45
+ anchors = [];
46
+ },
47
+ setVisible: (visible) => {
48
+ anchors.forEach(anchor => {
49
+ const element = anchor.getElement();
50
+ if (element) {
51
+ element.style.display = visible ? '' : 'none';
52
+ }
53
+ });
54
+ }
55
+ };
56
+ }
57
+ }
@@ -0,0 +1,13 @@
1
+ import Feature from "ol/Feature";
2
+ import Map from "ol/Map";
3
+ import { Text } from "ol/style";
4
+ import type { PointData, PulsePointLayerHandle, PulsePointOptions } from "../../types";
5
+ /**
6
+ * 高性能闪烁点图层构建器。
7
+ */
8
+ export default class PointPulseLayer {
9
+ static createTextStyle(options: PulsePointOptions, text: string): Text;
10
+ static withOpacity(color: string, opacity: number): string;
11
+ static createFeatures(pointData: PointData[], options: PulsePointOptions): Feature[];
12
+ static create(map: Map, pointData: PointData[], options: PulsePointOptions): PulsePointLayerHandle;
13
+ }