mapbox / leaflet-pip

point in polygon intersections for leaflet
https://mapbox.github.io/leaflet-pip/
BSD 2-Clause "Simplified" License
199 stars 46 forks source link

any reason this shouldn't work with leaflet-headless? #19

Closed doapp-ryanp closed 8 years ago

doapp-ryanp commented 8 years ago

I have a geoJson file of a bunch of NWS alert zone polygons in it. I simply want to find what polygon (if any) a given lat/lng point is in. I want to do this entirely headless (no browser).

I'm using leaflet-headless and leaflet-pip to try and pull this off - but I keep getting a [TypeError: Expecting a function in instanceof check, but got undefined] error when I invoke leafletPip.pointInLayer().

Before I spend lots of time digging into the leaflet[-pip] code, was wondering if you knew off the top of your head why this would not work? Here is my code:

let Promise    = require('bluebird'),
    fs         = Promise.promisifyAll(require("fs")),
    srcDataDir = __dirname + '/../srcData',
    L          = require('leaflet-headless'),
    leafletPip = require('leaflet-pip');

module.exports.generate = function() {
  let rochesterMn = {
    lat: 44.0150757,
    lng: -92.4775256
  };

  return fs.readFileAsync(srcDataDir + '/simplifiedZones.geojson')
    .then(data => {
      var geoJSON = {};
      try {
        geoJSON = JSON.parse(data);
      } catch (err) {
        throw err;
      }

      let ugcZoneLayer = L.geoJson(geoJSON);

      let foundPoly = leafletPip.pointInLayer([rochesterMn.lng, rochesterMn.lat], ugcZoneLayer, true);

      console.log(foundPoly);
  });
};

thanks in advance. FWIW im on OSX

doapp-ryanp commented 8 years ago

Sorry I got decided to dig in. Fix was straight forward. In Leafelet v1.0 there are no more Polygon classes

tmcw commented 8 years ago

Closing in favor of #8

doapp-ryanp commented 8 years ago

Thanks. Is there a plan to get the change into a published module any time soon? Your module here is great but we can't use it as it sits.