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();
	}
相关推荐
用户84298142418106 小时前
从 JavaScript 到可运行的字节码 - ByteJS 使用指南
javascript
OpenTiny社区6 小时前
AI Agent场景组件库 TinyRobot v1.0 正式发布:一站式打造您的AI助手
vue.js·github
学以智用7 小时前
wangEditor V5 精简完整参考手册
javascript
用户298698530147 小时前
React 前端实现 Excel 与 CSV 互转:基于 WebAssembly 的浏览器端方案
javascript·react.js·excel
ruanno_top1 天前
轮播每 3 秒自己翻页:键盘停不下来,读屏也不知道换了页
vue.js
1-1=01 天前
Vue 3 模板语
前端·javascript·vue.js
风卿1 天前
看着AI写代码太孤独了,来欣赏星云吧:一个DSH 装饰插件
前端·javascript
牧艺1 天前
弹层不用再手算坐标了:CSS Anchor Positioning 从原理到可上线
前端·javascript·css
Java小卷1 天前
面向 Schema 编程,Vue 3 页面级渲染引擎!轻松玩转各场景 Validation!
vue.js·低代码