按层 id 类别过滤传单
leaflet filtering by layer id categories
我已经修改了这段代码来创建类别标签数组 - 我想获取每个 tagCategory 组,如果它的标签参考切片匹配某些功能 - 通过其标签名称将其作为变量添加到列表中(以供使用用于过滤标记)
这是我的代码 - adapted from here
let ind00ss00test = new L.layerGroup();
console.log(ind00ss00test)
let LR1test = new L.layerGroup()
const subGroups1 = [];
d3.json(mapsData, function(data){
industry = L.geoJSON(data, {
pointToLayer: function (feature){
return new L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], {
className: feature.properties.HASHcodePM,
radius: getRadius(feature.properties.size),
fillOpacity:0.8,
color: getColor(feature.properties.type),
fillColor: getColor(feature.properties.type),
weight: getRadius(feature.properties.size)/3,
})
},
onEachFeature: function(feature, layer) {
layer.bindPopup("Name: " + feature.properties.Name + "<br>Type: "+ feature.properties.type)
var HASHcode = feature.properties["HASHcodePM"];
var INDSShash = feature.properties.HASHcodePM.slice(0,9); //INDSS
var LRhash = feature.properties.HASHcodePM.slice(9,12); //LR
var tagCategories = subGroups1[HASHcode];
if (!tagCategories) {
tagCategories = subGroups1[HASHcode] = L.geoJson();
} tagCategories.addLayer(layer);
if (INDSShash == "IND00SS00") tagCategories.addTo(ind00ss00test);
if (LRhash == "LR1") tagCategories.addTo(LR1test);
},
})
});
所以我想获取引用标签切片的标签 -
我想在 'overlayremove' 上使用 属性 LR1 过滤图层中的标记:
const content = L.layerGroup().addTo(myMap);
myMap.on('overlayadd overlayremove', () => {
if (myMap.hasLayer(ind00group)) {
ind00ss00test.addTo(content))
}
if (myMap.hasLayer(ind99group)) {
ind00ss99test.addTo(content))
}
if (!myMap.hasLayer(LR1Group)) {
LR1test.forEach(marker => content.removeLayer(marker))
}
})
ind00ss00test 可以是 added/removed,但标记不会使用 LR1test.forEach 进行过滤(如果取消选择 LR1,我只需要从添加的图层组中过滤标记。)所以本质上 -我希望能够获取这些图层组并根据类似功能将它们作为变量动态添加到列表中 - such as this - 而无需按名称手动添加每个图层组。
如有任何建议,我们将不胜感激。
好吧,我想通了,如果有人好奇的话。保持与上面相同的代码并替换这些 variables/options:
let lr1group = L.layerGroup()
let ind00ss00group = L.layerGroup()
let lr1List = [];
let ind00ss00List = [];
if (INDSShash =='IND00SS00' ) ind00ss00List.push(tagCategories);
if (LRhash == "LR1") lr1List.push(tagCategories);
const content = L.layerGroup().addTo(myMap);
// filter selection
myMap.on('overlayadd overlayremove', () => {
if (myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker=> marker.addTo(content))
}
if (!myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker => content.removeLayer(marker))
}
if (!myMap.hasLayer(lr1group)) {
lr1List.forEach(marker => content.removeLayer(marker))
}
})
我已经修改了这段代码来创建类别标签数组 - 我想获取每个 tagCategory 组,如果它的标签参考切片匹配某些功能 - 通过其标签名称将其作为变量添加到列表中(以供使用用于过滤标记)
这是我的代码 - adapted from here
let ind00ss00test = new L.layerGroup();
console.log(ind00ss00test)
let LR1test = new L.layerGroup()
const subGroups1 = [];
d3.json(mapsData, function(data){
industry = L.geoJSON(data, {
pointToLayer: function (feature){
return new L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], {
className: feature.properties.HASHcodePM,
radius: getRadius(feature.properties.size),
fillOpacity:0.8,
color: getColor(feature.properties.type),
fillColor: getColor(feature.properties.type),
weight: getRadius(feature.properties.size)/3,
})
},
onEachFeature: function(feature, layer) {
layer.bindPopup("Name: " + feature.properties.Name + "<br>Type: "+ feature.properties.type)
var HASHcode = feature.properties["HASHcodePM"];
var INDSShash = feature.properties.HASHcodePM.slice(0,9); //INDSS
var LRhash = feature.properties.HASHcodePM.slice(9,12); //LR
var tagCategories = subGroups1[HASHcode];
if (!tagCategories) {
tagCategories = subGroups1[HASHcode] = L.geoJson();
} tagCategories.addLayer(layer);
if (INDSShash == "IND00SS00") tagCategories.addTo(ind00ss00test);
if (LRhash == "LR1") tagCategories.addTo(LR1test);
},
})
});
所以我想获取引用标签切片的标签 -
我想在 'overlayremove' 上使用 属性 LR1 过滤图层中的标记:
const content = L.layerGroup().addTo(myMap);
myMap.on('overlayadd overlayremove', () => {
if (myMap.hasLayer(ind00group)) {
ind00ss00test.addTo(content))
}
if (myMap.hasLayer(ind99group)) {
ind00ss99test.addTo(content))
}
if (!myMap.hasLayer(LR1Group)) {
LR1test.forEach(marker => content.removeLayer(marker))
}
})
ind00ss00test 可以是 added/removed,但标记不会使用 LR1test.forEach 进行过滤(如果取消选择 LR1,我只需要从添加的图层组中过滤标记。)所以本质上 -我希望能够获取这些图层组并根据类似功能将它们作为变量动态添加到列表中 - such as this - 而无需按名称手动添加每个图层组。
如有任何建议,我们将不胜感激。
好吧,我想通了,如果有人好奇的话。保持与上面相同的代码并替换这些 variables/options:
let lr1group = L.layerGroup()
let ind00ss00group = L.layerGroup()
let lr1List = [];
let ind00ss00List = [];
if (INDSShash =='IND00SS00' ) ind00ss00List.push(tagCategories);
if (LRhash == "LR1") lr1List.push(tagCategories);
const content = L.layerGroup().addTo(myMap);
// filter selection
myMap.on('overlayadd overlayremove', () => {
if (myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker=> marker.addTo(content))
}
if (!myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker => content.removeLayer(marker))
}
if (!myMap.hasLayer(lr1group)) {
lr1List.forEach(marker => content.removeLayer(marker))
}
})