-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with rendering OS Maps Leisure Layers #28
Comments
Hi @nbarrett. I haven't done much in the the way of development with react-leaflet... however (looking at the problematic tile request) it would appear that the issue relates to the following:
As you have suggested there shouldn't be any reason why a react-leaflet app cannot utilise the Proj4JS and proj4Leaflet libraries. I therefore think the problem might be coming down to the |
Thanks @tmnnrs for your response. There were a few typos in my Layer data and I was getting the layer name slightly wrong as in the OS Maps API Demo, it's encoded into
In order to better understand the behaviour differences, I've done a like-for-like comparison of querystring parameters between the working OS Maps API Demo and my from My App via react-leaflet and it seems that the thing that's wrong is the setting of the tileCol, tileMatrix and tileRow which are all wildly out. From OS Maps API Demo https://api.os.uk/maps/raster/v1/wmts? From My App via react-leaflet https://api.os.uk/maps/raster/v1/wmts?key= The thing that confuses me is that with react-leaflet you supply a url with placeholders on the end e.g. |
Provided the CRS has been set within the map options - all the parameter calculations should be calculated automatically. It feels like the CRS isn't getting set... meaning the map is defaulting to Web Mercator (EPSG:3857) hence the incorrect tileMatrix + tileRow + tileColumn values. There is https://github.com/OrdnanceSurvey/tile-name-derivation to help with the mathematical relationships which can be used to derive tile names (ZXY and WMTS) from coordinates at a particular zoom level and vice-versa, however the Proj4JS and proj4Leaflet libraries should be taking away this headache. Have you seen the OS Data Hub Examples? These are vanilla JS + Leaflet code examples, but they might offer some further insight into where the react-leaflet setup might be going wrong. |
Thanks @tmnnrs - you got me on the right track!! For anyone else looking for a solution to this (I've seen a few people asking about this on stack overflow and no responses exist on there), the answer was that I needed to add a custom CRS - I did this in the form of a custom hook
With that hook defined, you can then use it the vicinity of your
Example of app now working at: https://oscillation-production.up.railway.app/ - and commit that delivered the above Footnote: Might be a good idea to provide some other examples in this repo (especially react-leaflet) or example projects built with more "current" tooling as I suspect the majority of developers are not building pure html solutions nowadays? |
Background to Problem
I'm developing a typescript react web application using the react-leaflet library. A more detailed tooling list is documented on the readme of my github project. I've already got a deployed version up and running that you can take a look at.
I initially built the app to use the OpenStreetMaps mapping provider as this was easier to get the auth setup, but the target application really needs to use the
Leisure_27700
Layer of OS Maps API. So for diagnostics, comparison and testing, I can now switch between different mapping providers in the UI.Everything's working quite well until I switch to the OS Maps
Leisure_27700
Layer, at which point the maps don't render. Under the covers, react-leaflet is issuing a series of get requests to the API e.g. https://api.os.uk/maps/raster/v1/wmts?key=mykeyremoved&service=WMTS&request=GetTile&version=1.0.0&style=default&layer=Leisure_027700&tileMatrixSet=EPSG:27700&tileMatrix=18&tileRow=87172&tileCol=131005.However on the specified 27700 Layer selections, I get HTTP 400 response from the OS Maps API with payload responses in the browser:
When I choose other Layers e.g. Light_3857 the application works okay. I've got an OSMaps developer premium account and the api key works in other OS-Data-Hub demo applications for instance: https://github.com/OrdnanceSurvey/OS-Data-Hub-API-Demos/tree/master/OSMapsAPI/Leaflet/Proj4Leaflet, so it does not seem to be a problem with me trying to access data I'm not entitled to.
The OS-Data-Hub-API-Demos demos do not use react-leaflet but use lower-level leaflet javascript for example here, so it's hard to see why these apps work but mine doesn't. Note that all parameters are passed by react-leaflet to the API using query string parameters and there is no http header setting. Could you let me know what I might be doing wrong please?
Steps to reproduce
Please see my production deployment where you can choose between the different layers and see the behaviour outlined in this issue.
You can go into developer tools in Chrome and see the urls being attempted.
Thanks in advance for your help!
The text was updated successfully, but these errors were encountered: