Posted by RdeBoer on August 1, 2012 at 9:48am
9 followers
| Project: | Leaflet |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | RdeBoer |
| Status: | closed (fixed) |
Issue Summary
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
#1
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.
#2
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
#3
I ran into the same issue with custom markers.
#4
@gmclelland, #3:
So did the patch to
leaflet/leaflet.drupal.jsoutlined 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
#5
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.
#6
Confirmed working against the latest -dev tarball as well.
#7
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.
#8
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).
#9
This is great news!
I love Leaflet.
#10
Automatically closed -- issue fixed for 2 weeks with no activity.
#11
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
#12
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