-
AuthorPosts
-
April 16, 2024 at 12:54 pm #1440102
Hi,
I used the ‘avf_gmap_vars’ filter to add custom google map styles but it’s not working. It’s correctly printed to the frontend via AviaHelper::print_javascript but the styling doesn’t change. What’s the best way to add custom styling (snazzy maps – snazzy maps plugin is NOT an option!)
All the best,
PatrickApril 17, 2024 at 5:50 pm #1440218Hey Patrick,
Please post the code that you are trying to use, I don’t see this as an available filter in our documentation, in the theme files it seems to only get the map api and doesn’t seem to apply to map style.Best regards,
MikeApril 17, 2024 at 5:56 pm #1440219it is in framework folder – php – class-gmaps.php line: 378 inside public function handler_wp_footer()
April 17, 2024 at 6:08 pm #1440221Hi,
Thanks Guenni007, what I meant is that it only seems to take the api key, do you see that it can be used to customize the map style?Best regards,
MikeApril 18, 2024 at 6:17 am #1440253It writes the zoom level, etc. so I assumed that I can also set the styles attribute because it’s on the same level when the map gets initialized.
All the best,
PatrickApril 18, 2024 at 12:12 pm #1440276Hi,
Can you share the function that you are using, and I can ask the team about it.
I assume that you want to change the map background-color, what other style are you tring to change?Best regards,
MikeApril 18, 2024 at 2:11 pm #1440292Hi Mike,
I want to add snazzy map styles which is done by setting the styles attribute of google maps.
add_filter( 'avf_gmap_vars', function($maps) { $snazzy = [ [ "featureType" => "all", "elementType" => "geometry", "stylers" => [ [ "hue" => "#006cff" ] ] ], [ "featureType" => "all", "elementType" => "geometry.fill", "stylers" => [ [ "hue" => "#006cff" ] ] ], [ "featureType" => "all", "elementType" => "labels.text", "stylers" => [ [ "hue" => "#006cff" ] ] ], [ "featureType" => "all", "elementType" => "labels.icon", "stylers" => [ [ "hue" => "#006cff" ] ] ], [ "featureType" => "landscape.man_made", "elementType" => "geometry", "stylers" => [ [ "hue" => "#006cff" ], [ "saturation" => "100" ] ] ], [ "featureType" => "poi", "elementType" => "all", "stylers" => [ [ "visibility" => "off" ] ] ], [ "featureType" => "road", "elementType" => "geometry", "stylers" => [ [ "lightness" => 50 ], [ "visibility" => "simplified" ] ] ], [ "featureType" => "road", "elementType" => "labels", "stylers" => [ [ "visibility" => "simplified" ] ] ], [ "featureType" => "transit", "elementType" => "labels.text", "stylers" => [ [ "visibility" => "off" ] ] ] ]; $maps['av_google_map']['av_gmap_0']['styles'] = $snazzy; return $maps; } );
When I check window.av_google_map in dev tools everything is there correctly but it seems like it doesn’t get initialized.
April 19, 2024 at 7:24 am #1440336Hi,
Thank you for the update.
The filter should work with slight modifications to the enfold/framework/js/conditional_load/avia_google_maps_api.js file. Please look for this code around line 177:
styles: this.$data.styles
Replace it with:
styles: typeof this.$data.styles === 'string' ? JSON.parse(this.$data.styles) : this.$data.styles
Then look for this code in the avf_gmap_vars filter:
$maps['av_google_map']['av_gmap_0']['styles'] = $snazzy;
Replace it with:
$maps['av_google_map']['av_gmap_0']['styles'] = json_encode($snazzy);
You may need to temporarily disable the Enfold > Performance > File Compression settings after modifying the js file.
Best regards,
IsmaelApril 19, 2024 at 8:12 am #1440337Hi Ismael,
Thank you. It works :)
Possible you put the changes into core with the next update?Thanks,
PatrickApril 19, 2024 at 10:00 am #1440344Hi Ismael,
I have another question. Is it possible to make the google map to work with borlabs cookie? I added the borlabs cookie shortcode arround the google map via the avf_in_shortcode_handler_prepare_content. If I don’t allow the cookie the map gets nicely blocked. When i press allow the map doesn’t load. I have to refresh the whole page so that the map loads again. Is there a way to fix that?
You can check on the website I sent you before. There are two versions. One is added via a google iframe which works. The second is the enfold element. Would be nice if it work with the enfold element too.
All the best,
PatrickApril 19, 2024 at 10:17 am #1440347the json method is used by google maps api long time ( in the meantime there is a cloud console for that) . https://mapstyle.withgoogle.com/ – they use a very similar json code like your “snazzy” one for styling.
is it possible to adapt that for the native google json?
Edit: it works with the google json aswell. In this case i do not name it snazzy.
But you had to edit a bit that output code of google json !
Changes in avia_google_maps_api.js are the same – and because it is set by a ternary operator there is nothing to stop it being included for the next release – right?
f.e.:
add_filter( 'avf_gmap_vars', function($maps) { $googleStyles = // here is the place to insert the edited google styling json // all curly brackets had to be changed to square brackets - and the ":" had to be replaced by: "=>" [ [ "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#ebe3cd" ] ] ], [ "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#523735" ] ] ], [ "elementType"=> "labels.text.stroke", "stylers"=> [ [ "color"=> "#f5f1e6" ] ] ], [ "featureType"=> "administrative", "elementType"=> "geometry.stroke", "stylers"=> [ [ "color"=> "#c9b2a6" ] ] ], [ "featureType"=> "administrative.land_parcel", "elementType"=> "geometry.stroke", "stylers"=> [ [ "color"=> "#dcd2be" ] ] ], [ "featureType"=> "administrative.land_parcel", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#ae9e90" ] ] ], [ "featureType"=> "landscape.natural", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#dfd2ae" ] ] ], [ "featureType"=> "poi", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#dfd2ae" ] ] ], [ "featureType"=> "poi", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#93817c" ] ] ], [ "featureType"=> "poi.park", "elementType"=> "geometry.fill", "stylers"=> [ [ "color"=> "#a5b076" ] ] ], [ "featureType"=> "poi.park", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#447530" ] ] ], [ "featureType"=> "road", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#f5f1e6" ] ] ], [ "featureType"=> "road.arterial", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#fdfcf8" ] ] ], [ "featureType"=> "road.highway", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#f8c967" ] ] ], [ "featureType"=> "road.highway", "elementType"=> "geometry.stroke", "stylers"=> [ [ "color"=> "#e9bc62" ] ] ], [ "featureType"=> "road.highway.controlled_access", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#e98d58" ] ] ], [ "featureType"=> "road.highway.controlled_access", "elementType"=> "geometry.stroke", "stylers"=> [ [ "color"=> "#db8555" ] ] ], [ "featureType"=> "road.local", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#806b63" ] ] ], [ "featureType"=> "transit.line", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#dfd2ae" ] ] ], [ "featureType"=> "transit.line", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#8f7d77" ] ] ], [ "featureType"=> "transit.line", "elementType"=> "labels.text.stroke", "stylers"=> [ [ "color"=> "#ebe3cd" ] ] ], [ "featureType"=> "transit.station", "elementType"=> "geometry", "stylers"=> [ [ "color"=> "#dfd2ae" ] ] ], [ "featureType"=> "water", "elementType"=> "geometry.fill", "stylers"=> [ [ "color"=> "#3300ff" ], [ "lightness"=> 40 ] ] ], [ "featureType"=> "water", "elementType"=> "labels.text.fill", "stylers"=> [ [ "color"=> "#ffffff" ] ] ] ] // end of insertion ; $maps['av_google_map']['av_gmap_0']['styles'] = json_encode($googleStyles); return $maps; });
April 19, 2024 at 11:19 am #1440350it works in this manner with google json:
by the way Patrick : the original snazzy json code (https://snazzymaps.com/) is similar to google code – so where did you get your snazzy code?
add_filter( 'avf_gmap_vars', function($maps) { $googleStyles = // here is the place to insert the edited google styling json // all curly brackets had to be changed to square brackets // and the ":" had to be replaced by: "=>" // edited google json code comes here from : https://mapstyle.withgoogle.com/ // end of insertion ; $maps['av_google_map']['av_gmap_0']['styles'] = json_encode($googleStyles); return $maps; });
April 19, 2024 at 11:52 am #1440354I got a json file:
[ { "featureType": "all", "elementType": "geometry", "stylers": [ { "hue": "#006cff" } ] }, { "featureType": "all", "elementType": "geometry.fill", "stylers": [ { "hue": "#006cff" } ] }, { "featureType": "all", "elementType": "labels.text", "stylers": [ { "hue": "#006cff" } ] }, { "featureType": "all", "elementType": "labels.icon", "stylers": [ { "hue": "#006cff" } ] }, { "featureType": "landscape.man_made", "elementType": "geometry", "stylers": [ { "hue": "#006cff" }, { "saturation": "100" } ] }, { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "road", "elementType": "geometry", "stylers": [ { "lightness": 50 }, { "visibility": "simplified" } ] }, { "featureType": "road", "elementType": "labels", "stylers": [ { "visibility": "simplified" } ] }, { "featureType": "transit", "elementType": "labels.text", "stylers": [ { "visibility": "off" } ] } ]
I added that first as a string in the filter but it didn’t work. So i changed it to array only. Did I miss something?
April 19, 2024 at 2:24 pm #1440365that it will work – i wrote as comment above:
// all curly brackets had to be changed to square brackets // and the ":" had to be replaced by: "=>"
so transformed is:
[ [ "featureType"=> "all", "elementType"=> "geometry", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "geometry.fill", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "labels.text", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "labels.icon", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "landscape.man_made", "elementType"=> "geometry", "stylers"=> [ [ "hue"=> "#006cff" ], [ "saturation"=> "100" ] ] ], [ "featureType"=> "poi", "elementType"=> "all", "stylers"=> [ [ "visibility"=> "off" ] ] ], [ "featureType"=> "road", "elementType"=> "geometry", "stylers"=> [ [ "lightness"=> 50 ], [ "visibility"=> "simplified" ] ] ], [ "featureType"=> "road", "elementType"=> "labels", "stylers"=> [ [ "visibility"=> "simplified" ] ] ], [ "featureType"=> "transit", "elementType"=> "labels.text", "stylers"=> [ [ "visibility"=> "off" ] ] ] ]
will result in: https://webers-testseite.de/enfold-map/
April 19, 2024 at 2:30 pm #1440368complete Code to set into child-theme functions.php:
( the changings in avia_google_maps_api.js stayes the same)add_filter( 'avf_gmap_vars', function($maps) { $googleStyles = [ [ "featureType"=> "all", "elementType"=> "geometry", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "geometry.fill", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "labels.text", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "all", "elementType"=> "labels.icon", "stylers"=> [ [ "hue"=> "#006cff" ] ] ], [ "featureType"=> "landscape.man_made", "elementType"=> "geometry", "stylers"=> [ [ "hue"=> "#006cff" ], [ "saturation"=> "100" ] ] ], [ "featureType"=> "poi", "elementType"=> "all", "stylers"=> [ [ "visibility"=> "off" ] ] ], [ "featureType"=> "road", "elementType"=> "geometry", "stylers"=> [ [ "lightness"=> 50 ], [ "visibility"=> "simplified" ] ] ], [ "featureType"=> "road", "elementType"=> "labels", "stylers"=> [ [ "visibility"=> "simplified" ] ] ], [ "featureType"=> "transit", "elementType"=> "labels.text", "stylers"=> [ [ "visibility"=> "off" ] ] ] ] ; $maps['av_google_map']['av_gmap_0']['styles'] = json_encode($googleStyles); return $maps; });
April 19, 2024 at 2:36 pm #1440369Hallo Günter,
Ich wechsel kurz auf Deutsch weil ich mich da besser Ausdrücken kann :D
Den Code den du mir jetzt geschickt hast ist ja schon der Code den ich so in Verwendung habe und der funktioniert auch. Ismael hatte nur Änderungen in im javascript gemacht (https://kriesi.at/support/topic/change-google-maps-styling/#post-1440336) und ich wollte nur wissen ob ihr diese Änderungen dann in den Core übernehmen könnt mit dem nächsten Update. Kann es sein, dass du https://kriesi.at/support/topic/change-google-maps-styling/#post-1440337 nicht gelesen hast? :D
Oder reden wir gerade aneinander vorbei?
Liebe Grüße
PatrickApril 19, 2024 at 4:25 pm #1440372doch ich las es;
nur wollte ich im Gegenzug wissen wo dein snazzy json her kommt, denn wenn du dem Link zu snazzy folgst, und dort mal ein Styling durchspielst, dann erhält man am schluss auch wie bei Google einen json code, der geschweifte Klammern und Doppelpunkte enthält.
Daher wollte ich wissen woher dein Snazzy Code kommt.Außerdem war mein Kommentar oben ja:
Changes in avia_google_maps_api.js are the same – and because it is set by a ternary operator there is nothing to stop it being included for the next release – right?
Es würde auf Grund der Verwendung eines ternären Operators jene die das Filter und diese Einstellungen nutzen auch nicht stören, wenn man es in Enfold aufnehmen würde.
Da ich auch Borlabs Nutzer bin – wäre das sicherlich eine Bereicherung.
April 22, 2024 at 6:27 am #1440473Ok, dann hab ich es missverstanden 😅
Yes, the ternary operator should be save for the changes in core and borlabs implementation would be great.
Thanks,
PatrickApril 22, 2024 at 7:34 am #1440490Hey!
@Guenni007: Thanks for the info. I’ve tested the modified filter, but it still doesn’t work without the adjustments in the enfold/framework/js/conditional_load/avia_google_maps_api.js file.@Resonanz Digital: We’ve forwarded this thread to our channel.
Cheers!
IsmaelApril 22, 2024 at 7:36 am #1440491Thanks Ismael,
Keep me updated please.
All the best,
PatrickApril 23, 2024 at 12:58 am #1440545Yes, Ismael, the changes have to be made in avia_google_maps_api.js – but since you’ve set the ternary operator, it shouldn’t bother those who don’t need the filter.
The change (read comments on snippet) only concerned instructions on how to create a code that could be used for filtering from the json code created by Google from that page: https://mapstyle.withgoogle.com/April 23, 2024 at 2:58 am #1440549Hi,
Thanks for the info. The modification will be included in the next patch.
Best regards,
IsmaelApril 25, 2024 at 7:50 am #1440762Great news, thank you.
Anything new on the Borlabs thing?
All the best,
PatrickApril 30, 2024 at 9:31 am #1441404Hi,
Anything new on the Borlabs thing?
I’m not entirely sure what you’re referring to. Did you open another thread about this issue?
Best regards,
IsmaelApril 30, 2024 at 9:33 am #1441405Hi Ismael,
It was here https://kriesi.at/support/topic/change-google-maps-styling/#post-1440344
Günter also said it would be a nice feature.
All the best,
PatrickMay 8, 2024 at 10:01 am #1442659 -
AuthorPosts
- You must be logged in to reply to this topic.