I have a CARTO map displayed via Leaflet (specifically via Leaflet within the CARTO.js library) using carto.createlayer()
.
I simply want to get the_geom
values from each marker as they're clicked on. Layer interactivity is set to the_geom
but values are being returned as null
. I can get the code below to return the values of other columns in my dataset (such as cartodb_id
, site_id
, etc.), but I don't seem to be able to access the_geom
values using data.the_geom
.
cartodb.createLayer(map, {
user_name: 'codemacabre',
type: 'cartodb',
sublayers: [{
sql: 'SELECT * FROM hydrous_sites_geo_map',
cartocss: '#hydrous_sites_geo_map {marker-fill: #F0F0F0;}',
interactivity: 'cartodb_id, the_geom'
}]
})
.addTo(map)
.on('done', function(layer) {
layer.setInteraction(true);
layer.on('featureClick', function(e, latlng, pos, data) {
console.log(data.cartodb_id);
console.log(data.the_geom); // returns null
});
});
See the screenshots for the console output (top) and actual dataset values (bottom):
I've read that the_geom
can become corrupted when exporting / re-importing (such as in these issues: 1 & 2), but I'm unsure if that's the case here or if the_geom
protected somehow or (most likely) if I'm missing something obvious.
Is there a knack to returning the_geom
values?