From 543c5b2951441b5235c194d2f52021e4546cc1bc Mon Sep 17 00:00:00 2001 From: Stefan Grassberger Date: Wed, 13 Nov 2024 18:22:49 +0100 Subject: [PATCH] User geolocation in Google Maps (#784) * Add checkbox for user geolocation location * Move control into map, multiple map support * Add mylocation parameter * Draw circle for my location, replacing marker * Update my location accuracy on every update * Fix my location circle position update * Fix map centering every time my location updates * Use icon for my location toggle * Add translation string * Add marker to user location * Follow user on map per default, stop following on drag * Fix AJAX markers not updating on re-center * Add translation string * Store my location setting in localStorage, global for all maps * Temp: Disabled locked location, disable zoom into location * Center on location on button press * Store follow my location option per map, add mylocationfollow parameter * Cleanup * Add my location zoom parameter * Add to existing module * Add to existing module * Add translation string --- extension.json | 4 +- i18n/en.json | 4 + resources/GoogleMaps/googlemaps3ajax.js | 2 +- .../GoogleMaps/img/mylocation-sprite-2x.png | Bin 0 -> 1582 bytes resources/GoogleMaps/jquery.googlemap.js | 5 + resources/GoogleMaps/mylocation.js | 267 ++++++++++++++++++ src/GoogleMapsService.php | 18 ++ 7 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 resources/GoogleMaps/img/mylocation-sprite-2x.png create mode 100644 resources/GoogleMaps/mylocation.js diff --git a/extension.json b/extension.json index d298bc4bb..480f2e5dc 100644 --- a/extension.json +++ b/extension.json @@ -248,7 +248,8 @@ "ext.maps.googlemaps3": { "scripts": [ "GoogleMaps/jquery.googlemap.js", - "GoogleMaps/ext.maps.googlemaps3.js" + "GoogleMaps/ext.maps.googlemaps3.js", + "GoogleMaps/mylocation.js" ], "messages": [ "maps-googlemaps3-incompatbrowser", @@ -256,6 +257,7 @@ "maps-searchmarkers-text", "maps-fullscreen-button", "maps-fullscreen-button-tooltip", + "maps-mylocation-button-tooltip", "maps-kml-parsing-failed" ], "targets": [ "desktop", "mobile" ] diff --git a/i18n/en.json b/i18n/en.json index fa7b345ea..dc434e968 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -81,6 +81,7 @@ "maps-displaymap-par-geojson": "URL of a file or name of the page containing GeoJSON data", "maps-fullscreen-button": "Toggle fullscreen", "maps-fullscreen-button-tooltip": "View the map as fullscreen or embedded.", + "maps-mylocation-button-tooltip": "Show my location on the map.", "validation-error-invalid-location": "Parameter \"$1\" must be a valid location.", "validation-error-invalid-locations": "Parameter \"$1\" must be one or more valid locations.", "validation-error-invalid-width": "Parameter \"$1\" must be a valid width.", @@ -125,6 +126,9 @@ "maps-par-height": "Allows setting the height of the map. By default pixels will be assumed as unit, but you can explicitly specify one of these units: px, ex, em.", "maps-par-centre": "The location on which the map should be centered", "maps-par-enable-fullscreen": "Enable fullscreen button", + "maps-par-enable-mylocation": "Enable the geolocation button", + "maps-par-mylocationzoom": "The zoom level to go to when user location is turned on", + "maps-par-enable-mylocationfollow": "Continously center map on user location", "maps-par-kml": "KML files to load onto the map.", "maps-par-markercluster": "Allows merging of multiple nearby markers into one marker", "maps-googlemaps3-incompatbrowser": "Your browser is not compatible with Google Maps v3.", diff --git a/resources/GoogleMaps/googlemaps3ajax.js b/resources/GoogleMaps/googlemaps3ajax.js index aa86319ed..c7b2d7d17 100644 --- a/resources/GoogleMaps/googlemaps3ajax.js +++ b/resources/GoogleMaps/googlemaps3ajax.js @@ -9,7 +9,7 @@ (function( $, sm ) { var ajaxRequest = null; - var mapEvents = ['dragend', 'zoom_changed']; + var mapEvents = ['dragend', 'bounds_changed']; $( document ).ready( function() { // todo: find a way to remove setTimeout. diff --git a/resources/GoogleMaps/img/mylocation-sprite-2x.png b/resources/GoogleMaps/img/mylocation-sprite-2x.png new file mode 100644 index 0000000000000000000000000000000000000000..546b97a245d9bd4964a726de96352c8b0619fbb8 GIT binary patch literal 1582 zcmaKteNYou5WqwEQZfV!PJ%Jw*by>{$S4JjIZ9P5Mko=jLPq?eAoYtct6U&s6iPFw z0VGOvj7NuR1*Jig5m1tffQhG=AXO8$q*Y8M&fj6=Y54hewHN&`(t1_B1lP5R(i8dx|%`4MPOMUr(@7s;q8Dv zTOCtn6-PF&Fer6F?lL#G`rSr1M*4y{in)GjIs8R(ZOK!BP6ucaKm!M7t87C^gv)w8 zM{VsNy-9i3bfY6zsoS=oFUNfMe|CJbm+?y4{)b3?)`E8u?roq@NRR)-hD)bb8JlEd z)F-T@4&EGCn~_d$HMV5@$F-#m&yC4-#N=~Jdym2Kf64tyI)c%-lr|L@K^M46zQq zge5Iyqm+e38LS8_WJ}b613@x@^k~m;Q34)?6#)o9C0eZZMLDd?t|Qil(vM`A;DYA9 zCa`_GV+%QdV-*jjr(Qoc1`pb@0`?r8zWPfWgX^qR#$33oeKDGITG*Gej&RCp(j_W? zq}PGyLw`eNo@@bidmYp*1Jtbm)Gc+74vl)C5M2A2Po=-H?`5@#%-<5$`So=xcOy!? zPm)L^k}vy^`T%4Y|L#Vi*0m_B$G(bz+;9CgU~l}Uj}Ai`()i+l?1qW74R!lc*Fay+ z{BtLa>%O`;sV5s83`gMl$Ac#Cdsc=WxBggaywY2|h!=SM%>IzJxUzJpj#l1}z-o~^;2ZOYPyLdHQBA(K4y#zlPIUu{t#I0G}$%4MgIIpG~~I1ro0% zR`MuTgu?mi>hV%&%`T6rC8(eJ@&gf=}JNN5_Z;SNmlkGFzR<&)P-wA@Tf` zXquml@bF$S$MgU?es;epD?JTF^cX}$;(>@LAfnGFYU~kjk8vz76Cbnj)Q*@(w@3YJ zMUj9rw^%x)5+NG)-rwq8w9iR8h=zeunN#FlA- 'maps-par-enable-fullscreen', ]; + $params['mylocation'] = [ + 'type' => 'boolean', + 'default' => false, + 'message' => 'maps-par-enable-mylocation', + ]; + + $params['mylocationfollow'] = [ + 'type' => 'boolean', + 'default' => false, + 'message' => 'maps-par-enable-mylocationfollow', + ]; + + $params['mylocationzoom'] = [ + 'type' => 'integer', + 'default' => -1, + 'message' => 'maps-par-mylocationzoom', + ]; + $params['scrollwheelzoom'] = [ 'aliases' => [ 'scrollzoom' ], 'type' => 'boolean',