[英]Playing with loaded geojson makers on mapbox with javascript
My problem is more related to JS than to mapbox. 我的问题与JS有关,而不是与Mapbox有关。
I've loaded few geojson markers with different dates . 我加载了几个带有不同日期的geojson标记 。 The Geojson format is : Geojson格式为:
"Fri Oct 17 01:00:00 GMT+02:00 2008" “ 2008年10月17日星期五01:00:00 GMT + 02:00”
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'; 目前,我只能过滤指定的值,例如return f.properties ['LabelName'] ==='Rennes';
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. Mozilla控制台对我没有帮助。
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]
. match()
返回一个匹配数组 ,因此可以通过添加[0]
访问第一个匹配项。
Also use ==
to compare values, not ===
which compares objects. 也可以使用==
比较值,而不是使用===
比较对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.