-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
Can I use a tile provider that accepts a different crs than the one used by my FlutterMap? #890
Comments
I'm not that familiar with CRSs but when you say you are unable to convert the coords, how far did you get. |
Btw there's a bit about custom CRS on the main docs.. https://github.com/fleaflet/flutter_map half way down |
I tried using To be clear, converting latitude and longitude is straightforward, there are methods for that in the Epsg3006 class. However, in the TileProvider you only have access to the "tile coordinates" (x/y and zoom), and I don't know how to convert those.
Thanks, I read it but it seems to apply to WMS layers? I'm not exactly sure how these things all relate, but my URL's are on the format |
Maybe it would be useful to show a link or whatever to which class you are looking at for Epsg3006. May trigger some ideas. |
I have this problem as well. Maybe we should make a pull request to add this feature to standard tile layers? |
Not sure why it needs a feature added to tile layers, you can pass a custom crs into MapOptions, so wouldn't that be the correct way to go ? Or am I misunderstanding what the point of the option is ? |
You're right, but if we want to use a single FlutterMap widget with multiple layers, each (possibly) with a different CRS (unless I misunderstand MapOptions... 🤣). |
What I'm currently doing is using a stateless widget, and setting the layer and CRS as a parameter. Simplified code: final Crs curCrs;
final TileLayerOptions curLayer;
final LatLngBounds initialBounds;
MyMap(this.curCrs, this.curLayer);
Widget build(BuildContext context) {
return FlutterMap(
mapController: mapController,
options: MapOptions(
crs: curCrs,
bounds: initialBounds,
// ...
),
layers: [
curLayer,
// ...
]
);
} |
Thanks @1075dn - I tried that, but it seems that other plugins, for example |
I don't use
Yup, me too. I'm still trying to figure out a solution to that. If you do first, let me know 😉! |
I've looked into it a bit. Since projections are different ways that points on the globe can be mapped to 2D x/y coordinates, it's impossible to display multiple layers projected with separate CRS, one above the next, without either:
Bad idea, me. However, people have been able to swap between two different CRS (showing one layer or the other, not both at the same time) with Leaflet (what
Apparently both @magnuswikhog and I are having trouble figuring out how to do this in Flutter. (I tried using a |
Maybe @kengu can confirm what I wrote about how projections work, and possibly also explain why |
@1075dn The reason why WMS supports crs in options is because it's part of the WMS standard, see below where each layer could be projected using different coordinate reference system. The backend is typically either 1) rendering dynamically from vectors using SLD combined with dynamic caching for improved response on repeated calls for same tile, or 2) wms tiles on all zoom levels are preprocessed into each supported projection. Reprojection tiles from one CRS to another on the client-side is less common on raster-formats because of the reasons you outlined above. For vector formats however, projections are always applied and hence it is less of a problem to support different crs there. |
Thanks for the detailed explanation, @kengu! So setting the CRS on a WMSTileLayer explicitly requests the WMS server to project the tiles with the same CRS as the other layers of the map, and does not (like I thought at first) allow a map to have layers with different projections. |
@1075dn Not exactly, it works like you would expect; Tiles returned from the WMS-service is projected using the crs supplied. This is perfectly fine as long as layers visible at the same time (baselayer + overlays) have the same crs. The conversion between screen, geodesic (lat/ln) and projected (i.e cartesian) coordinates uses the crs supplied in the layer, not the crs supplied in MapOptions. |
@kengu Thanks for clarifying! I didn't mean that it forced you to use the |
Also, by the way @kengu, do you have any solutions to switching the |
Correct. This must be managed outside of flutter_map. The same goes for changing MapOptions dynamically, which are always read from the current FlutterMap widget in FlutterMapState, see All you need to do is to build MapOptions from parameteres controlled outside of FlutterMap in the build method building FlutterMap, forcing rebuilds dynamically using a stateful widget og widget builder of you choice. The naive solution is to wrap FlutterMap with a stateful widget and call setState after changing som parameter that MapOptions are built from. |
Thanks @kengu - that works! |
I use a MapController to handle this. You can ensure zoom stays the same by setting zoom in options equal to zoom in map controller when building a new instance of MapOptions. edit: I don't know if this helps though on your problem - probably not after some additional thought. You probably need to compensate for the change before setting zoom-level after changing to another crs. |
I guess I need to figure out if there is any way to 'convert' zoom levels between |
Just thinking out loud, as can't recall what methods are aren't private, but can you get pixelbounds from both crs's and take the ratio difference between them, and then scale the zoom by that ? |
Erm, not quite sure that makes sense actually...need to look at code before speaking! |
The idea proposed by @ibrierley sounds reasonable. If that does not work out, you probably need to known more about the zoom levels used by the backend service you are consuming tiles from. Something like this from MapBox: |
@ibrierley I think only plugins can access the map state (which contains functions like @kengu Thanks for the tip - if I can't get something working with the existing functions, I'll try that... |
Is there any way for a |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue was closed because it has been stalled for 5 days with no activity. |
I have a FlutterMap that uses Epsg3857 CRS, but I want to be able to use a tile URL that is supposed to be used with Epsg3006. Is this possible?
I tried creating a custom TileProvider, but I'm unable to convert the Coords from Epsg3857 tile coordinates to Epsg3006 tile coordinates.
Any ideas?
The text was updated successfully, but these errors were encountered: