Hi,
Thanks for this module. I'm using with great success but am having trouble with displaying alternatives to the standard blue markers.
I found the README very useful. I based my attempts to introduce new marker icons on this excerpt:

$features = array(
  array(
    'type' => 'point',
    'lat' => 12.32,
    'lon' => 123.45,
    'icon' => array(
      'iconUrl' => 'sites/default/files/mymarker.png'
    ),
    'popup' => l($node->title, 'node/' . $node->nid),
    'leaflet_id' => 'some unique ID'
  ),
 ....
);

However the 'icon'/'iconUrl' part isn't working for me.
Any ideas?

Rik

Comments

rdeboer’s picture

Component: Documentation » Code
Assigned: Unassigned » rdeboer
Category: support » bug
Status: Active » Patch (to be ported)

Fixed it.
There's a typo in leaflet/leaflet.drupal.js

Line #168 (in "create_point") reads:

    var icon = new L.Icon(marker.icon.iconUrl);

Should be:

    var icon = new L.Icon( {iconUrl: marker.icon.iconUrl} );

Multiple marker colors based on a "differentiator" field in the View (eg. node type, taxonomy term, price category etc..) are used in this Leaflet map rendering module: IP Geolocation Views and Maps.

rdeboer’s picture

The Icon object has changed somewhat in Leaflet 0.4 (30 July 2012), so the setting of marker size, anchor, shadow and popup anchor don't work with the old leaflet.drupal.js code either, result in the introduced marker being, .... well, "off the mark".
Here is the entire create_point section as it should be. Note the extra ".options" level in the icon object.

    create_point: function(marker) {
      var latLng = new L.LatLng(marker.lat, marker.lon);
      this.bounds.push(latLng);
      var lMarker;
      if (marker.icon) {
      //var icon = new L.Icon(marker.icon.iconUrl);
        var icon = new L.Icon({iconUrl: marker.icon.iconUrl});

        // override applicable marker defaults
        if (marker.icon.iconSize) {
          icon.options.iconSize = new L.Point(parseInt(marker.icon.iconSize.x), parseInt(marker.icon.iconSize.y));
        }
        if (marker.icon.iconAnchor) {
          icon.options.iconAnchor = new L.Point(parseFloat(marker.icon.iconAnchor.x), parseFloat(marker.icon.iconAnchor.y));
        }
        if (marker.icon.popupAnchor) {
          icon.options.popupAnchor = new L.Point(parseFloat(marker.icon.popupAnchor.x), parseFloat(marker.icon.popupAnchor.y));
        }
        if (marker.icon.shadowUrl !== undefined) {
          icon.options.shadowUrl = marker.icon.shadowUrl;
        }
        if (marker.icon.shadowSize) {
          icon.options.shadowSize = new L.Point(parseInt(marker.icon.shadowSize.x), parseInt(marker.icon.shadowSize.y));
        }
        lMarker = new L.Marker(latLng, {icon:icon});
      }
      else {
        lMarker = new L.Marker(latLng);
      }
      return lMarker;
    },

Will look at generating a proper patch.
Rik

gmclelland’s picture

I ran into the same issue with custom markers.

rdeboer’s picture

@gmclelland, #3:
So did the patch to leaflet/leaflet.drupal.js outlined in #2 work for you?
Just copy the code from #2 and paste over the "create_point" section in the lealfet.drupal.js file.
Rik

rdeboer’s picture

Title: Alternative marker images and colors » Upgrade to Leaflet JS 0.4.x to show markers and multiple layers
Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
StatusFileSize
new8.81 KB
new2.33 KB

Patch (against 7.x-1.x-dev) and complete deployable module.
Tested with both Leaflet JS 0.4.0 and Leaflet JS 0.4.4 (7 Aug 2012).

The included fix to allow multiple layers to be stacked on the same canvas is evident in the OpenPisteMap (http://openpistemap.org), available from the map dropdown when you enable the Leaflet More Maps module.
It has relief-shading layer and piste layers on top of the base earth layer.

chaseontheweb’s picture

Confirmed working against the latest -dev tarball as well.

cossovich’s picture

Yep, confirmed here too. I've got the patch running against the most recent commit to 7.x-1.x and it's all working.

pvhee’s picture

Status: Patch (to be ported) » Fixed

Thanks for the patch, this is now committed! (and so is the example makefile).

I'll discuss with levelos to see whether we can roll out a new release with all these changes (including Views support).

rdeboer’s picture

This is great news!
I love Leaflet.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

prezaeis’s picture

Can you please tell me what this patch will do exactly?
I am using the IP Geolocation Views module to display content types using the Leaflet map. Would this patch allow me to use my own custom Markers?

Thank you

rdeboer’s picture

This was all sorted a long time ago. No need to patch.
Just use the latest version of Leaflet and IP Geoloc.
And if you're brave enough to use IP Geoloc 7.x-1.x-dev, then you get the option to number or tag yourmarkers too!
You add your own set of markers on the IP Geoloc config page.
Rik

rdeboer’s picture

Issue summary: View changes

added quote to iconUrl