Open gpsim opened 1 year ago
What happens if you try -y and not y in your template url.. ?
In this way, an error will be reported directly, and the layer resource cannot be requested
I see that the web side uses the proj4 and proj4leaflet.js plug-ins to call this layer. I don't know the flutter_ Does the map support proj4leaflet.js
Hmm, maybe this is an issue in proj4dart then? Have no idea, but there is not JavaScript dependency here!
I think our templateFunction
needs to be a little smarter for this to work in the "standard" way, like @ibrierley suggested:
What happens if you try -y and not y in your template url.. ?
https://wiki.openstreetmap.org/wiki/TMS
In JOSM, iD, Potlatch 2, and Merkaartor, you can use TMS tile sources (''e.g.'', for imagery background) which do the Y coordinates the TMS way, by simply inserting a minus in the tile URL specifier.
Right now, from what I can see, we don't take this into account when we build the tile URL from the template. On the other hand, if Baidu is using TMS tiles, there seems to be some sort of inversion of y
going on in _getTileUrl
. So simply setting the TileLayer
property tms: true
might help?
Would be prettier to handle this in the URL template though, since that seems to be the way others do it.
Typically all things being equal I think it makes sense to match up with what Leaflet.js does as much as possible.
Fair enough, they seem to be using the tms
flag for their tile layers.
@gpsim if you can clean up your example so it's easier to use it, it would also be easier for us to test. The formatting is all over the place and it looks like it contains some dead code as well.
(have tidied it up a bit, see if that helps)
The definition of TileProvider.invertY
seems a bit unintuitive:
int invertY(int y, int z) {
return ((1 << z) - 1) - y;
}
... or maybe this is not the intended purpose. With tms: true
and the following:
int invertY(int y, int z) {
return -y;
}
... the code seems to work.
It seems Leaflet does support -y
as well, which we don't: https://github.com/Leaflet/Leaflet/blob/main/src/layer/tile/TileLayer.js#L193
The confusing invertY
seems to come from: https://github.com/Leaflet/Leaflet/commit/d5e5f33d79d419988637097c7aea697ff3e0e469
This has since been fixed, to: https://github.com/Leaflet/Leaflet/blob/main/src/layer/tile/TileLayer.js#L189
EDIT: It also seems like we are unconditionally requesting retina/large tiles when r
is provided in the template?
https://github.com/fleaflet/flutter_map/blob/master/lib/src/layer/tile_layer/tile_provider/base_tile_provider.dart#L33
I tinkered a bit trying to align our code with Leaflet's but the tile layer code is so hairy... might be better to address this as part of a larger refactor.
This is as far as I got without making larger modifications. See my comments inline.
String _getTileUrl(String urlTemplate, Coords coords, TileLayer options) {
final z = _getZoomForUrl(coords, options);
// No easy access to _pxBoundsToTileRange in TileLayerState, also no access to projected tile bounds.
// Needless to call this for every tile if we have a globalTileRage which is always up-to-date
// ... but important to keep it up-to-date: https://github.com/ghybs/Leaflet.TileLayer.Fallback/pull/14
final globalTileRange = _pxBoundsToTileRange(options.tileSize, bounds);
final invertedY = '${(globalTileRange.max.y - coords.y).round()}';
final opts = <String, String>{
'x': '${coords.x.round()}',
// No check for !crs.infinite
'y': options.tms ? invertedY : '${coords.y.round()}',
// No check for !crs.infinite
'-y': invertedY,
'z': '${z.round()}',
's': getSubdomain(coords, options),
// Added retinaMode check
'r': options.retinaMode ? '@2x' : '',
}..addAll(options.additionalOptions);
return options.templateFunction(urlTemplate, opts);
}
// Duplicated code from TileLayerState
Bounds _pxBoundsToTileRange(num tileSizePx, Bounds bounds) {
final tileSize = CustomPoint(tileSizePx, tileSizePx);
return Bounds(
bounds.min.unscaleBy(tileSize).floor(),
bounds.max.unscaleBy(tileSize).ceil() - const CustomPoint(1, 1),
);
}
Yeah @JosefWN, we've come to a similar conclusion internally. There's so many features to add, fix and remove from TileLayer
, that it's worth rewriting it. Unfortunatley, we've got quite limited time, so we're not sure when we're going to get it done!
It's kind of difficult to visualise a rewrite of the tile layer I think without something a bit more concrete. I'm not sure what the specific aims and criteria would be. Maybe it needs to be part of a separate discussion about what's needed and how it would be interfaced to (especially with the notion of when we have multiple tile layers).
I certainly can understand the issues around access, as I've had similar myself and done my own version in the past here, so more than happy to ponder somewhere.
Yeah, I think several aspects need to change. In general: less is more, there are some features I doubt anyone is using (like controlling where fade-in animations start/stop). Everything comes with a cost, if not in performance then in maintenance. I think a sane way of looking at things in the long run is not "Is this a nice to have?" but rather "Is this something more people than the author of the PR will actually benefit from?". Forking is not that hard anyway, if you have really exotic needs.
Then there is the architectural issues; the current solution feels both complex and rigid. I can just intuitively tell that "something is not right" when I'm working with that piece of code, but I haven't thought further in terms of how to make it so.
Should we be making a Project to track things that might be added to a larger refactor/rewrite? Unfortunatley we can't add a project to the new Projects version on GitHub (lack of permissions), but we can create a 'classic' Project.
(We might want to do something similar to group issues about MacOS gestures (similar to something like #1395))
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.
I think this could be relabelled a bug, with TMS support being at least partially broken in flutter_map
.
The only (good) way to re-add TMS support is to get a MapCamera
through to the tile provider. At the moment, this will require a breaking change if I'm not mistaken.
What do you want implemented?
Hello, I tried to achieve Baidu layer tiles, but always render out of order.
http://online1.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1
What other alternatives are available?
I tried to modify the proj4 property with the following code.
Can you provide any other information?
Platforms Affected
Android, iOS
Severity
Obtrusive: No workarounds are available, and this is essential to me
Requirements