[英]Using a vector layer as an input to a raster source in openlayers
我正在嘗試將矢量要素用作Openlayers 5中柵格源的遮罩。(我只想對用戶可以動態選擇的特定管轄范圍內的柵格數據進行計算。)為此,我嘗試使用將具有我的特征的矢量層作為柵格源的輸入,然后測試每個像素以查看是否存在遮罩。
文檔指出,如果將矢量層配置為選項renderMode: 'image'
,則應該可行。 但是,當柵格圖層嘗試運行時,出現TypeError: h.getImage is not a function
。
我的代碼如下:
// The base raster data
var arc = new TileArcGISRest({
params: {
'LAYERS': "view:0"
},
url: myDataURL,
crossOrigin: 'anonymous',
});
// The vector mask in GeoJSON format
var town_vector = new ol.source.Vector({
url: 'towns.json',
format: new ol.format.GeoJSON(),
});
// The layer based on that vector
var town_layer = new ol.layer.Vector({
title: 'added Layer',
source: town_vector,
renderMode: 'image',
style: interest_style,
});
// The raster source that attempts the analysis
var summary_raster = new RasterSource({
sources: [arc, town_layer],
operation: function (pixels, data) {
var pixel = pixels[0];
var mask_pixel = pixels[1];
if (mask_pixel[0] == mask_value) {
run_calculation(pixel)
}
},
lib: {
run_calculation: run_calculation,
}
});
當我從源代碼中刪除“ town_layer”並消除掩蔽邏輯時,它可以完美工作。 但是,當我將“ town_layer”添加到柵格源時,會出現上述TypeError: h.getImage is not a function
。 如何“柵格化”此矢量圖層並將其用作柵格源的輸入?
它指出ol.source.ImageVector已從v4.5.0中棄用,建議使用ol.layer.Vector。 它對我有用。(我使用的是openlayers v6.0 )請嘗試使用v6.0,它也可能對您有用 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.