uniapp使用openlayers加载地图服务

news2025/1/17 3:08:47

uniapp使用openlayers加载地图服务

在这里插入图片描述

<!-- 地图组件 -->
<template>
	<view id="myMap" :regionChangeItem="regionChangeItem" :change:regionChangeItem="olRender.selectAdministrativeRegion"
		:tagSelectProduce=tagSelectProduce :tagSelectDistribute="tagSelectDistribute"
		:change:tagSelectProduce="olRender.tagSelectChangeProduce"
		:change:tagSelectDistribute="olRender.tagSelectChangeDistribute" :dropFrameDataProduce="dropFrameDataProduce"
		:dropFrameDataDistribute="dropFrameDataDistribute" :change:dropFrameDataProduce="olRender.loadDropFrameProduce"
		:change:dropFrameDataDistribute="olRender.loadDropFrameDistribute"
		style="width: 100%; height: calc(100vh - 84rpx);"></view>
</template>

<script>
	export default {
		props: {
			// 行政区选择数据
			regionChangeItem: {
				type: Object,
				default: () => ({
					geom: null,
				})
			},
			dropFrameDataProduce: {
				type: Object,
				default: () => ({
					imagesGeom05: [],
					imagesGeom1: [],
					imagesGeom2: [],
					xzqdm: 530000,
				})
			},
			dropFrameDataDistribute: {
				type: Object,
				default: () => ({
					imagesGeom05: [],
					imagesGeom1: [],
					imagesGeom2: [],
					xzqdm: 530000,
				})
			},
			tagSelectProduce: {
				type: Object,
				default: () => ({
					tag05: true,
					tag1: true,
					tag2: true,
				})
			},
			tagSelectDistribute: {
				type: Object,
				default: () => ({
					tag05: true,
					tag1: true,
					tag2: true,
				})
			},
		},
	}
</script>

<script module="olRender" lang="renderjs">
	import source, {
		Vector as sourceVector
	} from 'ol/source';
	import ol, {
		Map,
		Tile,
		View,
		Feature
	} from 'ol';
	import {
		Polygon
	} from 'ol/geom';
	import {
		Style,
		Fill,
		Stroke
	} from 'ol/style';
	import {
		fromLonLat,
		transform,
		Projection
	} from 'ol/proj.js';
	import {
		DragPan,
		MouseWheelZoom,
		defaults as defaultInteractions
	} from 'ol/interaction';
	import {
		Vector,
	} from 'ol/layer';
	import VectorImageLayer from 'ol/layer/Vector';
	import VectorSource from 'ol/source/Vector';
	import WKT from 'ol/format/WKT';
	import GeoJSON from "ol/format/GeoJSON";
	import {
		bbox as bboxStrategy
	} from 'ol/loadingstrategy';
	import {
		MapServiceLoader
	} from '@/map/MapServiceLoader.js';
	import GLOBAL_VARIABLE from '@/public/config/GlobalConfig';
	import {
		eventBus
	} from '@/utils/eventBus.js';
	export default {
		data() {
			return {
				mapId: 'myMap',
				map: null,
				mapServiceLoader: null,
				format: new WKT(),
				xzqId: 'xzq', // 行政区id
				xzqIdYns: 'xzqYns', // 行政区id(省)
				xzqHighlightId: 'xzqHighlight', // 选择后高亮行政区id
				projection: {},
				dropColor: {
					imagesGeom05: {
						strokeColor: 'rgba(175, 175, 175, 0.5)',
						fillColor: 'rgba(147, 250, 194, 0.5)',
					},
					imagesGeom1: {
						strokeColor: 'rgba(175, 175, 175, 0.5)',
						fillColor: 'rgba(147, 240, 250, 0.5)',
					},
					imagesGeom2: {
						strokeColor: 'rgba(175, 175, 175, 0.5)',
						fillColor: 'rgba(255, 196, 196, 0.5)',
					},
				},
				dropColorDistribute: {
					imagesGeom05: {
						strokeColor: 'rgba(152, 230, 0, 0.5)',
						fillColor: 'rgba(76, 230, 0, 0.5)',
					},
					imagesGeom1: {
						strokeColor: 'rgba(152, 230, 0, 0.5)',
						fillColor: 'rgba(152, 230, 0, 0.5)',
					},
					imagesGeom2: {
						strokeColor: 'rgba(230, 230, 0, 0.5)',
						fillColor: 'rgba(230, 230, 0, 0.5)',
					},
				},
				// 影像生产-落图框图层id
				drop05ProduceId: 'drop05_p',
				drop1ProduceId: 'drop1_p',
				drop2ProduceId: 'drop2_p',
				// 影像分发-落图框图层id
				drop05DistributeId: 'drop05_d',
				drop1DistributeId: 'drop1_d',
				drop2DistributeId: 'drop2_d',
				// 影像生产落图框图层
				imagesGeom05LayersProduce: null,
				imagesGeom1LayersProduce: null,
				imagesGeom2LayersProduce: null,
				// 影像分发-落图框图层
				imagesGeom05LayersDistribute: null,
				imagesGeom1LayersDistribute: null,
				imagesGeom2LayersDistribute: null,
			};
		},
		methods: {
			getRegionLayerDataCounty(cqlFilter = 'level in (2)') {
				const workspaceName = GLOBAL_VARIABLE.administrativeConfig.workspaceName;
				const layerName = GLOBAL_VARIABLE.administrativeConfig.layerNameCounty;
				const accessUrl = GLOBAL_VARIABLE.administrativeConfig.accessUrl;
				const optionWms = {
					layerName,
					matrixSet: 'EPSG:4326',
					accessUrl: `${accessUrl}/${workspaceName}/wms`,
					id: this.xzqId,
					serviceType: 'wms',
					otherPara: {
						layerName: layerName,
						matrixSet: 'EPSG:4326',
						format: 'image/png',
						VERSION: '1.1.1',
						LAYERS: workspaceName + ':' + layerName,
						projection: this.projection,
						zIndex: 10,
						opacity: 1,
						exceptions: 'application/vnd.ogc.se_inimage',
						CQL_FILTER: cqlFilter,
					},
					transformationMatrix: '1,2,3 2,4,5 4,6,7',
				};
				const optionWmTs = {
					layerName,
					matrixSet: 'EPSG:4326',
					accessUrl: `${accessUrl}/${workspaceName}/gwc/service/wmts?request=GetCapabilities`,
					id: this.xzqId,
					serviceType: 'wmts',
					transformationMatrix: '1,2,3 2,4,5 4,6,7',
					otherPara: {}
				};
				return optionWmTs;
			},
			innitMap() {
				const projection = new Projection({
					code: 'EPSG:4490',
					units: 'degrees',
					global: false,
				});
				this.projection = projection;
				const view = new View({
					projection,
					enableRotation: false, // 禁止地图旋转
				})
				const map = new Map({
					target: this.mapId,
					layers: [],
					view,
					controls: [],
					interactions: defaultInteractions({
							dragPan: false,
							doubleClickZoom: false, // 取消双击放大功能交互
							mouseWheelZoom: false, // 取消滚动鼠标中间的滑轮交互
							shiftDragZoom: false, // 取消shift+wheel左键拖动交互
						})
						.extend([
							new DragPan({
								condition: function(event) {
									return event.originalEvent.button === 1;
								}
							})
						]),
				});

				// 拖拽移动
				// const dragPan = new DragPan();
				// const mouseWheelZoom = new MouseWheelZoom();
				// // 添加DragPan和MouseWheelZoom交互到地图
				// map.addInteraction(dragPan);
				// map.addInteraction(mouseWheelZoom);

				// 禁用地图旋转
				view.setRotation(0);

				this.map = map;
				this.mapServiceLoader = new MapServiceLoader(map);
				// 加载行政区
				this.mapServiceLoader.loadServices(this.getRegionLayerDataCounty());
				// this.xzqLoadLocal();
				this.map.on('click', (e) => {
					this.handleMapClick(e);
				})
				// 定位到行政区
				this.goToXzqLayer();
			},
			/**
			 * 影像生产-落图框显示标签改变
			 */
			tagSelectChangeProduce(e) {
				this.imagesGeom05LayersProduce && this.imagesGeom05LayersProduce.setVisible(e.tag05);
				this.imagesGeom1LayersProduce && this.imagesGeom1LayersProduce.setVisible(e.tag1);
				this.imagesGeom2LayersProduce && this.imagesGeom2LayersProduce.setVisible(e.tag2);
			},
			/**
			 * 影像分发-落图框显示标签改变
			 */
			tagSelectChangeDistribute(e) {
				this.imagesGeom05LayersDistribute && this.imagesGeom05LayersDistribute.setVisible(e.tag05);
				this.imagesGeom1LayersDistribute && this.imagesGeom1LayersDistribute.setVisible(e.tag1);
				this.imagesGeom2LayersDistribute && this.imagesGeom2LayersDistribute.setVisible(e.tag2);
			},
			/**
			 * 影像分发-加载落图框
			 */
			loadDropFrameDistribute({
				imagesGeom05,
				imagesGeom1,
				imagesGeom2,
				xzqdm,
			}) {
				const wktFormat = this.format;
				const that = this;
				// 移除之前的高亮图层
				if (this.mapServiceLoader) {
					this.mapServiceLoader.removeLayerBiyId(this.drop05DistributeId);
					this.mapServiceLoader.removeLayerBiyId(this.drop1DistributeId);
					this.mapServiceLoader.removeLayerBiyId(this.drop2DistributeId);
				}
				this.imagesGeom05LayersDistribute = null;
				this.imagesGeom1LayersDistribute = null;
				this.imagesGeom2LayersDistribute = null;

				if (imagesGeom05.length) {
					let features = [];
					imagesGeom05.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop05DistributeId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 300,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColorDistribute.imagesGeom05.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColorDistribute.imagesGeom05.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop05DistributeId;
					this.imagesGeom05LayersDistribute = vectorLayer;
					// vectorLayer.setVisible(false);
					this.map.addLayer(vectorLayer);
				}
				if (imagesGeom1.length) {
					let features = [];
					imagesGeom1.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop1DistributeId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 200,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColorDistribute.imagesGeom1.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColorDistribute.imagesGeom1.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop1DistributeId;
					this.imagesGeom1LayersDistribute = vectorLayer;
					// vectorLayer.setVisible(false);
					this.map.addLayer(vectorLayer);
				}
				if (imagesGeom2.length) {
					let features = [];
					imagesGeom2.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop2DistributeId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 100,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColorDistribute.imagesGeom2.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColorDistribute.imagesGeom2.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop2DistributeId;
					this.imagesGeom2LayersDistribute = vectorLayer;
					// vectorLayer.setVisible(false);
					this.map.addLayer(vectorLayer);
				}
				if (xzqdm == 530000) {
					const myset = setTimeout(function() {
						that.gotoDropLayers([this.drop05DistributeId, this.drop1DistributeId, this
							.drop2DistributeId
						]);
						clearTimeout(myset)
					}, 200);
				}
			},
			/**
			 * 影像生产-加载图框
			 */
			loadDropFrameProduce({
				imagesGeom05,
				imagesGeom1,
				imagesGeom2,
				xzqdm,
			}) {
				const wktFormat = this.format;
				const that = this;
				// 移除之前的高亮图层
				if (this.mapServiceLoader) {
					this.mapServiceLoader.removeLayerBiyId(this.drop05ProduceId);
					this.mapServiceLoader.removeLayerBiyId(this.drop1ProduceId);
					this.mapServiceLoader.removeLayerBiyId(this.drop2ProduceId);
				}

				this.imagesGeom05LayersProduce = null;
				this.imagesGeom1LayersProduce = null;
				this.imagesGeom2LayersProduce = null;

				if (imagesGeom05.length) {
					let features = [];
					imagesGeom05.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop05ProduceId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 300,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColor.imagesGeom05.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColor.imagesGeom05.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop05ProduceId;
					this.imagesGeom05LayersProduce = vectorLayer;
					this.map.addLayer(vectorLayer);
				}
				if (imagesGeom1.length) {
					let features = [];
					imagesGeom1.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop1ProduceId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 200,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColor.imagesGeom1.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColor.imagesGeom1.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop1ProduceId
					this.imagesGeom1LayersProduce = vectorLayer;
					this.map.addLayer(vectorLayer);
				}
				if (imagesGeom2.length) {
					let features = [];
					imagesGeom2.forEach((geom) => {
						features = [...features, ...wktFormat.readFeatures(geom)];
					});
					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: that.drop2ProduceId
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});
					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 100,
						style(feature) {
							let strokeWidth = 1;
							return new Style({
								fill: new Fill({
									color: that.dropColor.imagesGeom2.fillColor,
								}),
								stroke: new Stroke({
									color: that.dropColor.imagesGeom2.strokeColor,
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = this.drop2ProduceId;
					this.imagesGeom2LayersProduce = vectorLayer;
					this.map.addLayer(vectorLayer);
				}
				if (xzqdm == 530000) {
					const myset = setTimeout(function() {
						that.gotoDropLayers([this.drop05ProduceId, this.drop1ProduceId, this.drop2ProduceId]);
						clearTimeout(myset)
					}, 200);
				}
			},
			/**定位到行政区
			 */
			goToXzqLayer() {
				// console.log('定位到行政区');
				const extents = [97.52736740199998, 21.142140719999986, 106.19671131500002, 29.22577058899998];
				this.map.getView().fit(extents);
			},
			/**
			 * 开关图层显示
			 */
			setLayerVisible(layerId, visible) {
				const layer = this.mapServiceLoader.findLayerById(this.xzqId);
				if (layer) {
					layer.setVisible(visible);
				}
			},
			/**
			 * 根据id定位到图层
			 */
			positioningLayersById(layerId, isVisible = true) {
				const that = this;
				const layer = this.mapServiceLoader.findLayerById(layerId);
				if (layer) {
					const extents = layer.getSource().getExtent();
					this.map.getView().fit(extents, {
						duration: 1000
					});
				}
				const myset = setTimeout(function() {
					// 关闭主图
					that.setLayerVisible(that.xzqId, isVisible);
					clearTimeout(myset)
				}, 1000);
			},
			/**
			 * 服务-切换地图到选择行政区上
			 */
			selectAtiveRegion({
				geom,
				xzqdm,
				children,
			}) {
				const that = this;
				// console.log('服务-切换地图到选择行政区上', xzqdm);
				const cqlFilter = `xzqdm = '${xzqdm}'`;
				// 加载行政区
				this.mapServiceLoader.loadServices(this.getRegionLayerDataCounty(cqlFilter));
			},
			/**
			 * 定位到落图框
			 */
			gotoDropLayers(ids = [this.drop05ProduceId, this.drop1ProduceId, this.drop2ProduceId, this.drop05DistributeId,
				this.drop1DistributeId, this.drop2DistributeId
			]) {
				const allLayers = this.map.getLayers().getArray();
				let extents = [];

				allLayers.forEach((o, i) => {
					if (ids.includes(o['id'])) {
						extents = [...extents, ...o.getSource().getExtent()]
					}
				});
				if (extents.length) {
					this.map.getView().fit(extents, {
						duration: 500
					});
				} else {
					// 没有落图框,定位到行政区
					this.goToXzqLayer();
				}
			},
			/**
			 * 行政区地图加载本地json
			 */
			xzqLoadLocal() {
				// 创建 GeoJSON 图层
				const geoJSONLayer = new VectorImageLayer({
					source: new VectorSource({
						url: "../../static/XZQ_2K.json",
						format: new GeoJSON()
					}),
					style: new Style({
						stroke: new Stroke({
							color: "#ff0000", // 描边红色
							width: 2 // 设置描边宽度为 1 像素
						}),
						fill: new Fill({
							color: "#ff000020" // 填充红色透明
						})
					})
				});
				console.log('geoJSONLayer', geoJSONLayer.getSource().getFeatures());
				geoJSONLayer.id = this.xzqId;
				geoJSONLayer.setVisible(false);
				this.map.addLayer(geoJSONLayer);
			},
			/**
			 * 行政区geom-切换地图到选择行政区上
			 */
			selectAdministrativeRegion({
				geom,
				xzqdm,
				children,
			}) {
				const isYns = xzqdm == 530000;
				let isYnsTrue = null;
				if (this.mapServiceLoader) {
					// 省显示地图是否存在
					isYnsTrue = this.mapServiceLoader.layersIsTrueById(this.xzqIdYns);
					// 移除之前的高亮图层
					this.mapServiceLoader.removeLayerBiyId(this.xzqHighlightId);
					if (isYnsTrue) {
						this.mapServiceLoader.setVisibleById(this.xzqIdYns, isYns);
					}
				}

				if (!isYnsTrue || !isYns) {
					if (!geom) {
						return;
					}
					const wktFormat = this.format;
					let features = [];
					if (children && children.length) {
						children.forEach((c) => {
							features = [...features, ...wktFormat.readFeatures(c.geom)];
						});
					} else {
						features = wktFormat.readFeatures(geom);
					}

					features.forEach((f) => {
						f.setProperties({
							cLayerStyleType: 'type1',
							type: 'region'
						});
					});
					const vectorSource = new VectorSource({
						features: [...features],
						strategy: bboxStrategy
					});

					const vectorLayer = new VectorImageLayer({
						source: vectorSource,
						zIndex: 10,
						style(feature) {
							let strokeWidth = 2;
							return new Style({
								fill: new Fill({
									color: '#E1F0FF',
								}),
								stroke: new Stroke({
									color: '#FFFFFF',
									width: strokeWidth,
								}),
							});
						},
					});
					vectorLayer.id = isYns ? this.xzqIdYns : this.xzqHighlightId;

					// this.mapServiceLoader.setVisibleById(this.xzqIdYns, isYns);
					this.map.addLayer(vectorLayer);
				}
				// 	// 移除之前的高亮图层
				// 	// this.mapServiceLoader && this.mapServiceLoader.removeLayerBiyId(this.xzqHighlightId);
				// 	// this.setLayerVisible(this.xzqId, true);
				// 	// this.goToXzqLayer();
				// if (xzqdm === 530000) {
				// 	this.map
				// }
				// 定位到行政区
				this.positioningLayersById(this.xzqHighlightId, false);
			},
			/**
			 * 影像点击事件
			 * 
			 * @param {Object} event
			 */
			handleMapClick(event) {
				console.log('点击:', event, event.coordinate);
			},
			/**
			 * 过滤行政区显示
			 */
			filterRegions() {
				console.log('过滤行政区显示')
			}
		},
		mounted() {
			this.innitMap();
		},
		onUnload() {
			// 移除地图实例
			this.map.dispose();
		}
	}
</script>

<style lang="scss" scoped>
	#myMap {
		padding: 0 $padding-base;
		margin-top: 30rpx;
	}
</style>

MapServiceLoader.js

import {
	Map
} from 'ol';
import {
	Tile as TileLayer,
	Vector as VectorLayer
} from 'ol/layer';
import {
	OSM,
	XYZ,
	Vector as VectorSource,
	ImageWMS,
	TileWMS,
	WMTS as sourceWMTS,
} from 'ol/source';
import {
	optionsFromCapabilities
} from 'ol/source/WMTS';
import {
	WMTS as tilegridWMTS
} from 'ol/tilegrid';

import {
	get as getProjection
} from 'ol/proj';
import {
	WMTSCapabilities
} from 'ol/format';

export class MapServiceLoader {
	map;

	wmtsOptionss = [];

	constructor(map) {
		this.map = map;
	}

	/**
	 * 获取当前的地图
	 */
	getMap() {
		return this.map;
	}

	/**
	 * 根据id查找图层
	 */
	findLayerById(id) {
		const layers = this.map.getLayers().getArray();
		// 使用自定义 id 属性查找图层
		return layers.find((layer) => layer.id === id);
	}


	/**
	 * 根据id移除图层
	 */
	removeLayerBiyId(layerId = null) {
		if (layerId) {
			const layer = this.findLayerById(layerId);
			if (layer) {
				this.map.removeLayer(layer);
			}
		}
	}

	/**
	 * 根据id显示或隐藏图层
	 */
	setVisibleById(layerId, isShow = true) {
		const layer = this.findLayerById(layerId);
		if (layer) {
			layer.setVisible(isShow);
		}
	}

	/**
	 * 根据id判断图层是否存在
	 */
	layersIsTrueById(layerId) {
		let isTrue = false;
		const layer = this.findLayerById(layerId);
		if (layer) {
			isTrue = true;
		}
		return isTrue;
	}

	async getWMTSLayerConfig({
		layerName,
		matrixSet,
		accessUrl,
		serviceType,
	}) {
		const response = await fetch(accessUrl);
		const text = await response.text();
		const parser = new WMTSCapabilities();
		let wmtsCapabilities = parser.read(text);
		const options = optionsFromCapabilities(wmtsCapabilities, {
			layer: layerName,
			matrixSet,
		});

		this.wmtsOptionss.push({
			url: accessUrl,
			ops: wmtsCapabilities
		});
		return options;
	}

	/**
	 * @param {Object} serviceConfigs
	 * 
	 */
	async loadServices(serviceConfigs) {
		const {
			layerName,
			matrixSet,
			accessUrl,
			serviceType,
			otherPara,
		} = serviceConfigs;
		let layer = null;
		if (serviceType == 'wmts') {
			const options = await this.getWMTSLayerConfig(serviceConfigs);
			layer = new TileLayer({
				source: new sourceWMTS(options)
			})
		} else if (serviceType == 'wms') {
			console.log('otherPara', otherPara);
			const source = new TileWMS({
				url: accessUrl,
				params: {
					...otherPara
				},
			});
			layer = new TileLayer({
				source,
			});
		} else {
			console.error('serviceType类型错误')
		}
		this.removeLayerBiyId(serviceConfigs.id);
		console.log('layer', layer);
		layer.id = serviceConfigs.id;
		this.map.addLayer(layer);
	}
}

ol依赖放到跟目录
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1513390.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数字图像处理 使用C#进行图像处理九 实现傅里叶变换

一、简述 傅立叶变换将图像分解为其正弦和余弦分量。换句话说,它将图像从空间域变换到频率域。这个想法是任何函数都可以用无限正弦函数和余弦函数之和来精确近似。傅里叶变换是实现此目的的一种方法。 网上有很多关于傅里叶变换的文章,这里就不进行赘述了,这里主要结合代码…

JS:36种原生JS数组方法(8种改变原数组方法,28种不涉及数组改变的方法)

一、改变原数组方法 1.push() 作用&#xff1a;向数组的末尾添加一个或多个元素 返回&#xff1a;添加后数组的长度。 <script>let arr [1, 2, 3];console.log(arr.push(4)); //4console.log(arr); //[1, 2, 3, 4]console.log(arr.push(2, 4)); //6console.log(arr);…

cad转shp再转3dtiles生成白模

1、准备CAD数据 2、arcgis中添加cad数据 添加面 cad中的标高字段是能带进arcgis中的&#xff0c;如果这个数据是建筑高度&#xff0c;可以直接用了 3、转shp 4、shp转3dtiles白模 cesiumlab中shp转3dtiles白模效果一

新零售SaaS架构:什么是线上商城系统?

零售商家为什么要建设线上商城 传统的实体门店服务范围有限&#xff0c;只能吸引周边500米内的消费者。因此&#xff0c;如何拓展服务范围&#xff0c;吸引更多消费者到店&#xff0c;成为了店家迫切需要解决的问题。 缺乏忠实顾客&#xff0c;客户基础不稳&#xff0c;往往是…

buuctf warmup

1.代码审计&#xff1a; <?phphighlight_file(__FILE__);class emmm //定义了一个类{public static function checkFile(&$page) 类里面又申明创建了一个函数{$whitelist ["source">"source.php","…

安装汇春MDTIDE以及HI-TECH PICCv9.83(PICC语言编译器)

最近了解了汇春一款8位通用型MCU----MDT10F684&#xff0c;所以这里安装一下IDE以及配置一下环境。 1.安装汇春MDTIDE 去到官网下载对应的开发包&#xff0c;我不知道里面内容是否一致。 Flash/MTP MCU (yspringtech.com) 不要点说明书下载&#xff0c;点了没反应&#xff0…

借助ChatGPT提高编程效率指南

PS: ChatGPT无限次数&#xff0c;无需魔法&#xff0c;登录即可使用,网页打开下面 一、借助ChatGPT提高编程效率指南 随着计算机技术的飞速发展&#xff0c;编程已经成为了现代社会中一个非常重要的技能。对于许多人来说&#xff0c;编程不仅是一项工作技能&#xff0c;而且是…

docker之自己制作jdk镜像

一&#xff0c;下载想要制作的镜像的对应jdk&#xff08;自行下载&#xff09;&#xff0c;本文使用jdk17&#xff08;因为自己的springboot项目时在jdk17下开发的&#xff0c;悲&#xff01;&#xff01;&#xff01;&#xff0c;再加上没有在官网上找到对应镜像&#xff0c;只…

ubuntu22.04 在wifi网络正常使用的情况下创建热点连接

ubuntu22.04 在wifi网络正常使用的情况下创建热点连接 在ubuntu22.04版本中正常通过设置打开wifi热点会取消正常的wifi网络连接 接下来让我们一起尝试在wifi网络正常的情况下创建热点连接 查看硬件是否支持 iw list | grep AP #查看是否支持AP模式 Device supports AP-side…

小米官网登录注册的滑动效果

小米官网登录注册的滑动效果 登录组成页面 <div class"client"><div class"userbox"><div class"title"><a href"javascript:;" class"active" id"DL">登录</a><a href&quo…

250+可用的 AI 资源网站

&#x1f482; 个人网站:【 海拥】【神级代码资源网站】【办公神器】&#x1f91f; 基于Web端打造的&#xff1a;&#x1f449;轻量化工具创作平台&#x1f485; 想寻找共同学习交流的小伙伴&#xff0c;请点击【全栈技术交流群】 这里是关于AI网站的一份资源列表。欢迎访问该链…

message: apoc.meta.data is unavailable

报错内容 Traceback (most recent call last):File "/langchain-master/templates/neo4j-semantic-ollama/ingest.py", line 9, in <module>graph Neo4jGraph()File "/root/anaconda3/envs/sakura/lib/python3.9/site-packages/langchain_community/gra…

智慧农业新篇章:DSSAT模型、APSIM模型、WOFOST与PCSE模型综合应用,引领作物生长模拟与产量预测新潮流

目录 ★WOFOST模型与PCSE模型应用 ★基于R语言APSIM模型进阶应用与参数优化、批量模拟 ★最新DSSAT作物模型建模方法及应用 ★基于Python语言快速批量运行DSSAT模型及交叉融合、扩展应用 ★R语言与作物模型&#xff08;以DSSAT模型为例&#xff09;融合应用 ★遥感数据与…

酷开科技以消费者需求为导向冲刺OTT行业的星辰大海

通过大屏营销、互动营销等方式&#xff0c;提升品牌认知度和市场竞争力。酷开科技始终坚持以消费者的需求为导向&#xff0c;致力于为品牌方和消费者搭建高效、准确的沟通桥梁&#xff0c;开创OTT大屏营销新纪元。 伴随技术发展&#xff0c;智能电视已经从“尝鲜”变成了主流产…

C# Web自动化--Selenium入门

安装依赖库 需要引用的核心库是Selenium.RC&#xff0c;Selenium.Support&#xff0c;Selenium.WebDriver 然后再需要引用 浏览器驱动库&#xff0c;这里我以IE浏览器为例&#xff0c;Chrome使用方式跟IE是一样的&#xff0c;程序包名称为Selenium.WebDriver.ChromeDriver。 …

静电ESD整改:原因、影响与解决方案详解?|深圳比创达电子

静电&#xff08;ESD&#xff09;是在日常生活和工作中常见的现象&#xff0c;但它可能对电子设备和器件造成严重的损坏。本文将介绍静电ESD的定义、原因、影响以及解决方案&#xff0c;帮助大家更好地了解ESD问题&#xff0c;并采取相应的整改措施。 一、静电ESD的定义 静电…

技术驱动校园招聘:Java+SpringBoot+Vue的实践之旅

✍✍计算机编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java实战 |…

【Linux操作系统】:Linux进程概念(2)

一、Z(zombie)-僵尸进程 1.僵尸进程概念 故事 张三每天都有跑步的习惯&#xff0c;这一天他和往常一样跑步&#xff0c;跑了两三圈&#xff0c;突然跑在它前面的一个人倒在地上不动了&#xff0c;作为热心市民张三赶紧报警并且拨打120。很快120就来了&#xff0c;但是没过几分…

Docker单机下的容器网络管理

Docker容器网络管理 容器网络类型 Docker安装以后&#xff0c;会在我们的主机上创建三个网络 docker network ls可以看到有bridge、host和none三种网络类型 我们先把ubuntu的网络环境配置一下 docker run -it ubuntu apt update apt install net-tools iputils-ping curl这…

移速u盘怎么恢复彻底删除的文件,移速u盘彻底删除的文件如何恢复

移速u盘怎么恢复彻底删除的文件&#xff1f;在日常使用中&#xff0c;我们经常会遇到需要删除U盘中的文件的情况。然而&#xff0c;有时候我们可能会不小心将重要的文件彻底删除&#xff0c;导致数据的丢失。对于移速U盘用户来说&#xff0c;如何恢复彻底删除的文件成为了一个备…