5

I have a dataset that is in EPSG:27700 projection, but I have a tool that requests tiles for standard XYZ tiles.

So the endpoint currently returns tiles from localhost:3000/z/y/x.png (but it's in ESPG:27700)

I have a tool that requests tiles in a standard ESPG:3857 format again using /z/y/x.png.

Is there any way to adapt between then. I don't mind building some middleware that intercepts the get request modifies, and returns the correct tile.

1
  • 2
    Libraries like OpenLayers and Leaflet, combined with proj4.js, would take care of that for you.
    – TomazicM
    Aug 4, 2021 at 17:26

1 Answer 1

1

Lots of different choices here to solve this problem. One possible solution:

Either convert the coordinates from ESPG:3857 to EPSG:27700 before they go to the server (i.e. in JavaScript using proj4.js) or do so on the server side in the server side language of your choice. proj4 has bindings to many different programming languages.

For proj4.js on the client side the solution might look something like this:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.5/proj4.js"></script>
    <script>
            let longitude = -1.142578; // X
            let latitude = 52.052490; // Y
            
            const bcs = `+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`;
            //first number is longitude, next is latitude
            let result = proj4('EPSG:3857', bcs).forward([ longitude,latitude]);
            console.log(result) // your coordinates in EPSG:27700
            // Now send these coordinates back to the server.
    </script>

You will have to find a way to intercept the requests in the client side mapping library that you are using. The solution will look fairly similar if you happen to be using node.js on the server except you will load proj4 from it's npm module.

2
  • Thanks for that Eoin, going to give that a go now. I'll get back shortly.
    – paul_f
    Aug 7, 2021 at 17:03
  • @paul_f I realised I made a mistake in my code above; I just copy pasted and tweaked a bit from one of my codebases. It was to transform from WGS84 to BCS, not from EPSG:3857. My apologies. Proj4.js already comes with EPSG:3857 defined. I've edited my answer to reflect this. Hopefully this helps.
    – Eoin
    Aug 20, 2021 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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