my-openlayer 0.1.7 → 0.1.9

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/MyOl.d.ts CHANGED
@@ -5,7 +5,7 @@ import Point from "./core/Point";
5
5
  import Line from "./core/Line";
6
6
  import MapBaseLayers from "./core/MapBaseLayers";
7
7
  import MapTools from "./core/MapTools";
8
- import { MapInitType } from './types';
8
+ import { MapInitType, EventType } from './types';
9
9
  export default class MyOl {
10
10
  map: Map;
11
11
  private baseLayers;
@@ -48,7 +48,7 @@ export default class MyOl {
48
48
  * @returns MapTools
49
49
  */
50
50
  getTools(): MapTools;
51
- restPosition(duration?: number): void;
51
+ resetPosition(duration?: number): void;
52
52
  /**
53
53
  * 地图定位
54
54
  * @param lgtd 经度
@@ -63,5 +63,5 @@ export default class MyOl {
63
63
  * @param clickType 点击类型
64
64
  * @param callback 回调函数
65
65
  */
66
- mapOnEvent(eventType: string | undefined, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
66
+ mapOnEvent(eventType: EventType, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
67
67
  }
package/dist/MyOl.js CHANGED
@@ -129,7 +129,7 @@ class MyOl {
129
129
  this.mapTools = new MapTools(this.map);
130
130
  return this.mapTools;
131
131
  }
132
- restPosition(duration = 3000) {
132
+ resetPosition(duration = 3000) {
133
133
  if (!this.options.center)
134
134
  return console.error('未设置中心点');
135
135
  this.locationAction(this.options.center[0], this.options.center[1], this.options.zoom, duration);
@@ -150,7 +150,7 @@ class MyOl {
150
150
  * @param clickType 点击类型
151
151
  * @param callback 回调函数
152
152
  */
153
- mapOnEvent(eventType = "def", callback, clickType) {
153
+ mapOnEvent(eventType, callback, clickType) {
154
154
  MapTools.mapOnEvent(this.map, eventType, callback, clickType);
155
155
  }
156
156
  }
@@ -1,5 +1,5 @@
1
1
  import Map from "ol/Map";
2
- import { MapJSONData } from "../types";
2
+ import { EventType, 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";
@@ -12,8 +12,8 @@ export default class MapTools {
12
12
  * 根据名称获取图层
13
13
  * @param layerName 图层名称
14
14
  */
15
- getLayerByLayerName(layerName: string): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
16
- static getLayerByLayerName(map: Map, layerName: string): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
15
+ getLayerByLayerName(layerName: string | string[]): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
16
+ static getLayerByLayerName(map: Map, layerName: string | string[]): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
17
17
  /**
18
18
  * 设置地图裁剪
19
19
  */
@@ -22,13 +22,13 @@ export default class MapTools {
22
22
  * 移除图层
23
23
  * @param layerName 图层名称
24
24
  */
25
- removeLayer(layerName: string): void;
25
+ removeLayer(layerName: string | string[]): void;
26
26
  /**
27
27
  * 移除图层
28
28
  * @param map 地图对象
29
29
  * @param layerName 图层名称
30
30
  */
31
- static removeLayer(map: Map, layerName: string): void;
31
+ static removeLayer(map: Map, layerName: string | string[]): void;
32
32
  setLayerVisible(layerName: string, visible: boolean): void;
33
33
  /**
34
34
  * 设置图层可见性
@@ -37,7 +37,7 @@ export default class MapTools {
37
37
  * @param visible 是否可见
38
38
  */
39
39
  static setLayerVisible: (map: Map, layerName: string, visible: boolean) => void;
40
- mapOnEvent(eventType: string, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
40
+ mapOnEvent(eventType: EventType, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
41
41
  /**
42
42
  * 地图监听事件
43
43
  * @param map
@@ -45,5 +45,5 @@ export default class MapTools {
45
45
  * @param clickType 点击类型
46
46
  * @param callback 回调函数
47
47
  */
48
- static mapOnEvent(map: Map, eventType: string | undefined, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
48
+ static mapOnEvent(map: Map, eventType: EventType, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon'): void;
49
49
  }
@@ -21,9 +21,16 @@ class MapTools {
21
21
  const targetLayer = [];
22
22
  const layers = map.getLayers().getArray();
23
23
  Object.keys(layers).forEach(function (key) {
24
- const _layerName = layers[key]['values_'].layerName;
25
- if (_layerName && _layerName === layerName) {
26
- targetLayer.push(layers[key]);
24
+ const _layerName = layers[key].get('layerName');
25
+ if (typeof layerName === "string") {
26
+ if (_layerName && _layerName === layerName) {
27
+ targetLayer.push(layers[key]);
28
+ }
29
+ }
30
+ else {
31
+ if (_layerName && layerName.includes(_layerName)) {
32
+ targetLayer.push(layers[key]);
33
+ }
27
34
  }
28
35
  });
29
36
  return targetLayer;
@@ -99,7 +106,7 @@ class MapTools {
99
106
  * @param clickType 点击类型
100
107
  * @param callback 回调函数
101
108
  */
102
- static mapOnEvent(map, eventType = "def", callback, clickType) {
109
+ static mapOnEvent(map, eventType, callback, clickType) {
103
110
  const clickTypeObj = {
104
111
  point: ['point'],
105
112
  line: ['line'],
package/dist/types.d.ts CHANGED
@@ -91,3 +91,4 @@ export interface PointData {
91
91
  [propName: string]: any;
92
92
  }
93
93
  export type MeasureHandlerType = 'Polygon' | 'LineString';
94
+ export type EventType = 'click' | 'moveend' | 'hover';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -36,5 +36,8 @@
36
36
  "vite-plugin-css-modules": "^0.0.1",
37
37
  "vite-plugin-libcss": "^1.1.1",
38
38
  "vue-tsc": "^2.0.6"
39
+ },
40
+ "peerDependencies": {
41
+ "ol": "^6.15.1"
39
42
  }
40
43
  }