wp-plugin-leaflet-map icon indicating copy to clipboard operation
wp-plugin-leaflet-map copied to clipboard

Address filter refocus map

Open shaneonabike opened this issue 3 years ago • 1 comments

Hey there,

This is more of a question then a bug, but I was curious if others had implemented a address box whereby the address would be geocoded and then the map moved within range of points.

I see that in the API of this plugin you create a geocoder for addresses through Google Maps, but I wasn't sure if others had done some fancy JS or something else to make a filter like this work. I think it's an awesome addition really.

Thanks!

shaneonabike avatar Feb 14 '22 18:02 shaneonabike

I'm sure there's some simple PHP to do it; might be worth adding to the FAQ; but I have not implemented this.

bozdoz avatar Feb 14 '22 19:02 bozdoz

I suppose this is a question of whether we can use the geocoder via Ajax. Seems worth trying.

bozdoz avatar Dec 31 '22 15:12 bozdoz

I actually found https://github.com/smeijer/leaflet-geosearch which can be integrated into the Leaflat map and this extension.

shaneonabike avatar Feb 02 '24 15:02 shaneonabike

Do you know this example?

hupe13 avatar Feb 03 '24 07:02 hupe13

Wow @hupe13 that totally helped me. Just for reference for other folks. I'll dd the code here to make it easier when discovering this issue.

const search = new GeoSearch.GeoSearchControl({
    provider: new GeoSearch.OpenStreetMapProvider({
        params: {
            // email: "[email protected]", // auth for large number of requests
            "accept-language": "de", // render results in German
            countrycodes: "de", // limit search results to Germany
            addressdetails: 1, // include additional address detail parts
        },
    }),
    //more options see https://github.com/smeijer/leaflet-geosearch, search "Show result"
    updateMap: false,
});
map.addControl(search);
map.on("geosearch/showlocation", function(event){
    map.setView([event.location.y, event.location.x], 17);
});

The key here being that we want to turn off updating the map via updateMap: false. Then we set the view based on the geosearch/showlocation action.

shaneonabike avatar Feb 08 '24 18:02 shaneonabike

I have just seen that my example did not work, now it works again. Thank you.

hupe13 avatar Feb 08 '24 18:02 hupe13