-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to current leaflet. #8
Comments
Oh... that would be great. BTW: Thanks for that great leaflet plugin :-) |
I am getting |
Patches accepted, as always, if someone wants to help with this update. |
I do like to contribute patches! But this is somewhat outside my Cheers, On 07/16/2015 12:19 PM, Tom MacWright wrote:
|
Ok... the API of leaflet for 1.0 changes.
check, this is a problem. For now the solution would be to only check for L.Polygon (since now MultiPolygons are handled also in this class), but the leaflet API might change again (see Leaflet/Leaflet#3498 (comment)) |
How about opening a separate branch for leaflet-1.0-dev? |
This is the only breaking change I experienced in using leaflet-pip with Leaflet 1.0, so the fix seems easy enough: just remove the line. Except then things don't work for earlier versions of Leaflet. To make matters worse, the discussion on Leaflet regarding MultiPolygon is on-going A branch would work, or a comment could be appended to the source code referencing the relevant threads so users can confidently repair the issue themselves until the API stabilizes. |
Why not just amend the code so it checks if L.MultiPolygon exists, and if it does, it uses it, otherwise it wont. That way when the code changes, it will still work. perhaps something like the following: add a new function to handle both situations: instanceCheck: function() {
if (L.MultiPolygon) {
return (l instanceof L.MultiPolygon || l instanceof L.Polygon);
} else {
return(l instanceof L.Polygon);
}
} and then replace if (l instanceof L.MultiPolygon || l instanceof L.Polygon) with if (instanceCheck()) fyi, I havn't verified whether this works, but in theory, it should. |
Why use instanceof here? var leafletPip = {
bassackwards: false,
getGeometry: function(l) {
var geom = null,
type = null;
if (l.toGeoJSON) {
geom = l.toGeoJSON().geometry;
type = (geom) ? geom.type : null;
// checking for supported types (only MultiPolygon and Polygon)
if (type === "MultiPolygon" || type === "Polygon") {
return geom;
}
}
return null;
},
pointInLayer: function(p, layer, first) {
'use strict';
if (p instanceof L.LatLng) p = [p.lng, p.lat];
else if (leafletPip.bassackwards) p = p.concat().reverse();
var results = [];
layer.eachLayer(function(l) {
if (first && results.length) return;
var geom = leafletPip.getGeometry(l);
if (geom && gju.pointInPolygon({ type: 'Point', coordinates: p }, geom)) {
results.push(l);
}
});
return results;
}
}; |
I applied the code from nikolauskrismer, and it got me up and running with Leaflet 1.0 Beta 2... mostly. The states in my demo, http://exploringspatial.com/#demo/8, won't unhighlight any more. I'm going to see if that is an easy fix (at this point, I'm working on a local copy). |
Fixed in #20 |
No description provided.
The text was updated successfully, but these errors were encountered: