I generate a map layer with the following code:
var GeoJSON = {};
GeoJSON.type = "FeatureCollection";
GeoJSON.features = [];
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: "~/icons/delivery-truck.png"
}))
});
for (var i = 0; i < data.length; i++) {
var machineGeoObject = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [data[i]["longitude"], data[i]["latitude"]],
},
"properties": data[i],
"style": iconStyle
}
GeoJSON.features.push(machineGeoObject);
} //end of loop
var format = new ol.format.GeoJSON({
featureProjection: "EPSG:3857"
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
features: format.readFeatures(GeoJSON)
})
});
map.addLayer(vector);
There is no error. When I call map.getLayers()
in the console, I see the added layer. The layer's property 'visible' is true. Why can't I see the pinpointed locations with icons on the map? Why do I only see a bare map?