I am trying to create an overlayMap by querying a Carto dataset using geoJson.

So far I have:

    var baseMaps = {
        "OSM B&W" : OpenStreetMap_BlackAndWhite,
        "Toner" : Stamen_Toner,
        "Relief Map": Stamen_TopOSMRelief, 
        "Satellite Imagery": Esri_WorldImagery

    var geojsonFeature = "http://sspradli.carto.com/api/v2/sql?      format=GeoJSON&q={SELECT * FROM mosquitosamplingsites";   

    var bicycleRental = L.geoJson(bicycleRental).bindPopup('Mosquito trap site');

    var overlayMaps={
    "Mosquito Sampling Sites": bicycleRental


You can view results here

  • What is your issue, can you elaborate? – Jorge Sanz Nov 26 '16 at 9:04

There are at least two problems with your jsbin code.

  1. You are not including Carto.js, instead you are using regular Leaflet

  2. You are not using the Carto SQL API to get geojson, which would look something this:

    var sql = new cartodb.SQL({ user: 'examples', format: 'geojson' });
    // create the layer and add to the map, then will be filled with data
    var countriesLayer = L.geoJson().addTo(map);
    sql.execute("SELECT * FROM european_countries_e").done(function(geojson) {

Maybe have a look at some of the Carto docs and tutorials?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.