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...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Martijn Houtman’s picture

Yeah, I did somewhat the same. I've added the following to geofield_map.js, line 100:

	if (feature.setIcon && properties && properties.icon) {
	  feature.setIcon(properties.icon);
	}

And used a custom module to alter the properties of a geofield marker:

	function MODULE_preprocess_field(&$variables) {
	  if (isset($variables['element']['#field_type']) && $variables['element']['#field_type'] == 'geofield') {
	    foreach ($variables['element'][0]['#attached']['js'][2]['data']['geofieldMap'] as $index => &$data) {
	      $data['data']->properties['icon'] = 'PATH-TO-ICON';
	    }
	  }
	}

Would like a better construction for this, maybe an optional parameter in the field display settings?

2pha’s picture

Thanks Martijn. Worked well.

bshaddad’s picture

Thanks ! worked for me as well.

Charlesdru’s picture

Category: feature » support
Priority: Minor » Normal

Hello

I want to know exactly where to put the php code, file name and folder.

I am a beginner in php code.

Thank you

anou’s picture

Assigned: Unassigned » anou
FileSize
3.77 KB

Finally 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 !

anou’s picture

Status: Active » Needs review
Charlesdru’s picture

FileSize
45.44 KB

Hello

I patch the file, I think it is ok.

I do not see my custom marker.

For geofield_map.js file what append?

Charlesdru’s picture

Bonjour

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

anou’s picture

Hello,
Better stay in English for "all" to understand.
If you don't see your custom marker it's maybe :

  1. because you didn't save your settings after filling the path of your custom marker in the display fields page
  2. or maybe the path to your custom marker is wrong
  3. or maybe my patch is wrong... but I did made it work in my site. (so I leave this option for later on :-))

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.

hamish_s’s picture

Anou,

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.

hamish_s’s picture

Another 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

hamish_s’s picture

I now have it working ... it seems it would not kick in on my development server but works like a dream on the real server.

anou’s picture

Hello hamish_s,
Sorry I didn't manage to answer you before you made it work. I'm happy you did it!

bbujisic’s picture

Category: support » feature
FileSize
3.61 KB

Hey @anou,

Great fix, worked sweet for me, thanks heaps! I updated it in two ways:

  • #12 - It did not work in dev server because it insisted on being in root folder of the site (http://www.example.com/index.php). I guess @hamish_s had similar dev server as I did: http://localhost/example/index.php. So I added base_path() to $map_settings['custom_marker']
  • I added a nice trim function, just in case somebody entered /path/to/the/new/marker.png in Path to custom marker field.

Review would be highly appreciated!

anou’s picture

Hi 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!

bbujisic’s picture

Status: Needs review » Reviewed & tested by the community

+1 for #15, patch applied successfully.

RTBC?

el1_1el’s picture

working for me...thanks

bendev’s picture

Hello,

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 ?

bendev’s picture

I 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

2pha’s picture

I 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

Brandonian’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Marking 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...

nevosa’s picture

for 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,

  $datum->properties = array(
            'description' => $description,
	    'profile' => $result->profile_users_type,
          );

4. following that, the data (profile type) was available to use in the geofield_map.js.
On line ~125 I added:

          if (iconPath) {
// 			 console.dir("profile type") ;
// 			 console.dir(feature.geojsonProperties.profile) ;
             if(feature.geojsonProperties.profile == "my_special_profile")
				 
                      feature.setIcon('/' + 'sites/all/modules/MY_MODULE/markers/MY_MARKER.png'); 
        }

Hope this helps.
N.

vinmassaro’s picture

Issue summary: View changes
Status: Closed (won't fix) » Needs review

@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:

  • OpenLayers and Leaflet provide features that are beyond the scope of what this module provides, and setup is confusing for novice users wanting a simple map implementation.
  • An important feature that is lost with both OpenLayers and Leaflet is the ability to click points of interest on a Google map (businesses, landmarks, etc) and get a popup for the location. It is only possible to click mapped markers.
  • Effort on both Leaflet and OpenLayers projects is moving away from Google Map support.
  • I looked at GMap, but it does not provide a field formatter to display a map. It also appears that address data would need to be recreated as Location field data.

Thanks in advance.

drclaw’s picture

FileSize
179.27 KB

Hi,

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

Marko B’s picture

This 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.

var GeoJSON = function( geojson, options ){
  var _geometryToGoogleMaps = function( geojsonGeometry, opts, geojsonProperties ){
    
    var googleObj;

    switch ( geojsonGeometry.type ){
      case "Point":
      var icon1 = 'sites/all/modules/contrib/geofield/modules/geofield_map/js/download.jpeg';
      var icon2 = 'sites/all/modules/contrib/geofield/modules/geofield_map/js/download2.jpeg';
       opts.icon = icon1;
        opts.position = new google.maps.LatLng(geojsonGeometry.coordinates[1], geojsonGeometry.coordinates[0]);
        var bounds = new google.maps.LatLngBounds();
        bounds.extend(opts.position);
        googleObj = new google.maps.Marker(opts);
        googleObj.set('bounds', bounds);
        if (geojsonProperties) {
          googleObj.set("geojsonProperties", geojsonProperties);
        }
        google.maps.event.addListener(googleObj, 'mouseover', function() {
    googleObj.setIcon(icon2);
});
google.maps.event.addListener(googleObj, 'mouseout', function() {
    googleObj.setIcon(icon1);
});
Jaesin’s picture

More Hackery.

This is useful if you want to set all of the icons to a custom icon without patching the geofield module.

google.maps.Map.prototype.markers = new Array();
google.maps.Marker.prototype.googleSetMap = google.maps.Marker.prototype.setMap;
google.maps.Marker.prototype.setMap = function(map){
  this.googleSetMap(map);
  this.map.getMarkers().push(this);
}
google.maps.Map.prototype.getMarkers = function() {
  return this.markers
};

Then later:

var markers = map.getMarkers();

markers.forEach(function(marker) {
  marker.setIcon('http://maps.google.com/mapfiles/ms/icons/blue-dot.png');
});
HansKuiters’s picture

Patch at #15 works for me too. Thanks.

johnkareoke’s picture

Patch 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

Only local images are allowed.

anou’s picture

Johncarolin, your image is not accessible.

madhaze’s picture

Patch in #15 wouldn't apply for me on 2.3 so i updated using same code in #15 for this patch.

Ante890’s picture

nico.knaepen’s picture

I was unable to apply the patch through git apply. In attachment I have added a new patch.

nico.knaepen’s picture

This is the correct patch.

nico.knaepen’s picture

I 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.

Miguel.kode’s picture

Status: Needs review » Reviewed & tested by the community

It works for me!!

michel.settembrino’s picture

It works for me too!

Thanks.

Koen.Pasman’s picture

The patch works, but fixes the icon size to 21x30. My patch removes this so Maps will take the original marker size.

Honza Pobořil’s picture

Little 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).

bendev’s picture

Here is the interdiff patch from #34 to make the path to the marker relative to the current theme directory

m.abdulqader’s picture

Thanks works for me. #34

Koen.Pasman’s picture

But 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 of drupal_get_path('theme', $GLOBALS['theme']);

k8e1050’s picture

Huge thanks to anou and bbujisic for that patch in #15. Your legends.

charos’s picture

Patch 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 .

timcamps’s picture

Solution #22 works beautifully when wanting Different Markers per Type/Role/Whatever.

malcomio’s picture