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.
Hello,
I've search so long to make it work so I post here my solution to display a custom marker on google map with Geofield Map module. It could be more user friendly to make a setting page but for now it's just a line of php in the original module.
So line 100, I added:
<?php feature.setIcon('/PATH-TO-MY-CUSTOM-MARKER/custom-marker.png'); ?>
just before <?php feature.setMap(map); ?>
Could be a good upgrade to have this possibility via the UI... If I have time...
Comments
Comment #1
Martijn Houtman CreditAttribution: Martijn Houtman commentedYeah, I did somewhat the same. I've added the following to
geofield_map.js
, line 100:And used a custom module to alter the properties of a geofield marker:
Would like a better construction for this, maybe an optional parameter in the field display settings?
Comment #2
2phaThanks Martijn. Worked well.
Comment #3
bshaddad CreditAttribution: bshaddad commentedThanks ! worked for me as well.
Comment #4
Charlesdru CreditAttribution: Charlesdru commentedHello
I want to know exactly where to put the php code, file name and folder.
I am a beginner in php code.
Thank you
Comment #5
anouFinally I did a patch for geofield_map submodule. Martijn Houtman solution didn't work with geofield_map used by views. Now it works for both.
You can configure it in field display configuration and/or in views geofield_map settings.
So now Charles-C, you must learn how to apply patches to modules. Here's a good page to begin with. Good luck.
And have fun !
Comment #6
anouComment #7
Charlesdru CreditAttribution: Charlesdru commentedHello
I patch the file, I think it is ok.
I do not see my custom marker.
For geofield_map.js file what append?
Comment #8
Charlesdru CreditAttribution: Charlesdru commentedBonjour
J'ai bien appliquer le patch, mes je ne vois toujour pas le marqueur.
Est ce que je dois midifier le fichier geofield_map.js ?
Merci de bien vouloir aider un novice du php et Js
Comment #9
anouHello,
Better stay in English for "all" to understand.
If you don't see your custom marker it's maybe :
For your info, all the files are modified directly by the patch and this is also true for geofield_map.js. If you're not sure everything is changed in the js, you can do the changes "a la mano" copying from the patch directly to geofield_map.js.
Comment #10
hamish_s CreditAttribution: hamish_s commentedAnou,
I have also rolled in the patch, but the icons are not changing. The field shows, and I put in a variety of image locations to no avail. When I delete the new path, the old icons show, so, it is still working.
I have indeed saved my settings;
I have tried a variety of paths (without the /)
since you mad eit work, I am sure it is good. Were there any tweaks that did not make it into the patch?
Thanks for any direction you can provide.
Charles-C - did you resolve your problem? Can you please update if you were bale to make it work for you?
Thanks again.
Comment #11
hamish_s CreditAttribution: hamish_s commentedAnother question ... when I try, weakly, to decode the php in the module file, it seems to me that there is a place created where the user gets to specify if hey want to use a custom icon "yes" 'no".
Yet, I cannot find anywhere in my guis where I would actually tell it to use my icon. Can you please point me to where that box is?
Thanks for your work - I think this will be a terrific customization.
Hamish
Comment #12
hamish_s CreditAttribution: hamish_s commentedI now have it working ... it seems it would not kick in on my development server but works like a dream on the real server.
Comment #13
anouHello hamish_s,
Sorry I didn't manage to answer you before you made it work. I'm happy you did it!
Comment #14
bbujisic CreditAttribution: bbujisic commentedHey @anou,
Great fix, worked sweet for me, thanks heaps! I updated it in two ways:
base_path()
to$map_settings['custom_marker']
/path/to/the/new/marker.png
in Path to custom marker field.Review would be highly appreciated!
Comment #15
anouHi Branislav,
Nice catch for the base_path() + trim. I've tested it and I can only say that it is great and working fine for me.
Patch modified attached here because of some white space errors on git apply. Beside that it's all the same.
Bravo!
Comment #16
bbujisic CreditAttribution: bbujisic commented+1 for #15, patch applied successfully.
RTBC?
Comment #17
el1_1el CreditAttribution: el1_1el commentedworking for me...thanks
Comment #18
bendev CreditAttribution: bendev commentedHello,
Thank you for this patch, it is working fine.
Do you know if it would be possible to have different types of markers depending on a field of the content type or depending on a property of the view row result ?
I have already found this link :
https://developers.google.com/maps/tutorials/customizing/custom-markers#...
any advice how to build it ?
Comment #19
bendev CreditAttribution: bendev commentedI managed to do this but this is a bit too much custom code because I need to compare in the JS the value of a row field against a given value (0/1) to decide whether I should display icon path 0 or 1.
A more generic approach would be more useful... if you have any idea how to do that I can try to adapt my code
Comment #20
2phaI use the leaflet module to output my maps.
I have supplied a patch for it that allows greater control of the map options and allows for tokens to be used in the icon image path https://drupal.org/node/2089209
There is a comparison of different mapping modules at https://drupal.org/node/1704948
Comment #21
Brandonian CreditAttribution: Brandonian commentedMarking as won't fix. Geofield Map is intended to be a simple solution, and I'm not interested in adding additional functionality to the bundled module.
If you want to have a more customized map, I would suggest checking out @cboyden's excellent tutorial on building custom maps with Leaflet and Drupal. http://2013.badcamp.net/sessions/put-your-content-map-intro-maps-and-loc...
Comment #22
nevosa CreditAttribution: nevosa commentedfor those of you struggling with different markers, I've achieved for different user profiles using a view by adding the following:
1. Apply patch #15
2. Add a field you would use to distinct different markers (I added "profile type") to the view and hide it.
3. Then, on geofiled_map_plugin_style_map.inc line ~126,
4. following that, the data (profile type) was available to use in the geofield_map.js.
On line ~125 I added:
Hope this helps.
N.
Comment #23
vinmassaro CreditAttribution: vinmassaro commented@Brandonian: I'm wondering if you will reconsider this feature request. In an attempt to get custom markers working, I spent all of yesterday testing out OpenLayers and Leaflet. The main takeaway was that Geofield Map is still the simplest no-frills way to display a map on a node from Geofield data.
A couple of reasons I hope you will reconsider this request:
Thanks in advance.
Comment #24
drclaw CreditAttribution: drclaw commentedHi,
I would also ask that this patch be reconsidered. I've tested out the patch in comment #15, and I believe it's actually stays quite true to the simple nature of the module. It adds an option to the field formatter form where you can specify a path to a marker. It doesn't get any simpler than that! I've attached a screenshot of the settings form and resulting map.
I would agree that setting up a dynamic marker pull from another field is getting into complicated territory, but the patch n #15 is not that complex. It's simple, concise and better yet: it works! Please reconsider!
Thanks!
drclaw
Comment #25
Marko B CreditAttribution: Marko B commentedThis is not a patch, rather a hack but could be a start for proper patch. To not only have custom icon pin but also rollover icon I changed GeoJSON.js first part with this.
Comment #26
Jaesin CreditAttribution: Jaesin commentedMore Hackery.
This is useful if you want to set all of the icons to a custom icon without patching the geofield module.
Then later:
Comment #27
HansKuiters CreditAttribution: HansKuiters commentedPatch at #15 works for me too. Thanks.
Comment #28
johnkareoke CreditAttribution: johnkareoke commentedPatch 15 partially worked for me. Some of my geofields are WKT polygons (see image). After applying this patch, I am able to set my custom marker, and they work with points, but if the field is a polygon, this breaks the map. It would be useful if this patch distinguished points from polygons. I am not exactly sure how to do that. Any suggestions/help.
Thanks
Comment #29
anouJohncarolin, your image is not accessible.
Comment #30
madhaze CreditAttribution: madhaze commentedPatch in #15 wouldn't apply for me on 2.3 so i updated using same code in #15 for this patch.
Comment #31
Ante890 CreditAttribution: Ante890 commentedHI I added support for retina icon . Read more http://samcroft.co.uk/2011/google-maps-marker-icons-for-iphone-retina-di...
Comment #32
nico.knaepen CreditAttribution: nico.knaepen as a volunteer commentedI was unable to apply the patch through git apply. In attachment I have added a new patch.Comment #33
nico.knaepen CreditAttribution: nico.knaepen as a volunteer commentedThis is the correct patch.Comment #34
nico.knaepen CreditAttribution: nico.knaepen as a volunteer commentedI was unable to apply the patch through git apply. In attachment I have added a new patch. This patch should be placed within the geofield module folder.
Comment #35
Miguel.kode CreditAttribution: Miguel.kode commentedIt works for me!!
Comment #36
michel.settembrino CreditAttribution: michel.settembrino as a volunteer commentedIt works for me too!
Thanks.
Comment #37
Koen.Pasman CreditAttribution: Koen.Pasman at Aubergine IT commentedThe patch works, but fixes the icon size to 21x30. My patch removes this so Maps will take the original marker size.
Comment #38
Honza Pobořil CreditAttribution: Honza Pobořil as a volunteer commentedLittle feature request:
In settings field it should support wildchart like %theme_path.
And it is good to mention supported image file types (inc. SVG if it is supported).
Comment #39
bendev CreditAttribution: bendev at WebstanZ commentedHere is the interdiff patch from #34 to make the path to the marker relative to the current theme directory
Comment #40
m.abdulqader CreditAttribution: m.abdulqader at Sprintive commentedThanks works for me. #34
Comment #41
Koen.Pasman CreditAttribution: Koen.Pasman at Aubergine IT commentedBut this forces the marker image to be in the theme path, which is not something you want to enforce I think. It's better to just replace a placeholder like
%theme_path%
with the contents ofdrupal_get_path('theme', $GLOBALS['theme']);
Comment #42
k8e1050 CreditAttribution: k8e1050 commentedHuge thanks to anou and bbujisic for that patch in #15. Your legends.
Comment #43
charos CreditAttribution: charos commentedPatch works great but there is a design flow with Views in its logic: If you assign different marker icons per content type and create a View with locations from different content types, you'd expect to display the icons according to the setting in each content type.
Right now in Views you either get the default marker icon or override it with a custom one. I believe a clean approach would be to respect the icon that was set already on the content type .
Comment #44
timcamps CreditAttribution: timcamps commentedSolution #22 works beautifully when wanting Different Markers per Type/Role/Whatever.
Comment #45
malcomio CreditAttribution: malcomio as a volunteer and at Capgemini commentedSeems related to #2362929: Define custom markers per marker type with Geofield Map