Skip to content

Commit

Permalink
Support for Leaflet v 1.0
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
Ryan Pendergast committed Mar 8, 2016
1 parent 126bcb6 commit e76cfdc
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@
var gju = require('geojson-utils');

var leafletPip = {
bassackwards: false,
pointInLayer: function(p, layer, first) {
if (p instanceof L.LatLng) p = [p.lng, p.lat];
else if (leafletPip.bassackwards) p = p.concat().reverse();
bassackwards: false,
pointInLayer: function(p, layer, first) {
if (p instanceof L.LatLng) p = [p.lng, p.lat];
else if (leafletPip.bassackwards) p = p.concat().reverse();

var results = [];
var results = [];

layer.eachLayer(function(l) {
if (first && results.length) return;
if ((l instanceof L.MultiPolygon ||
l instanceof L.Polygon) &&
gju.pointInPolygon({
type: 'Point',
coordinates: p
}, l.toGeoJSON().geometry)) {
results.push(l);
}
});
return results;
}
layer.eachLayer(function(l) {
if (first && results.length) return;

if (isPoly(l) &&
gju.pointInPolygon({
type: 'Point',
coordinates: p
}, l.toGeoJSON().geometry)) {
results.push(l);
}
});
return results;
}
};

function isPoly(l) {
if (L.MultiPolygon) {
return (l instanceof L.MultiPolygon || l instanceof L.Polygon);
} else { //leaftletjs >= 1.0
return (l.feature && l.feature.geometry && l.feature.geometry.type && -1 != ['Polygon', 'MultiPolygon'].indexOf(l.feature.geometry.type));
}
}

module.exports = leafletPip;

0 comments on commit e76cfdc

Please sign in to comment.