Javascript 防止使用零值、地图框、传单打印缩放点
我正在用Mapbox js制作气泡图 问题是:如果点低于某个值,我会试图阻止点出现。当前显示的值为0 设置点的函数如下所示。我已经注释掉了一个不成功的if语句Javascript 防止使用零值、地图框、传单打印缩放点,javascript,maps,leaflet,mapbox,Javascript,Maps,Leaflet,Mapbox,我正在用Mapbox js制作气泡图 问题是:如果点低于某个值,我会试图阻止点出现。当前显示的值为0 设置点的函数如下所示。我已经注释掉了一个不成功的if语句 function layer(selecta){ geoJson = L.geoJson(geoJsonData, { pointToLayer: function(feature, latlng) { return L.circleMarker(latlng, {
function layer(selecta){
geoJson = L.geoJson(geoJsonData, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
color: '#c10000',
// if (parseInt(feature.properties[selecta]) < 50000){
radius: (Math.sqrt(feature.properties[selecta] / 3.141592) / 50)
// }
}).bindPopup('<h3>' + feature.properties.country + '</h3><p>' + 'Refugees, asylum seekers and IDPs in ' + currentYear + ': ' + numeral(feature.properties['yr' + currentYear]).format('0,0') + '</p>',{
closeButton: true,
minWidth: 320
});
}
}).addTo(map);
};
layer('yr2013');
如果我去掉值低于200的值,就像上面的例子一样,这将在控制台中返回一个错误。这些点仍然显示出来,但这是一次大规模的黑客攻击
有人能告诉我一个更干净的方法吗
X编辑X
我从来没有找到解决办法,但最终还是找到了解决办法
传单具有圆形标记器选项“不透明度”和“填充不透明度”
这是我的建议
所以我做了一个函数,如果值太小,它会返回零,这样标记就不会出现
但从技术上讲,它仍然存在。这个怎么样:
function layer(selecta){
geoJson = L.geoJson(geoJsonData, {
pointToLayer: function(feature, latlng) {
//I suppose this is an integer
var number_refugees = numeral(feature.properties['yr' + currentYear]);
if(number_refugees > 0){
var popup_content = '<h3>' + feature.properties.country + '</h3>'
+ '<p>' + 'Refugees, asylum seekers and IDPs in ' + currentYear + ': '
+ number_refugees.format('0,0') + '</p>';
return L.circleMarker(latlng, {
color: '#c10000',
radius: (Math.sqrt(feature.properties[selecta] / 3.141592) / 50)
}).bindPopup(popup_content),{
closeButton: true,
minWidth: 320
});
}
}
}).addTo(map);
};
layer('yr2013');
功能层(selecta){
geoJson=L.geoJson(geoJsonData{
pointToLayer:功能(特性、latlng){
//我想这是一个整数
变量编号=数字(特征属性['yr'+当前年份]);
如果(难民人数>0){
var popup_content=''+feature.properties.country+''
+“”+“难民、寻求庇护者和国内流离失所者在“+当前年份+”:”
+数字格式('0,0')+'';
返回L.circleMarker(车床{
颜色:“#c10000”,
半径:(Math.sqrt(feature.properties[selecta]/3.141592)/50)
}).bindPopup(弹出内容){
关闭按钮:对,
最小宽度:320
});
}
}
}).addTo(地图);
};
层('yr2013');
您是否尝试过使用Mapbox.js的.setFilter()
?它应该删除您不想要的功能,而不仅仅是使它们透明
谢谢,我已经试过了。当我运行该代码时,它返回无法设置未定义的属性“feature”。但我可以使用feature访问L.circleMarker函数中的对象。这很让人困惑,因为我没有使用=你能把它放到网上吗?我试过制作小提琴,但它依赖于依赖关系。另外,我没有自己的服务器,这不能发布到工作服务器上
function layer(selecta){
geoJson = L.geoJson(geoJsonData, {
pointToLayer: function(feature, latlng) {
//I suppose this is an integer
var number_refugees = numeral(feature.properties['yr' + currentYear]);
if(number_refugees > 0){
var popup_content = '<h3>' + feature.properties.country + '</h3>'
+ '<p>' + 'Refugees, asylum seekers and IDPs in ' + currentYear + ': '
+ number_refugees.format('0,0') + '</p>';
return L.circleMarker(latlng, {
color: '#c10000',
radius: (Math.sqrt(feature.properties[selecta] / 3.141592) / 50)
}).bindPopup(popup_content),{
closeButton: true,
minWidth: 320
});
}
}
}).addTo(map);
};
layer('yr2013');