-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to remove search pin? #13
Comments
The seach pin of ol-geocoder.js will be added to a layer named "geocoder-layer-....". function remove_search_pin() {
var remove_layer_name = 'geocoder-layer';
var layers_to_remove = [];
map.getLayers().forEach(function(layer) {
var layer_name = layer.getProperties().name;
if (layer_name && layer_name.match(remove_layer_name)) {
layers_to_remove.push(layer);
}
});
for (var i = 0; i < layers_to_remove.length; i++) {
map.removeLayer(layers_to_remove[i]);
}
} After Geocode I called this function using Chrome's DevTools. |
Thanks for figuring this out! Can you wire this up so that you can click on the pin to remove it and send me a pull request? Would be great! |
I am not too happy about the extra button. It adds cognitive load for the user, especially because its use is not obvious and it does nothing until you actually use the search function. Maybe this is something we need to add upstream to the ol-geocoder instead of trying to fix this here. |
I agree with that idea too. I found 'propertychange' event on map.getLayers() on OpenLayers, added function that hook this event and change css for pin remove button when geocoding at bcd3546 But my code may be a little redundant.
|
Thanks, this looks good now. I have merged this. We can always improve on this later, if the upstream ol-geocoder adds some functionality. |
Thank you for the information. This helps to remove or clear the mark when I hit the clear button. However, in my case, the geocoder also shows a popup of the address of the pin. ` var geocoder = new Geocoder('nominatim', { geocoder.on('addresschosen', function(evt) { function clear_all() {
} |
When using the search a pin will be set on the map. There is currently no way to remove the pin.
The text was updated successfully, but these errors were encountered: