1

I am following Javi's tutorial on using non web Mercator tiles and successfully followed instructions and got it all working.

However, when I change to use my projection I would like to use I get the following error:Error: Invalid LatLng object: (NaN, NaN)

I have taken the Proj4 defintion from EPSG.io for British National Grid (EPSG:27700) and EPSG:27700 is declared in the PostGIS Spatial Ref Table.

I have tried a different projection, a random Australian one and that successfully worked, so am really confused why I am getting the error.

Can anyone help?

Code:

function main() {       
    var center = [51.479559, -0.241699]
    var map = new L.Map('map', {
      center: center,
      zoom: 4,
      crs: cartodb.proj('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs', '27700')
    });

    // add cartodb layer with one sublayer
    cartodb.createLayer(map, {
      user_name: 'tjmgis',
      type: 'cartodb',
      sublayers: [{
         sql: 'select cartodb_id, st_transform(the_geom, 27700) as the_geom_webmercator from world_borders',
         cartocss: '#layer { polygon-fill: #F00; polygon-opacity: 0.3; line-color: #F00; }'
      }]
    })
    .addTo(map)
  }
  window.onload = main;
1

The problem is in this function of the extension:

function mapToWGS84(pt) {
    pt = projection.inverse(mercator.forward([pt.lng, pt.lat]));
    return new L.LatLng(pt[1], pt[0])
}

mercator.forward returns a point outside projections bounds and it fails. That happens when the map view bounds go outside projection bounds.

as a side note you may want to add this to the query:

st_transform(ST_Intersection(the_geom, ST_MakeEnvelope(-13, 0, 13, 90, 4326)), 27700)

in other to make sure there is no geometry outside range (the bounds I used are not correct)

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.