my-openlayer 0.1.8 → 0.1.10

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;
@@ -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
@@ -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
  }
package/dist/core/Line.js CHANGED
@@ -22,7 +22,9 @@ export default class Line {
22
22
  return new Style({
23
23
  stroke: new Stroke({
24
24
  color: options.strokeColor || 'rgba(3, 122, 255, 1)',
25
- width: options.strokeWidth || 2
25
+ width: options.strokeWidth || 2,
26
+ lineDash: options?.lineDash,
27
+ lineDashOffset: options?.lineDashOffset
26
28
  }),
27
29
  });
28
30
  },
@@ -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
  }
@@ -20,10 +20,17 @@ class MapTools {
20
20
  static getLayerByLayerName(map, layerName) {
21
21
  const targetLayer = [];
22
22
  const layers = map.getLayers().getArray();
23
- Object.keys(layers).forEach(function (key) {
24
- const _layerName = layers[key]['values_'].layerName;
25
- if (_layerName && _layerName === layerName) {
26
- targetLayer.push(layers[key]);
23
+ Object.values(layers).forEach((layer) => {
24
+ const _layerName = layer.get('layerName');
25
+ if (typeof layerName === "string") {
26
+ if (_layerName && _layerName === layerName) {
27
+ targetLayer.push(layer);
28
+ }
29
+ }
30
+ else {
31
+ if (_layerName && layerName.includes(_layerName)) {
32
+ targetLayer.push(layer);
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.8",
4
+ "version": "0.1.10",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",