I'm trying to use vector features as a mask for a raster source in Openlayers 5. (I want to do calculations on raster data only within specific jurisdictions, which are dynamically selectable by the user.) To do this, I tried to use the vector layer with my features as an input to the raster source, and then test each pixel to see if the mask is present.
The documentation indicates that this should be possible if the vector layer is configured with the option renderMode: 'image'. However, when the raster layer attempts to run I get a TypeError: h.getImage is not a function.
My code is as follows:
// 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,
}
});
It works perfectly when I remove the "town_layer" from the source, and eliminate the masking logic. However, when I add the "town_layer" to the raster source I get the aforementioned TypeError: h.getImage is not a function. How can I "rasterize" this vector layer and use it as in input to the raster source?
ol.layer.Vectorwithol.layer.VectorImageand using OL version 6 beta looks like the only reliable way of getting it to work. - Mikenpm install [email protected], and usedol/layer/VectorImage. There are no errors in the console, but the map fails to render entirely. Do you have any recommendations on what to do to get this working? - Zach Balleisen