dcfemtech / hackforgood-waba-map

DCFemTech Hack for Good 2016 - WABA Bike Map Project
MIT License
10 stars 9 forks source link

Fix Dropdown Menu #57

Closed NealHumphrey closed 8 years ago

NealHumphrey commented 8 years ago

Dropdown menu currently not working (layers menu is working)

NealHumphrey commented 8 years ago

@alulsh: digging back through the code it looks like the dropdown menu was only ever connected to the dynamic rebuffer calculation, and was never connected to the preloaded buffers. So pulling the code out of the git history won't work.

It's relatively simple to make the functions to do the filtering, but since I'm writing from scratch I'd rather approach it a bit more holistically. In particular, I'd like to refactor these variables:

var dcBuffer500 = L.mapbox.featureLayer().addTo(map);
var dcBuffer1000 = L.mapbox.featureLayer();
var dcBuffer2500 = L.mapbox.featureLayer();
var dcBuffer5280 = L.mapbox.featureLayer();

I'm thinking of adding a new category to the GeoJSON (i.e. buffer distance), so that we can merge all the data into one buffer variable and add a more universal filter function. This would allow us to more easily expand our filter/color coding criteria in the future (i.e. separated lanes vs. trails vs. standard, by county)

What do you think? Alternative is a quick and dirty toggle with our existing variables.

NealHumphrey commented 8 years ago

p.s. this could go hand-in-hand with the other function I mentioned (admin generate buffers) since I can custom fields to the GeoJSON as we parse it from each source - or at least set it up to be able to do so later.

alulsh commented 8 years ago

we can merge all the data into one buffer variable

Can you elaborate on this point? We need four separate featureLayers for the four different buffers (for as long as we pre-generate buffers to workaround https://github.com/dcfemtech/hackforgood-waba-map/issues/1, which is explained in more depth in https://github.com/dcfemtech/hackforgood-waba-map/pull/8). This sounds like it would create only one featureLayer on the map.

This would allow us to more easily expand our filter/color coding criteria in the future (i.e. separated lanes vs. trails vs. standard, by county)

This is great! I like the forward thinking 👍

NealHumphrey commented 8 years ago

Instead of adding and removing featureLayers from the map (.featureLayer().addTo(map);), I was thinking we'd put all the buffers into one layer and use the setFilter function provided by featureLayer to toggle which ones are shown.

At a minimum we can wrap the current variables in a map that directly connects the distance (e.g. 500 or 1000) to the featureLayer. Then you can iterate over them instead of having to manually maintain a list of which buffer layers you have anywhere you need to use it. Like this (note untested code example):

var buffer = {};
//.loadURL returns the layer object so it is what is assigned to the variable
buffer['500'] = L.mapbox.featureLayer().loadURL('./buffers/DC_Bike_Buffer_500ft.geojson')
buffer['1000'] = L.mapbox.featureLayer()

Object.keys(buffer).forEach(function (key) {
   console.log(key) //the distance, e.g. 500
   var currentLayer = buffer[key]
});
tomBeach commented 8 years ago

See comment for "Admin tool to generate buffers on demand" issue...

alulsh commented 8 years ago

No longer using a drop down menu after https://github.com/dcfemtech/hackforgood-waba-map/pull/78. Closing.