In form-display configuration for a content type, one can set the default zoom and styling of a Geolocation Google Geocoder, but I can't see a way to set the initial center of the map, which defaults at sea at 0,0.

It would be great to be able to set a center by lat/lng. This would not set the geolocation field value, but would just center the map so that users could avoid dragging the map a lot to figure out where they want to place a marker.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juliencarnot created an issue. See original summary.

ChristianAdamski’s picture

Sounds good. Patch welcome :)

ChristianAdamski’s picture

Oh, actually, while you are at this: we might also add an option to trigger the client location automatically, if no value is set yet? Sounds useful to me, aye?

juliencarnot’s picture

Ok, gave it a try, wasn't that complicated following your example! ;-)

I separated lat and lng in 2 fields to clarify syntax, and took the liberty to set default zoom at 5, so that the default map at 0,0 is easier to identify and pan...

Works for me, hope it will for you!

As for the automatic client location, wouldn't that overlap with https://www.drupal.org/node/2777753 ? I'll give it a try later but I'm really not sure I'll manage to tackle that one!

juliencarnot’s picture

Status: Active » Needs review
ChristianAdamski’s picture

Status: Needs review » Needs work

Hey Julien,

thanks for the effort. This does not work though. The Google Settings stuff is used for all maps, including the common map stuff which has it's very own magic to determine the center.

The settings for lat/lng have to explicitly be tied to the google geocoder widget.

I think it's not hard. Just move the settings to the widget and alter the widget JS.

juliencarnot’s picture

Well, that was looking too good to be true! ;-) It didn't seem to affect my common map views but it is indeed in the views settings...

Thanks for taking time to review the patch, explain the problem and point to the solution. I've just had a look at GeolocationGooglegeocoderWidget.php and geolocation-widget-googlegeocoder.js but I don't really see where/how to move this and I don't have enough time right now to figure it out by trial and error.

If somebody with actual coding skills wants to give it a try, I'll be happy to learn how it should have been done and to test it!

ChristianAdamski’s picture

- shuffled some stuff around, minor typo fixes, separated coder a little more where due, added correct description
- added default Lat Lng to geocoding widget
- added option to trigger client location on load when value not yet set
- added option to set marker at said position, when former option is enabled
- fixed weired CSS for map controls location indicator
- added schema where due (hopefully)

Please test.

  • ChristianAdamski authored 4d86bc1 on 8.x-1.x
    Issue #2804385 by juliencarnot, ChristianAdamski: Add default center...
ChristianAdamski’s picture

Status: Needs review » Fixed

Comitted. Let's see what breaks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.