0

I have a carto-map that consists of four layers. The users of my map should have the option to choose the map projection. For one layer this works fine:

$('#selectProjection').on('click', function() {
            var srid = $(this).val();
            firstLayer.setSQL("SELECT cartodb_id, st_transform(the_geom, " + srid + ") as the_geom_webmercator FROM firsttable"); 
 });

But i have to project all four layers. If a add the same query just for another layer, there is no layer projected at all. This code doesn't work:

$('#selectProjection').on('click', function() {
            var srid = $(this).val();
            firstLayer.setSQL("SELECT cartodb_id, st_transform(the_geom, " + srid + ") as the_geom_webmercator FROM firsttable"); 
            secondLayer.setSQL("SELECT cartodb_id, st_transform(the_geom, " + srid + ") as the_geom_webmercator FROM secondtable");
});

Does anoyone have an idea?

EDIT: a js fiddle with the whole code: https://jsfiddle.net/nmrs11kq/11/

  • Why is it failing? Could you share the whole code? You can use a js fiddle or plkr link. – ramiroaznar Jun 21 '17 at 9:14
  • Thanks for replying. I added a link in the original post. – dijea Jun 21 '17 at 10:46
  • sorry, i had to update the link. i realized the code wasn't complete – dijea Jun 21 '17 at 11:04
  • You forget to add CARTO.js library, but I was able to replicate your issue. Have a look at my answer. – ramiroaznar Jun 21 '17 at 13:24
1

If you open your browser console and go to the Network tab, and look for the call that is triggered by your dropdown menu, there is a PostGIS error that tells you CARTO cannot transform some points located on certain latitudes:

Postgis Plugin: ERROR:  transform: couldn't project point (-37.543 -106.778 0): latitude or longitude exceeded limits (-14)\nin executeQuery Full sql was: 'SELECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_webmercator\",1e-05),1e-05,true),5) AS geom FROM (SELECT cartodb_id, st_transform(the_geom, 953009) as the_geom_webmercator FROM magmachron) as cdbq WHERE \"the_geom_webmercator\" && ST_SetSRID('BOX3D(-20037508.3 20037508.25881302,-20037508.25881302 20037508.3)'::box3d, 3857)'\n"],"errors_with_context":[{"type":"layer","message":"Postgis Plugin: ERROR:  transform: couldn't project point (-37.543 -106.778 0): latitude or longitude exceeded limits (-14)\nin executeQuery Full sql was: 'SELECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_webmercator\",1e-05),1e-05,true),5) AS geom FROM (SELECT cartodb_id, st_transform(the_geom, 953009) as the_geom_webmercator FROM magmachron) as cdbq WHERE \"the_geom_webmercator\" && ST_SetSRID('BOX3D(-20037508.3 20037508.25881302,-20037508.25881302 20037508.3)'::box3d, 3857)'\n

So it looks like the there are certain points within the magmachron dataset that you need to filter. You can check that when commenting these lines, the code works:

// magmachron.setSQL("SELECT cartodb_id, st_transform(the_geom, " + srid + ") as the_geom_webmercator" + " FROM magmachron");

Finally, you can find similar (working) application to the one your are building here.

  • Thank you very much! I absolutely ignored that it could be a data issue. – dijea Jun 21 '17 at 13:52

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.