Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,11 @@ | |
"files": [ | ||
"leaflet-pip.js" | ||
] | ||
}, | ||
"0.0.2": { | ||
"files": [ | ||
"leaflet-pip.js" | ||
] | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.leafletPip=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var pip = require('point-in-polygon'); | ||
|
||
function getLls(l) { | ||
var lls = l.getLatLngs(), o = []; | ||
for (var i = 0; i < lls.length; i++) o[i] = [lls[i].lng, lls[i].lat]; | ||
return o; | ||
} | ||
|
||
var leafletPip = { | ||
bassackwards: false, | ||
pointInLayer: function(p, layer, first) { | ||
'use strict'; | ||
if (p instanceof L.LatLng) p = [p.lng, p.lat]; | ||
if (leafletPip.bassackwards) p.reverse(); | ||
|
||
var results = []; | ||
layer.eachLayer(function(l) { | ||
if (first && results.length) return; | ||
// multipolygon | ||
var lls = []; | ||
if (l instanceof L.MultiPolygon) { | ||
l.eachLayer(function(sub) { lls.push(getLls(sub)); }); | ||
} else if (l instanceof L.Polygon) { | ||
lls.push(getLls(l)); | ||
} | ||
for (var i = 0; i < lls.length; i++) { | ||
if (pip(p, lls[i])) results.push(l); | ||
} | ||
}); | ||
return results; | ||
} | ||
}; | ||
|
||
module.exports = leafletPip; | ||
|
||
},{"point-in-polygon":2}],2:[function(require,module,exports){ | ||
module.exports = function (point, vs) { | ||
// ray-casting algorithm based on | ||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html | ||
|
||
var x = point[0], y = point[1]; | ||
|
||
var inside = false; | ||
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) { | ||
var xi = vs[i][0], yi = vs[i][1]; | ||
var xj = vs[j][0], yj = vs[j][1]; | ||
|
||
var intersect = ((yi > y) != (yj > y)) | ||
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi); | ||
if (intersect) inside = !inside; | ||
} | ||
|
||
return inside; | ||
}; | ||
|
||
},{}]},{},[1]) | ||
(1) | ||
}); |