The simpler media website CMS
Hi!
Can you give some code examples to use callback function to set map options with printGoogleMap function.
For instance, I would like to activate the auto zoom, modify map options etc. For some reason the zoom of the map is not correct.
Thanks!
Comments
You create a function that takes and modifies the
$map
object created within that function on line 387. The callback is then used in line 423.I have never used this as I favor if the openstreetmap plugin.
It should IMHO work like this. $map must be used as a reference as far as I see:
Create a function like
Then use
Easier way might be to use the actual GoogleMap class directly instead of
printGoogleMaps)
which is just a convenience wrapper of that anyway. There you can directly pass your configuration to it without this callback workaround. Usage example within that function itself.I have tried but it does not seem to work, it all clears my pins:
Do I need to return the $map object?
Try the correct parameters ;-) The callback is the 5th paramater ;-)
No, should not, the callback use does not use any return. That's why it is ipassed by reference in my example reason actually. Again, I never tried this actually. Perhpas try using the class directly, it is not that much more complicated.
Just curious:
Is
$map->zoom = 'auto';
what you are trying to do? Because that should already have been done in the default setup.Thanks @acrylian and sorry for the beginner mistake ;-).
When calling the callback function ($map->zoom = 'auto'), I have this error message that I don't understand:
AVERTISSEMENT : Parameter 1 to mapcallback() expected to be a reference, value given dans server_path/zp-core/zp-extensions/GoogleMap.php à la ligne 423
printGoogleMap called from include (album.php [133])
If it is not working well, I will use the class directly as you advise...
@sbillard I am trying to force the auto zoom feature as it does not work for me by default all the time. I would like also to change the height of the map too but I am not sure if it is possible using the $map object but javascript....
Thanks guys for your support anyway ;-)
I must precise that when I set $map->zoom = 15; it works but with the same warning. Forcing to auto does not work as default behaviour does not work either...
I just took a look. Please try changing line 423 within
printGoogleMap()
where it readscall_user_func($callback, $map);
to
call_user_func($callback, &$map);
Or the callback must return $map like
$map = call_user_func($callback, $map);
instead. But the result will be the same.
Since we call a function via function it probably requires an extra reference definition here.
Within the template function "auto" is actually hardcoded as mentioned above. If it does not work perhaps it works but for some reason not as expected?
That can be done by adding a rule for
#map_canvas
in your CSS.When objects are passed as parameters for all practical purposes they are passed by reference, (https://www.php.net/manual/en/language.oop5.references.php) so the code presented by acrylian is redundant. The callback function will modify the actual map object.
The real issue seems to be the interpretation of the $map->zoom="auto" setting. In reality, this is used to invoke fitting the map to the bounds of several geopoints. As noted above, zoom="auto" is set by default. But if there is only one getpoint it will be overridden and set to 13 because the fitting fails miserably. There is no possibility of automatically zooming to contain only one point. (Note also that if you examine the javascript code generated, the javascript zoom option will always be set to 13 if the map object zoom property was set to 'auto'. Automatic zooming only occurs if there are multiple geopoints. I do not know why 13 was selected, seems arbitrary, but it does work.)
Indeed it is.
Thank you guys. I have found what I need!
@acrylian I have choosen googlemap because openstreetmap plugin even if it was my choice at first place does not load map tiles correctly with bootstrap 4 js when map is displayed in a tab panel. It looks like js order loading issue I guess... but it is fine anyway with googlemap.