forked from mapbox/leaflet-pip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 850 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var gju = require('geojson-utils');
function isPoly(l) {
return l.feature &&
l.feature.geometry &&
l.feature.geometry.type &&
['Polygon', 'MultiPolygon'].indexOf(l.feature.geometry.type) !== -1;
}
var leafletPip = {
bassackwards: false,
pointInLayer: function(p, layer, first) {
if (typeof p.lat === 'number') p = [p.lng, p.lat];
else if (leafletPip.bassackwards) p = p.concat().reverse();
var 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;
}
};
module.exports = leafletPip;