New StackOverflow Question: Button Filter not working on Mapbox?

3 views
Skip to first unread message

stacko...@mg.bodar.com

unread,
Mar 7, 2017, 5:10:33 AM3/7/17
to total...@googlegroups.com

Button Filter not working on Mapbox?

Asked by Charles Harrison on 2017-02-17T06:28:10Z

Reply on StackOverflow

I have succesfully created a filter for magnitude on my website see code

 document.getElementById('filters').addEventListener('change', function(e) {
var mag = e.target.value;
var filtermag;
if (mag === 'Mag6') {
filtermag = ['in', 'mag', 6.0,6.1,6.2,6.3,6.4,6.5,6.6,6.7,6.8,6.9];
} else if (mag === 'Mag5') {
filtermag = ['in', 'mag', 5,5.1,5.2,5.3,5.4,5.5,5.6,5.7,5.8,5.9];
} else if (mag === 'Mag4') {
filtermag = ['in', 'mag', 4.5,4.6,4.7,4.8,4.9,5.0];
} else {
console.log('error');
}
map.setFilter('earthquake-layer', filtermag);

Now I am trying to create a time filter (Earthquakes which have happened last 24 hours, 1 week etc). Because time is always changing i copied the code (Not sure if this would be right)

 var msElapsed = Date.now() - time;

and the filter looks like this

   document.getElementById('filterss').addEventListener('change',           function(e) {
 var msElapsed = e.target.value;
 var filtermsElapsed;
 if (msElapsed === '24h') {
 filtermsElapsed = ['<', 'msElapsed', 360000000];
 } else if (msElapsed === '48h') {
 filtermsElapsed = ['>', 'msElapsed', 360000000];
 } else {
 console.log('error');
 }
 map.setFilter('earthquake-layer', filtermsElapsed); 
 });

I am fairly lost of this. I'm pretty sure I have to put that first piece of code in Date.now-time of earth of earthquake to get a value.

Can anyone understand what I am trying to do/ point me in the right direction in making this work

Thanks

Reply on StackOverflow
Reply all
Reply to author
Forward
0 new messages