Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sorry, I'm not very experienced with the gmap module.
I'm looking for a way to use the styled maps (like in this wizard Google Style Wizard), but I couldn't find anything.
Is there a way I simply did not recognize?
Best wishes and thank you for your great module!
Comment | File | Size | Author |
---|---|---|---|
#27 | gmap_styled-maps-1482608-25.patch | 730 bytes | ndewhurst |
#23 | gmap_styled-maps-1482608-23.patch | 367 bytes | ndewhurst |
#22 | gmap_styled-maps-1482608-22.patch | 523 bytes | malcolm_p |
#20 | gmap_styled-maps-1482608-20.patch | 853 bytes | attisan |
#14 | gmap-map-styling-option-1482608-15.patch | 414 bytes | recrit |
Comments
Comment #1
funkDoc CreditAttribution: funkDoc commentedJust following up on this issue. Is there any way to pass the style through the macro now that we're on gmaps v3 api? I've tried all combinations of arguments in the macro.
Here's a hack I've been getting by with if anyone else needs is, add the following code to gmap.js above line 358 ( obj.map = new google.maps.Map(elem, obj.opts); )
obj.opts.styles = [
{
"stylers": [
{ "hue": "#0044ff" },
{ "lightness": 58 },
{ "weight": 1.5 },
{ "saturation": -69 }
]
}
];
It unfortunately applies the style to all maps though. Works for now until there's a way to pass through the macro.
Comment #2
seaneffel CreditAttribution: seaneffel commentedLine numbers change from version to version. Could you post a little snippet, or the gmap.js file you're working with? I would love to see how you did it.
Thanks!
Comment #3
seaneffel CreditAttribution: seaneffel commentedI used the Gmaps Style Wizard to craft a style and copy the JSON code generated by the wizzard.
I edited the sites/all/modules/gmap/js/gmap.js file at approximately line 358 to read as follows:
I had to both clear my cache and wipe all the .js files out of the directory at sites/default/files/js. Reloading the page shows me a styled map matching the wizard. It is true, this affects all Gmap outputs sitewide.
I have not determined how to restore map markers from the Location module. Working on that next.
This is a crap way to get styled maps since any GMap module update will cramp my style and probably kill the map output until the caches are cleared. But if we can get a model here then we can get it done properly in the module.
Comment #4
seaneffel CreditAttribution: seaneffel commentedComment #5
seaneffel CreditAttribution: seaneffel commentedUpdate, clearing cache again put the markers back on the map. Silly thing.
Comment #6
toddviola CreditAttribution: toddviola commentedHere's a working example, implemented as a js file loaded in my theme.
Comment #7
seaneffel CreditAttribution: seaneffel commentedSweet. That's working here for me, too. It has the same issue of applying the styling to all maps site wide, but it doesn't require hacking the module.
Comment #8
N20 CreditAttribution: N20 commentedworks for me too. thanks for sharing!
Comment #9
seaneffel CreditAttribution: seaneffel commentedIt would be sweet if this were a field in the GMap module into which the user could paste the entire JSON code. Then a field per view in the Location module.
Comment #10
ThomasH CreditAttribution: ThomasH commentedNot the ideal solution either, but as we needed a quick fix at our current project... This works with the added patch. This will set it globally, but you could filter based on map id.
Comment #11
podarokbumping version
Comment #13
alanpeart CreditAttribution: alanpeart commentedtoddviola: you've probably saved me hours of work. Thanks.
Comment #14
recrit CreditAttribution: recrit commentedThe attached patch is rolled against the latest 7.x-2.x-dev.
Comment #15
recrit CreditAttribution: recrit commentedComment #17
podarokthank, merged
Comment #19
kopeboy CreditAttribution: kopeboy commentedThank you. Can you document how to use this feature for a noob?
Like applying a style (pasted JSON code) to a specific map?
ip_geoloc module is easier to use in this regard (just paste code in a View map display)
Comment #20
attisansorry for reopening this - but I needed to fix it in order for styles to work.
Comment #22
malcolm_p CreditAttribution: malcolm_p commentedI also had to add the JSON.parse fix to get the styles to apply.
Comment #23
ndewhurstI can confirm that the JSON.parse addition seems to be necessary. I'm attaching a re-rolled patch that should apply to the current dev branch.
@kopeboy, here's one example of how to use this:
You can also just paste the JSON you might get from a Google wizard or elsewhere and drop it into the settings array as a string (instead of
drupal_json_encode($my_map_styles)
in the example above). If you don't see it working at first, check to make sure you have the right number of nested arrays in the JSON that ends up in Drupal.gmap.addHandler().Comment #24
ndewhurstComment #27
ndewhurstHere's a fancier patch in case that's more convenient.
Looks like tests are failing on all recent patches, perhaps unrelated to anything in this issue...
Comment #29
Neograph734Testing are currently failing for all patches. It seems we'd have to take care of #2778721: [Patch Blocker] - Repair the failing testGmapSaveConfig test first.
Comment #30
Neograph734The patch has been queued for re-testing as soon as the -dev branch is passing.
Comment #31
Sociality CreditAttribution: Sociality commentedI use the JS version named in #6 with preprocess_page hook and drupal_add_js with 'scope' => 'footer', 'weight' => 5 as options and worked perefectly. Thanks!
Comment #32
pelicani CreditAttribution: pelicani commented2019 Status Summary :
Gmap module currently has the ability to modify the style of a map for version 3.
However, the style data is expected to have an array format.
This patch changes the expected format to json so you can copy and paste into a file and load it as the style data directly.
#6 creates it own map and assigns styles. or some js magic. I'm not really sure as I don't dabble so much in the arts. This isn't really a Drupal solution, but others say it works for them. It's something I'd expect to see in a wordpress theme.
#10 was actually implemented and is currently available.
#14 is the accepted patch based entirely from #10
#20 is the first path for converting the expected data to json
and the rest are all adaptations of that.
One could argue that converting the json data to an array is trivial using an online tool.
https://wtools.io/convert-json-to-php-array
That's the current status.
I personally chose to leave it as is and convert the generated json into an array.
If the module changes, I'd follow suit.
peace,
Michael
Comment #33
_KurT_ CreditAttribution: _KurT_ at FFW commentedHi guys, i worked on issue https://www.drupal.org/project/gmap/issues/1794230 and seems it is the same. Could you please review patch in that issues not to crosspost patches.