mapbox - Leaflet-Omnivore make external file.geojson available to javascript variable -
i'm using omnivore extension load geojson files mapbox/ leaflet map. later, i'm using turf.js on data.
i'm loading external geojson file map customlayer, having trouble making geojson data available in variable pts use later.
var polylayer = l.geojson(null, { style: function(feature) { return { color: '#f00', weight: 1, opacity: 0.9 }; } }).addto(map); var polys = omnivore.geojson('polys.geojson', null, polylayer); var ptslayer = l.geojson(null, { oneachfeature: labeleachfeature, pointtolayer: function (feature, latlng) { return l.circlemarker(latlng, style(feature)) ;} }); var pts = omnivore.geojson('pts.geojson', null, ptslayer); polylayer.on('mouseover', function(e) { var matchingpoints = turf.featurecollection([]) matchingpoints.features = pts.features.filter(function(pt) { if(pt.properties.servesbldg === e.layer.feature.properties.bldg_no) return true }) ptslayer.setgeojson(matchingpoints); }); function getpoints(building, pts) { var matchingpoints = turf.featurecollection([]) matchingpoints.features = pts.features.filter(function(pt) { if(pt.properties.servesbldg === building.properties.bldg_no) return true }) return matchingpoints } here's gist of i've got including geojson files.
instead of using omnivore grab pts layer... why not declare pts variable, use jquery.getjson grab pts.geojson , assign response pts variable, call l.geojson(pts).addto(map). have layer added, , have original geojson structure available use in other places, need.
Comments
Post a Comment