Reputation: 194
I want to log the coordinates each time I click on a feature on my map. What I do is:
When I click on the map I do call the map.on('singleclick')
function and get the featureInfo from the layer's features returned. The returned object looks like this:
geometry: Object
coordinates: Array[1]
type: "MultiPolygon
geometry_name: "the_geom"
id: "Kreise.5"
Where the coordinates array contains the desired coordinates. Then I call a function that will push the attributes: layer, geometry_name and coordinates to a geometry array.
var setGeometry = function (layer, geom, flatCoordinates) {
var geometry = [];
geometry.push([{
layer: layer,
geom: angular.uppercase(geom),
flatCoordinates: setFlatCoordinates(flatCoordinates)
}]);
console.log(geometry);
};
Unfortunately, everytime I click on the map and this function is called, it won't add new geometry objects to this array, it just overwrites the old attributes.
I tried to push these attributes to a local array in the map.on('singleclick')
function which will work as intended, but I'd like to have a solution which calls the function above. Any ideas?
Upvotes: 0
Views: 37
Reputation: 194
Nevermind, by re-reading this question I noticed that I should have declared the geometry array outside the called function. Since calling the function will always instantiate a new array and overwrite the old one.
Upvotes: 1