mcguffin / acf-openstreetmap-field

WordPress ACF Field for OpenStreetMap
https://wordpress.org/plugins/acf-openstreetmap-field/
GNU General Public License v3.0
107 stars 22 forks source link

Be able to setView() on marker-geocode-result event #122

Open Cyrille37 opened 2 months ago

Cyrille37 commented 2 months ago

Hi @mcguffin

It would be nice to be able to call map.setView() in marker-geocode-result for customization.

Perhaps reversing these two lines would be enough ?

// map-input.js
//   initGeocode()
//     this.geocoder

this.el.dispatchEvent( new CustomEvent( 'osm-editor/marker-geocode-result', { detail: {  model, geocode: e.geocode, previousGeocode } } ), { bubbles: true } )

this.map.setView( latlng, this.map.getZoom() ); // keep zoom, might be confusing else

My first thought was to use getBounds() if this.config.max_markers == 1 like :

if ( this.maxMarkers === 1 ) {
  this.map.setView( latlng, 17 );
} else {
  this.map.setView( latlng, this.map.getZoom() ); // keep zoom, might be confusing else
}

this.el.dispatchEvent( new CustomEvent( 'osm-editor/marker-geocode-result', { detail: {  model, geocode: e.geocode, previousGeocode } } ), { bubbles: true } )

Thanks & cheers