vue中openlayers过滤高亮显示某个图层

vue中openlayers过滤高亮显示某个图层

openlayers库没有直接支持这样设置,所以可以使用库:ol-ext ,地址:https://viglino.github.io/ol-ext/examples/filter/map.filter.crop.html

效果:


关键代码:

js 复制代码
	/**
	 * 对绘制的区域做高亮显示,过滤其他图层
	 * 使用 Crop filter
	 */
	applyCropFilter(wktString) {
		const wktParser = new WKT();
		const feature = wktParser.readFeature(wktString);
		const cropExtent = feature.getGeometry().getExtent();
		this.cancelCropFilter();

		// -------裁剪过滤---------
		// this.cropFilter = new Crop({
		// 	feature: feature,
		// 	inner: false,
		// 	shadow: true,
		// });
		// -------高亮过滤---------
		this.cropFilter = new Mask({
			feature: feature,
			inner: false,
			shadow: true,
		});

		this.map.getLayers().forEach((layer) => {
			const lId = layer.id;
			// 这里是排除不进行过滤的图层
			if (lId && lId !== GLOBAL_VARIABLE.geoserverLayers.SSQDT.name) {
				layer.addFilter(this.cropFilter);
			}
		});
		this.map.render();
	}
	
	/**
	 * 恢复图层,取消过滤
	 */
	cancelCropFilter() {
		this.map.getLayers().forEach((layer) => {
			if (this.cropFilter) {
				layer.removeFilter(this.cropFilter);
			}
		});
		this.map.render();
	}
相关推荐
excel8 小时前
研究 Vue 3 源码的收获
前端·vue.js
lerhxx10 小时前
AI 应用如何高效优雅地恢复中断?—— "连接解耦 + 状态持久化"
前端·javascript
mantou13211 小时前
我给 AI Agent 做了个「油猴」:让 Claude Code / Codex 直接用你已登录的浏览器
前端·javascript·后端
默_笙11 小时前
🍕 一个主编、三个工种、两本手册:搭一支 AI 调研队
前端·javascript
CappuccinoRose12 小时前
FormData数据处理
开发语言·前端·javascript·表单数据
飘尘13 小时前
SVG和Canvas,前端里的两支“画笔”,用的时候怎么选择?
前端·javascript·面试
vx-程序开发15 小时前
【计算机毕设】51300童装超市管理系统的设计与实现
java·vue.js·spring boot·源码·课程设计·毕设·大作业
ym hyd 11116 小时前
题库建立与考试系统源码 Java+SpringBoot+Vue3 前后分离
java·开发语言·vue.js·spring boot·毕设
Sand(ContextGate)17 小时前
Python Agent 测试实战:测试与评估,让 Agent 像传统软件一样可交付
前端·javascript·python·microsoft·ai
码艺-Alimjan17 小时前
Tauri 网站To桌面应用实战总结
前端·javascript·vue