my-openlayer 0.0.14 → 0.0.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.
@@ -1,4 +1,4 @@
1
- import MyOl from "../index";
1
+ import Map from "ol/Map";
2
2
  interface Options {
3
3
  Vue: any;
4
4
  Template: any;
@@ -10,11 +10,11 @@ interface Options {
10
10
  zIndex?: number;
11
11
  }
12
12
  export default class DomPoint {
13
- private myOlMap;
13
+ private map;
14
14
  private app;
15
15
  private anchor;
16
16
  private dom;
17
- constructor(map: MyOl, options: Options);
17
+ constructor(map: Map, options: Options);
18
18
  setVisible(visible: boolean): void;
19
19
  remove(): void;
20
20
  }
@@ -2,10 +2,10 @@
2
2
  import Overlay from "ol/Overlay";
3
3
  export default class DomPoint {
4
4
  constructor(map, options) {
5
- this.myOlMap = map;
5
+ this.map = map;
6
6
  const { Vue, Template, lgtd, lttd, props, } = options;
7
7
  this.dom = document.createElement('div');
8
- this.myOlMap.map.getViewport().appendChild(this.dom);
8
+ this.map.getViewport().appendChild(this.dom);
9
9
  if (Vue.version.startsWith('3')) {
10
10
  this.app = Vue.createApp(Object.assign(Template, {
11
11
  props: { ...props }
@@ -24,13 +24,13 @@ export default class DomPoint {
24
24
  stopEvent: false
25
25
  });
26
26
  this.anchor.setPosition([lgtd, lttd]);
27
- this.myOlMap.map.addOverlay(this.anchor);
27
+ this.map.addOverlay(this.anchor);
28
28
  }
29
29
  setVisible(visible) {
30
30
  this.dom.style.visibility = visible ? 'visible' : 'hidden';
31
31
  }
32
32
  remove() {
33
33
  this.app.unmount();
34
- this.myOlMap.map.removeOverlay(this.anchor);
34
+ this.map.removeOverlay(this.anchor);
35
35
  }
36
36
  }
@@ -1,19 +1,20 @@
1
1
  import Map from "ol/Map";
2
- import MyOl from "../index";
2
+ import VectorSource from "ol/source/Vector";
3
+ import VectorLayer from "ol/layer/Vector";
4
+ import { Style } from "ol/style";
3
5
  import { OptionsType, MapJSONData } from "../types";
4
6
  export default class Line {
5
7
  private map;
6
- private myOlMap;
7
8
  riverLayerList: any[];
8
9
  riverLayerShow: boolean;
9
10
  [propertyName: string]: any;
10
- constructor(myOlMap: MyOl, map: Map);
11
- addLineCommon(data: MapJSONData, options: OptionsType): any;
11
+ constructor(map: Map);
12
+ addLineCommon(data: MapJSONData, options: OptionsType): VectorLayer<VectorSource<import("ol/geom").Geometry>>;
12
13
  addRiverLayersByZoom(fyRiverJson: MapJSONData, options?: OptionsType): void;
13
14
  showRiverLayer(show: boolean): void;
14
15
  showRiverLayerByZoom(): void;
15
16
  addRiverWidthByLev(arr?: any): void;
16
17
  setFeatureAttr(feature: {
17
18
  get: (arg0: string) => any;
18
- }): any;
19
+ }): Style;
19
20
  }
package/dist/core/Line.js CHANGED
@@ -2,11 +2,11 @@ import VectorSource from "ol/source/Vector";
2
2
  import GeoJSON from "ol/format/GeoJSON";
3
3
  import VectorLayer from "ol/layer/Vector";
4
4
  import { Stroke, Style } from "ol/style";
5
+ import MapTools from "./MapTools";
5
6
  export default class Line {
6
- constructor(myOlMap, map) {
7
+ constructor(map) {
7
8
  this.riverLayerList = [];
8
9
  this.riverLayerShow = false;
9
- this.myOlMap = myOlMap;
10
10
  this.map = map;
11
11
  }
12
12
  addLineCommon(data, options) {
@@ -71,7 +71,7 @@ export default class Line {
71
71
  this.map.addLayer(riverLayer);
72
72
  }
73
73
  this.showRiverLayerByZoom();
74
- this.myOlMap.mapOnEvent('moveend', () => {
74
+ MapTools.mapOnEvent(this.map, 'moveend', () => {
75
75
  this.showRiverLayerByZoom();
76
76
  });
77
77
  }
@@ -2,6 +2,7 @@
2
2
  * 地图底图图层
3
3
  */
4
4
  import Map from "ol/Map";
5
+ import WMTSTileGrid from "ol/tilegrid/WMTS";
5
6
  import { MapbaseType, MapJSONData } from "../types";
6
7
  interface MapLayersOptions {
7
8
  zIndex?: number;
@@ -17,7 +18,7 @@ export default class MapBaseLayers {
17
18
  constructor(map: Map, options: MapLayersOptions);
18
19
  addMapLayer(type: MapbaseType): void;
19
20
  createLayer(layer: any): any;
20
- getTileGrid(length: number): any;
21
+ getTileGrid(length: number): WMTSTileGrid;
21
22
  getTiandiTuLayer(tiandituType?: 'img_c' | 'ter_c'): any;
22
23
  getTerrainLayer(): any;
23
24
  /**
@@ -13,4 +13,12 @@ export default class MapTools {
13
13
  */
14
14
  static setMapClip(baseLayer: any, data: MapJSONData): any;
15
15
  removeLayer(layerName: string): void;
16
+ /**
17
+ * 地图监听事件
18
+ * @param map
19
+ * @param eventType 事件类型
20
+ * @param clickType 点击类型
21
+ * @param callback 回调函数
22
+ */
23
+ static mapOnEvent(map: Map, eventType: string | undefined, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
16
24
  }
@@ -63,4 +63,44 @@ export default class MapTools {
63
63
  removeLayer(layerName) {
64
64
  this.map.removeLayer(this.getLayerByLayerName(layerName));
65
65
  }
66
+ /**
67
+ * 地图监听事件
68
+ * @param map
69
+ * @param eventType 事件类型
70
+ * @param clickType 点击类型
71
+ * @param callback 回调函数
72
+ */
73
+ static mapOnEvent(map, eventType = "def", callback, clickType) {
74
+ const clickTypeObj = {
75
+ point: ['point'],
76
+ line: ['line'],
77
+ polygon: ['polygon', 'MultiPolygon']
78
+ };
79
+ if (eventType === "click") {
80
+ map.on("click", (e) => {
81
+ // 获取点位 feature
82
+ const pixel = map.getEventPixel(e.originalEvent);
83
+ const features = map.getFeaturesAtPixel(pixel);
84
+ let feature = undefined;
85
+ if (features.length > 0)
86
+ feature = features[0];
87
+ callback(feature, { features, pixel });
88
+ });
89
+ }
90
+ else if (eventType === 'moveend') {
91
+ map.on('moveend', function () {
92
+ const zoom = map.getView().getZoom();
93
+ if (zoom) {
94
+ callback(zoom);
95
+ }
96
+ });
97
+ }
98
+ else if (eventType === 'hover') {
99
+ map.on('pointermove', (e) => {
100
+ const pixel = map.getEventPixel(e.originalEvent);
101
+ const features = map.getFeaturesAtPixel(pixel);
102
+ callback({ features, pixel });
103
+ });
104
+ }
105
+ }
66
106
  }
@@ -1,10 +1,10 @@
1
1
  import Map from "ol/Map";
2
- import MyOl from "../index";
2
+ import VectorLayer from "ol/layer/Vector";
3
+ import VectorSource from "ol/source/Vector";
3
4
  import { OptionsType, PointData } from '../types';
4
5
  export default class Point {
5
- private myOlMap;
6
6
  private map;
7
- constructor(myOlMap: MyOl, map: Map);
7
+ constructor(map: Map);
8
8
  /**
9
9
  *
10
10
  * @param pointData
@@ -15,7 +15,7 @@ export default class Point {
15
15
  * hasImg: Boolean 是否显示图标
16
16
  * }
17
17
  */
18
- addPoint(pointData: PointData[], type: string, options: OptionsType): any;
18
+ addPoint(pointData: PointData[], type: string, options: OptionsType): VectorLayer<VectorSource<import("ol/geom").Geometry>>;
19
19
  addClusterPoint(pointData: any[], type: string | undefined, options: OptionsType): void;
20
20
  /**
21
21
  * 添加点 - 闪烁
@@ -43,7 +43,7 @@ export default class Point {
43
43
  * 设置dom元素为点位
44
44
  */
45
45
  setDomPoint(id: string, lgtd: number, lttd: number): void;
46
- setDomPointVue(pointInfoList: any[], template: any): {
46
+ setDomPointVue(pointInfoList: any[], template: any, Vue: any): {
47
47
  setVisible: (visible: boolean) => void;
48
48
  remove: () => void;
49
49
  };
@@ -10,9 +10,9 @@ import { Cluster } from 'ol/source';
10
10
  import * as turf from 'turf';
11
11
  import GeoJSON from "ol/format/GeoJSON";
12
12
  import DomPoint from "./DomPoint";
13
+ import MapTools from "./MapTools";
13
14
  export default class Point {
14
- constructor(myOlMap, map) {
15
- this.myOlMap = myOlMap;
15
+ constructor(map) {
16
16
  this.map = map;
17
17
  }
18
18
  /**
@@ -142,7 +142,7 @@ export default class Point {
142
142
  }
143
143
  // 在流域中心添加闪烁点位
144
144
  setTwinkleLayerFromPolygon(twinkleList, className, key, json) {
145
- this.myOlMap.getTools().removeLayer('twinklePoint');
145
+ new MapTools(this.map).removeLayer('twinklePoint');
146
146
  // 计算多边形的中心点坐标
147
147
  const calculatePolygonCenter = (polygonCoordinates) => {
148
148
  const polygon = turf.polygon(polygonCoordinates[0]);
@@ -272,9 +272,10 @@ export default class Point {
272
272
  this.map.addOverlay(anchor);
273
273
  }
274
274
  }
275
- setDomPointVue(pointInfoList, template) {
275
+ setDomPointVue(pointInfoList, template, Vue) {
276
276
  const layer = pointInfoList.map((pointInfo) => {
277
- return new DomPoint(this.myOlMap, {
277
+ return new DomPoint(this.map, {
278
+ Vue,
278
279
  Template: template,
279
280
  lgtd: pointInfo.lgtd,
280
281
  lttd: pointInfo.lttd,
@@ -1,12 +1,13 @@
1
1
  import Map from "ol/Map";
2
- import MyOl from "../index";
2
+ import VectorLayer from "ol/layer/Vector";
3
+ import VectorSource from "ol/source/Vector";
4
+ import { Geometry } from "ol/geom";
3
5
  import { OptionsType, MapJSONData } from '../types';
4
6
  export default class Polygon {
5
- private myOlMap;
6
7
  map: Map;
7
8
  private colorMap;
8
9
  [key: string]: any;
9
- constructor(myOlMap: MyOl, map: Map);
10
+ constructor(map: Map);
10
11
  /**
11
12
  * 获取等级颜色
12
13
  * @param lev
@@ -19,7 +20,7 @@ export default class Polygon {
19
20
  * @param options 图层配置
20
21
  */
21
22
  addPolygonMapLayer(data: MapJSONData, type: string | undefined, options: OptionsType): void;
22
- addPolygonLayerCommon(dataJSON: MapJSONData, options?: OptionsType): any;
23
+ addPolygonLayerCommon(dataJSON: MapJSONData, options?: OptionsType): VectorLayer<VectorSource<Geometry>>;
23
24
  /**
24
25
  * 根据数据数组更新某个面颜色
25
26
  * @param layerName 图层名称
@@ -10,14 +10,13 @@ import Feature from "ol/Feature";
10
10
  import ImageStatic from "ol/source/ImageStatic";
11
11
  import MapTools from "./MapTools";
12
12
  export default class Polygon {
13
- constructor(myOlMap, map) {
13
+ constructor(map) {
14
14
  this.colorMap = {
15
15
  '0': 'rgba(255, 0, 0, 0.6)',
16
16
  '1': 'rgba(245, 154, 35, 0.6)',
17
17
  '2': 'rgba(255, 238, 0, 0.6)',
18
18
  '3': 'rgba(1, 111, 255, 0.6)'
19
19
  };
20
- this.myOlMap = myOlMap;
21
20
  this.map = map;
22
21
  }
23
22
  /**
@@ -71,7 +70,7 @@ export default class Polygon {
71
70
  //fyBasinJson中的id的key需要跟options中的nameKey一致
72
71
  addPolygonLayerCommon(dataJSON, options = {}) {
73
72
  if (options.type != null) {
74
- this.myOlMap.getTools().removeLayer(options.type);
73
+ new MapTools(this.map).removeLayer(options.type);
75
74
  }
76
75
  const layer = new VectorLayer({
77
76
  name: options.type,
@@ -283,7 +282,7 @@ export default class Polygon {
283
282
  return this[layerName];
284
283
  }
285
284
  removePolygonLayer(layerName) {
286
- this.myOlMap.getTools().removeLayer(layerName);
285
+ new MapTools(this.map).removeLayer(layerName);
287
286
  this[layerName] = null;
288
287
  }
289
288
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import View from "ol/View";
1
2
  import Map from "ol/Map";
2
3
  import Polygon from "./core/Polygon";
3
4
  import Point from "./core/Point";
@@ -24,7 +25,7 @@ export default class MyOl {
24
25
  * @param options.extent 视图范围
25
26
  * @returns View
26
27
  */
27
- static getView(options?: MapInitType): any;
28
+ static getView(options?: MapInitType): View;
28
29
  /**
29
30
  * 获取 地图 面 操作
30
31
  * @returns Polygon
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ class MyOl {
68
68
  */
69
69
  getPolygon() {
70
70
  if (!this.polygon)
71
- this.polygon = new Polygon(this, this.map);
71
+ this.polygon = new Polygon(this.map);
72
72
  return this.polygon;
73
73
  }
74
74
  getMapBaseLayers() {
@@ -173,7 +173,7 @@ class MyOl {
173
173
  */
174
174
  getPoint() {
175
175
  if (!this.point)
176
- this.point = new Point(this, this.map);
176
+ this.point = new Point(this.map);
177
177
  return this.point;
178
178
  }
179
179
  // ╔══════════╗
@@ -185,7 +185,7 @@ class MyOl {
185
185
  */
186
186
  getLine() {
187
187
  if (!this.line)
188
- this.line = new Line(this, this.map);
188
+ this.line = new Line(this.map);
189
189
  return this.line;
190
190
  }
191
191
  /**
@@ -231,38 +231,7 @@ class MyOl {
231
231
  * @param callback 回调函数
232
232
  */
233
233
  mapOnEvent(eventType = "def", callback, clickType) {
234
- const clickTypeObj = {
235
- point: ['point'],
236
- line: ['line'],
237
- polygon: ['polygon', 'MultiPolygon']
238
- };
239
- const map = this.map;
240
- if (eventType === "click") {
241
- map.on("click", (e) => {
242
- // 获取点位 feature
243
- const pixel = map.getEventPixel(e.originalEvent);
244
- const features = map.getFeaturesAtPixel(pixel);
245
- let feature = undefined;
246
- if (features.length > 0)
247
- feature = features[0];
248
- callback(feature, { features, pixel });
249
- });
250
- }
251
- else if (eventType === 'moveend') {
252
- map.on('moveend', function () {
253
- const zoom = map.getView().getZoom();
254
- if (zoom) {
255
- callback(zoom);
256
- }
257
- });
258
- }
259
- else if (eventType === 'hover') {
260
- map.on('pointermove', (e) => {
261
- const pixel = map.getEventPixel(e.originalEvent);
262
- const features = map.getFeaturesAtPixel(pixel);
263
- callback({ features, pixel });
264
- });
265
- }
234
+ MapTools.mapOnEvent(this.map, eventType, callback, clickType);
266
235
  }
267
236
  }
268
237
  MyOl.DefaultOptions = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",