fnLoadMaps: function (mapDate, sId) {
let me = this; // this is an Ext JS ViewController object containing this and other defined functions
let baseUrl = '../resources/allmaps/';
let mapLayers = [];
Ext.Ajax.request({
url: '../resources/animap.php?m=getCountyMaps',
params: {
stateId: sId,
changedate: mapDate
},
success: function (response) {
me.countyGroup == null ? me.countyGroup = new L.layerGroup() : me.countyGroup.clearLayers();
let adCty = L.geoJson(null, {
style: function (feature) {
return { color: '#999999', weight: 1, fillOpacity: 0.1 };
}
});
let selColor = L.geoJson(null, {
style: function (feature) {
return { color: '#000000', weight: 1.5, fillOpacity: 0.3 };
}
});
let nonCty = L.geoJson(null, {
style: function (feature) {
return { color: '#ff3300', weight: 1, fillOpacity: 0.1 };
}
});
let customColor = L.geoJson(null, {
style: function (fetaure) {
return { color: '#4d2600', weight: 1, fillOpacity: 0.1 };
}
});
let rsp = Ext.JSON.decode(response.responseText);
let mapLayer = new L.Layer();
for (let x = 0; x < rsp.maps.length; x++) {
if (rsp.maps[x].obsoletedate === null || rsp.maps[x].obsoletedate >= mapDate) {
if (rsp.maps[x].map !== null) {
let locUrl = '../resources/allmaps/' + rsp.maps[x].map;
if (rsp.maps[x].stateId == sId) {
mapLayer = new L.Layer();
if (rsp.maps[x].map.indexOf('_NCA_') > 0) {
mapLayer = omnivore.kml(locUrl, null, customColor);
mapLayer.options.county = rsp.maps[x]; //This varies per loop by x
mapLayer.bindTooltip(function(layer) {
console.log(layer);
return layer.features.NAME; //Added as features is the problem. Omnivore sometimes does not return it from the XML conversion
});
} else {
mapLayer = omnivore.kml(locUrl, null, customColor);
mapLayer.bindTooltip(function (layer, cty) {
return layer.features.NAME;
});
}
me.countyGroup.addLayer(mapLayer);
}
}
}
}
me.countyGroup.addTo(me.map);
}
})
}
I am trying to add an object with additional data for the converted KML file using omnivore. The code below does add the county object to the layer and the layer is added to the map. However, the issue is, the county data is always the last county layer added. All individual layers end up with the same county data.
mapLayer = omnivore.kml(locUrl, null, customColor);
// console.log(mapLayer);
mapLayer.options.county = rsp.maps[x];
mapLayer.bindTooltip(function (layer) {
console.log(layer);
return '<strong>' + rsp.maps[x].name.toString() + '</strong>';
});
me.countyGroup.addLayer(mapLayer);
This is the case with every layer object. Reality is there are seven counties being added to a map and each has a different dataset I need to attach, allowing me to extract my information in a tooltip.
All KML files have a feature attribute in the files, however when omnivore converts some of these to GeoJSON it is dropping the features attribute all together.
So what is my error in getting a custom set of data attached to a Leaflet layer?
Added code to clear up how the process runs.
3