i need some help to set icons to vectors in my map. I mean when map loads it shows different icons depending of property "station" in GeoJson. Using "for" I've got the name station and set a variable to store the path to get the icon. In console it shows the correct path but when i try to use it openlayerIcon as src it takes the last variable.
let startDatajson = (new ol.format.GeoJSON({
dataProjection : 'EPSG:4326',
featureProjection: 'EPSG:3857',
})).readFeatures(startJson);
let stationStartSource = new ol.source.Vector({
features: startDatajson
});
var onLoadSrc;
var getLoadStation = startDatajson.length;
for(i=0;i<getLoadStation;i++){
var getStation = startDatajson[i].get("Station");
if(getStation == "NNAA"){
onLoadSrc="assets/img/alert-smaller.png";
}else{
onLoadSrc="assets/img/blue-triangle.png";
}
/* switch(getStation){
case "NNAA": onLoadSrc="assets/img/alert-smaller.png";
break;
case "LIM027": onLoadSrc="assets/img/blue-triangle.png";
break;
} */
console.log(getStation);
console.log(onLoadSrc);
}
/* creating image as style */
var startIconStyle = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5,0.5],
size: [28,19],
offset: [1,1],
scale: 1,
src: onLoadSrc,
})
});
/* creating vector and adding image on style created before */
startStationsLayer = new ol.layer.Vector({
source: stationStartSource,
visible:true,
title:"ultimasEstaciones",
style: startIconStyle,
});
map.addLayer(startStationsLayer);