openlayers - 如何在 openalyer 6 中用矢量图层遮盖图像层?
问题描述
我有一个带有矩形图像的图像层。我想用矢量图层掩盖这个图像,使其适合边界内。我已经尝试过这个https://gis.stackexchange.com/questions/185881/clipping-tilelayer-with-georeferenced-polygon-clipping-mask 但它似乎是一个正常的 vecotr 图层叠加。我想掩盖一个图像层。我的图像层是:
var ext = [677276.6184634935, 998535.6531789962, 680930.1784387273, 1001712.63214407];
var imageLayer = new ImageLayer({
source : new Static({
title: 'imageee',
url: '/static/wetlandapp/images/idw/idw.png',
crossOrigin: 'anonymous',
projection: 'EPSG:32643',
imageExtent: ext,
imageSmoothing: true,
}),
//opacity: 0.9,
});
map.addLayer(imageLayer);
map.getView().fit(ext);
我使用 ol-ext 添加了掩码,如下所示:
var dep = data.features[0];
var coords = dep.geometry.coordinates;
var f = new Feature(new MultiPolygon(coords));
var maskk = new Mask({ feature: f, inner:false, fill: new Fill({ color:[255,255,255,0.8] }) }); //, opacity: 0.1
imageLayer.addFilter(maskk);
maskk.fillColor_ = 'rgba(0,255,0,0.2)';
maskk.set('active', true);
并添加图层剪辑如下:
var clipLayer = new VectorLayer({
style: null,
source: new VectorSource({
features: new GeoJSON().readFeatures(data, {
dataProjection: 'EPSG:32643',
featureProjection: 'EPSG:32643',
}),
}),
});
clipLayer.getSource().on('addfeature', function () {
imageLayer.setExtent(clipLayer.getSource().getExtent());
});
var style = new Style({
fill: new Fill({
color: 'black',
}),
});
imageLayer.on('postrender', function (e) {
var vectorContext = getVectorContext(e);
e.context.globalCompositeOperation = 'destination-in';
clipLayer.getSource().forEachFeature(function (feature) {
vectorContext.drawFeature(feature, style);
});
e.context.globalCompositeOperation = 'source-over';
});
map.addLayer(clipLayer);
问题在于剪辑,所有其他区域的图层都不可见。而在 masking 中,图像层没有被屏蔽完成,但所有其他层都是可见的。我想要一个输出,比如在启用所有其他图层的剪辑中/应该是可见的。
解决方案
推荐阅读
- c# - 如何将列添加到已经存在的超网格?
- javascript - 使用 JavaScript 从 URL 获取产品 ID
- r - 使用 ggplot 和拼凑而成的嵌套图的中心标签
- python - 如何在mysql表中添加数据
- powershell - 使用 Powershell 将用户从多个 AD 组复制到新的 AD 组
- r - 如何将ggplot构面保存为单独的对象和文件
- javascript - 存在休息时响应文本始终为空事件
- wordpress - 我在博客中的内容又重复了一次
- python - Numpy数组重塑自定义python
- mysql - : 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在“app”附近使用的正确语法)