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

Uncaught TypeError: Cannot read property '1' of undefined #23

Closed Craytor closed 7 years ago

Craytor commented 7 years ago

Hello! I'm trying to use this api library. I have my code looking like the following:

When I run this, and try to click on a polygon, all I get is this:

I hope I explained this enough, I'm not sure what else to say other than I've been banging my head off my desk the past few days.

Please let me know if you need any more additional information.

tmcw commented 7 years ago

Okay, looking into it! Fix is happening in #24 which should resolve at least one of the issues with Leaflet v1

tmcw commented 7 years ago

Thanks, this should be fixed in #24, which clears up some Leaflet v1 incompatibilities. Try out version 1.1.0: if it works, please close this issue. If it doesn't, please add a sample of the GeoJSON output from http://weather_api.dev/alerts so I can debug this further.

Craytor commented 7 years ago

Thanks, that was fast! So I went ahead and tried it, but I seem to be getting the same error (my fault possibly). I've went ahead and uploaded everything for testing purposes (I'll take it back down after we get this sorted out). The link of the app is here. Many thanks!

tmcw commented 7 years ago

Okay, tracked it down: there's a feature that looks like

{
  "type": "Feature",
  "id": "4a1a777ddffb28ed6caabd67eabf49bef002bf82",
  "properties": {
    "fill": "#483D8B",
    "fill-opacity": 0.9,
    "stroke": "#000000",
    "stroke-width": 2,
    "stroke-opacity": 0.9,
    "headline": "Winter Weather Advisory issued November 20 at 5:18PM EST until November 21 at 4:00AM EST by NWS Pittsburgh",
    "description": "...WINTER WEATHER ADVISORY REMAINS IN EFFECT UNTIL 4 AM EST\nMONDAY...\n* STORM TOTAL ACCUMULATIONS...4 TO 6 INCHES...EXCEPT UP TO 10\nINCHES ON THE RIDGETOPS OF EASTERN TUCKER COUNTY.\n* PERIOD OF MOST INTENSE SNOW...THROUGH THIS EVENING.\n* SNOW ENDING...MONDAY LATE MORNING.\n* WINDS...WEST 15 TO 25 MPH WITH GUSTS UP TO 40 MPH.\n* IMPACTS...ROADS MAY BECOME SNOW COVERED AND SLIPPERY. IN\nCOMBINATION WITH THE WIND...BLOWING SNOW MAY REDUCE\nVISIBILITY... MAKING TRAVEL DIFFICULT."
  },
  "geometry": {
    "type": "MultiPolygon",
    "coordinates": [
      []
    ]
  }
}

While this is technically valid GeoJSON, it's a very rare variation, such that leaflet-pip's internal algorithm, geojson-js-utils, is crashing on it. Omitting this feature (and any feature where the Polygon's coordinates look like [[]], with no actual positions) should fix the issue.

So: I've filed this issue upstream, and if I can get co-maintainership of that module I can fix it there. In the meantime, omitting these features (that won't display on the map anyway) should be a fair workaround.

Craytor commented 7 years ago

@tmcw Alright, that did seem to be the issue. I went ahead and made my API so it doesn't return an alert if it doesn't have any coordinates for now. In the mean time I'll continue to watch your open issue with the upstream.

Finally, this could be a related issue(?), but when I click on some of the polygons, it is returning an empty array (and there is no pop up on the map), while others are working fine. For example, the (only) polygon in Nebraska works fine, but the polygon in the most northern part of California, and also the most southern part of California are not working at all. Does this make sense? The link to the project is the same, and is available here.

Do you want me to open a separate issue, or is here ok?

Again thanks for your help, I greatly appreciate it.