简体   繁体   中英

Playing with loaded geojson makers on mapbox with javascript

My problem is more related to JS than to mapbox.

I've loaded few geojson markers with different dates . The Geojson format is :

"Fri Oct 17 01:00:00 GMT+02:00 2008"

I would like to filter markers per years. For the moment i was only able to filter specified value like return f.properties['LabelName'] === 'Rennes';

  • I thought of playing with regex like this :
 douze.onclick = function(e) { all.className = ''; this.className = 'active'; // The setFilter function takes a GeoJSON feature object // and returns true to show it or false to hide it. markerLayer.setFilter(function(f) { // First try wtih reGex on DateTime var stryear = f.properties['DateTime']; var reg20 = /20\\d*/g; console.log(stryear.match(reg20)); return f.stryear.match(reg20) === '2012'; }); return false; }; 

But it doesn't work. Does the regex return a good value? Mozilla console doesn't help me.

Thanks in advance for your help

I think you want this:

...
var reg20 = /20\d*/g;
console.log(stryear.match(reg20));
return f.stryear.match(reg20)[0] == '2012';

match() returns an array of matches, so access the first match by adding [0] .
Also use == to compare values, not === which compares objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM