compare geojson fields

14 views
Skip to first unread message

Ariel DeGennaro

unread,
Oct 6, 2016, 9:39:56 AM10/6/16
to Leaflet
I have a map with lines and points
I want to use the oneachfeature on the points to check if the feature.properties.name field matches any name field in the line geojson and if it does, bind the same popup as is bound to the line (using data in the line geojson).

Pat Keller

unread,
Oct 6, 2016, 11:41:46 PM10/6/16
to Leaflet
Build a hashmap mapping the line name to its popup. Then when you loop through the points, check if a key exists in the lineMap for the point name. If it does, assign the same popup to the point.


This is psuedocode, but should give you a good idea.

var lineMap;
var pointMap;

for(var line in geojsonLines){
var linePopup=createPopup(xxx);
lineMap[line.properties.name] =linePopup;
}

for(var point in geojsonPoints){
if(lineMap.hasOwnProperty(point.properties.name)){
pointMap[point.properties.name] =lineMap[point.properties.name];
} else{
var pointPopup = createPopup(xxx);
pointMap[point.properties.name] = pointPopup;
Reply all
Reply to author
Forward
0 new messages