I am utilizing two maps, one is where someone could add or remove features (admin file) and another that the end-users would see (user file). However, I have no way to save the features I added in my admin file upon refreshing in my browser.
I wanted to know if there's a way to save features and pull them up again (for both files)?
//the main map of the app
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-90.055, 35.147]),
zoom: 17,
})
});
//---------------------------------------------------------
//---------------------------------------------------------
///this creates the markers for the map
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat([-90.055, 35.147])),
name: 'Somewhere else'
});
iconStyle = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'icon.png',
})
});
//Sets specific style for that one point
iconFeature.setStyle(new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'icon.png',
})
}));
eventFeature.setStyle(new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'icon.png',
})
}));
var eventLayerSource = new ol.source.Vector({
features: [iconFeature]
});
//individual layers for the user to switch through based on selection
var event_Layer = new ol.layer.Vector({
source: eventLayerSource,
// style for all elements on a layer
style: new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'icon.png'
})
}),
visible: true,
tab_name: 'event'
});
// display popup on click
map.on('click', function (evt) {
var coordinate = evt.coordinate;
console.log(evt.coordinate);
console.log(ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326'));
});
map.on('singleclick', function (evt) {
var lonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
var clickFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat(lonLat)),
name: window.prompt("Enter name of event","Event name"),
});
clickFeature.setStyle(iconStyle);
clickFeature.setId(clickFeature.get('name'));
eventLayerSource.addFeature(clickFeature);
});
map.on('dblclick', function(evt){
eventLayerSource.removeFeature(
eventLayerSource.getFeatureById(prompt("Enter name")));
})
This is my code for the admin file. I appreciate any insight as I am new to Openlayers.