my-openlayer 0.1.13 → 0.1.15

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.
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import Map from "ol/Map";
5
5
  import { Tile as TileLayer } from "ol/layer";
6
+ import { TileWMS } from "ol/source";
6
7
  import WMTSTileGrid from "ol/tilegrid/WMTS";
7
8
  import XYZ from "ol/source/XYZ";
8
9
  import { MapLayersOptions, TiandituType, AnnotationLayerOptions } from "../types";
@@ -17,6 +18,10 @@ export default class MapBaseLayers {
17
18
  static addAnnotationLayer(map: Map, options: AnnotationLayerOptions): TileLayer<XYZ>;
18
19
  addMapLayer(): void;
19
20
  createLayer(layer: any): any;
21
+ addGeoServerLayer(url: string, layer: string, options: {
22
+ zIndex?: number;
23
+ visible?: boolean;
24
+ }): TileLayer<TileWMS>;
20
25
  static getTiandiTuLayer(options: {
21
26
  type: TiandituType;
22
27
  token: string;
@@ -4,7 +4,7 @@
4
4
  import { Tile as TileLayer } from "ol/layer";
5
5
  import { get as getProjection } from "ol/proj";
6
6
  import { getTopLeft, getWidth } from "ol/extent";
7
- // import { WMTS } from "ol/source";
7
+ import { TileWMS } from "ol/source";
8
8
  import WMTSTileGrid from "ol/tilegrid/WMTS";
9
9
  import XYZ from "ol/source/XYZ";
10
10
  import MapTools from "./MapTools";
@@ -108,6 +108,24 @@ export default class MapBaseLayers {
108
108
  }
109
109
  return layer;
110
110
  }
111
+ addGeoServerLayer(url, layer, options) {
112
+ const wmsLayer = new TileLayer({
113
+ source: new TileWMS({
114
+ url: url,
115
+ params: {
116
+ 'LAYERS': layer,
117
+ 'TILED': true,
118
+ 'VERSION': '1.1.1' // 或 '1.3.0'
119
+ },
120
+ serverType: 'geoserver',
121
+ crossOrigin: 'anonymous', // 允许跨域
122
+ }),
123
+ zIndex: options.zIndex ?? 10,
124
+ visible: options.visible ?? true,
125
+ });
126
+ this.map.addLayer(wmsLayer);
127
+ return wmsLayer;
128
+ }
111
129
  //img_c 影像底图 ter_c 地形底图
112
130
  static getTiandiTuLayer(options) {
113
131
  return new TileLayer({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "0.1.13",
4
+ "version": "0.1.15",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",