mapbox / leaflet-omnivore

universal format parser for Leaflet & Mapbox.js
https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-gpx/
Other
651 stars 126 forks source link

Multipolygons from topojson don't have feature object #19

Closed sabas closed 10 years ago

sabas commented 10 years ago

I'm using a topojson derived from a geojson (and properties preserved with -p flag), and it behaves correctly with polygons . I'm attaching events with this chain

.on('mouseover',mouseover_prov).on('mouseout',mouseout_prov).on('click',onMapClick_prov)

and each function has an e argument, but console.log shows e.layer.feature.properties only on Polygon type geometries. This gives an error when trying to populate a popup with properties.something..

The console.log trace is

s.Mixin.Events.fireEvent mapbox.js:1
s.FeatureGroup.s.LayerGroup.extend._propagateEvent mapbox.js:3
s.Mixin.Events.fireEvent mapbox.js:1
s.FeatureGroup.s.LayerGroup.extend._propagateEvent mapbox.js:3
s.Mixin.Events.fireEvent mapbox.js:1
s.Path.s.Path.extend._fireMouseEvent mapbox.js:3
t.(anonymous function).o
tmcw commented 10 years ago

More context (link to actual working demo) would be necessary to debug this. leaflet-omnivore's level of abstraction over topojson is very very thin, so it's likely issues are rooted elsewhere.

sabas commented 10 years ago

@tmcw here it is http://kode-tech.it/andrea/choro_bad/ief1_2009.html

ghost commented 10 years ago

it seems a bug...

tmcw commented 10 years ago

What seems like a bug isn't always a bug :) This is the classic MultiPolygon corner case in Leaflet: multipolygons do not have .feature: you'll need to iterate through eachLayer() to grab the .feature of a sub-layer (or bring this up in Leaflet core). Same effect is easily replicable with a L.geoJson layer or any other MultiPolygon-containing collection.

sabas commented 10 years ago

Thanks @tmcw appreciate it :-) I'll look into your suggestion.