Is it possible to reset or clear the map and plot new points? I have a search box that am using to query a geojson API.
After the first mapped result, the second search is plotted in addition which I do not want. What I want to achieve is, if I search, that result should be plotted not all subsequent searches I make.
Is there a way, to overwrite that first plotted result or remove it before plotting a new search result?
button.addEventListener('click', function(e) {
inputVal = input.value;
// console.log(inputVal);
getPointLayer = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://0.0.0.0:5000/api/v1/dumela/' + inputVal,
format: new ol.format.GeoJSON()
}),
style: styleFunction
});
var layersOnMap = map.getLayers();
// reset the map, clear all point
if (layersOnMap) {
map.removeLayer(getPointLayer);
}
console.log(layersOnMap.length);
map.addLayer(getPointLayer);
});