Writing style function in OpenLayers?
ran into some problems with the = signs. this is working for me
var customStyleFunction = function(feature, resolution) {
if(feature.get('WELL_CLASS')=== 'EXISTING') {
strokecolor = '#020815';
} else if(feature.get('WELL_CLASS')=== 'PROPOSED') {
strokecolor = '#f61212';
} else if(feature.get('WELL_CLASS')=== 'INJECTION') {
strokecolor = '#198cff';
}
return [new ol.style.Style({
image: new ol.style.Circle({
fill: new ol.style.Fill({
color: '#1b465a'
}),
stroke: new ol.style.Stroke({
color: strokecolor,
width: 3
}),
radius: 5
})
})];
};
and here is the layer definition:
var wellsLayer = new ol.layer.Vector({
source: new ol.source.GeoJSON({
projection: 'EPSG:3857',
url: "./data/WELLS.geojson"
}),
name: 'Wells',
style: customStyleFunction
});
Try this change to your layer definition:
var wellsLayer = new ol.layer.Vector({
source: new ol.source.GeoJSON({
projection: 'EPSG:3857',
url: 'data/WELLS.geojson'
}),
style: customStyleFunction // "style:" is inserted and ',' is removed
});