Open theo2f opened 2 years ago
It looks like you are on the right track. This is the main code that you need.
static RectangleD GetWebMercatorTileLatLonBounds(int tileX, int tileY, int zoomLevel, int tileSize = 256)
{
if (zoomLevel < 0) throw new System.ArgumentException("zoomLevel must be >=0", nameof(zoomLevel));
PointD topLeft = TileUtil.PixelToWebMercator((tileX * tileSize), (tileY * tileSize), zoomLevel, tileSize);
PointD bottomRight = TileUtil.PixelToWebMercator(((tileX + 1) * tileSize), ((tileY + 1) * tileSize), zoomLevel, tileSize);
return RectangleD.FromLTRB(topLeft.X, bottomRight.Y, bottomRight.X, topLeft.Y);
}
protected override string FormatTileUrl()
{
//https://www.e-education.psu.edu/geog585/node/699
//bounding box specified by bottom left, top right coords
//create bounding box
var bounds = GetWebMercatorTileLatLonBounds(this.x, this.y, this.zoomLevel, 256);
//0,5009377.085697314,2504688.5428486555,7514065.628545967
string boundingBox = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00000000},{1:0.00000000},{2:0.00000000},{3:0.00000000}",
bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
string strUrl = string.Format(System.Globalization.CultureInfo.InvariantCulture, imageUrlFormat, boundingBox);
return strUrl;
}
I created a branch named WMS-Tile-Server-Test with some modifications to test this. I'm not going to push this into the main branch (yet) as it needs some testing and the example WMS you supplied seems very slow and is hard to test. If you're patient it does seems to download all the tiles eventually though.
If you pull down this test branch you can see the mods to get it working
Thank you very much, Winston! Working very well! I'm looking forward to seeing this in the main branch. I suggest you create a usage example, to make it easier for everyone.
About the performance on server that I sent the example, maybe you can use the URL below to make tests. Seems faster.
https://ahocevar.com/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=topp%3Astates&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX=-13775786.985667605%2C5009377.085697312%2C-13149614.849955441%2C5635549.221409475
Hi! How can I convert the XYZ Tile format to WMS Tile format? I see many maps on web using this format and I would like to use them.
URL sample: https://ies-ows.jrc.ec.europa.eu/gwis?service=WMS&request=GetMap&layers=admin.countries_borders&styles=&format=image%2Fpng&transparent=true&version=1.1.1&singletile=false&width=2048&height=2048&srs=EPSG%3A3857&bbox=0,5009377.085697314,2504688.5428486555,7514065.628545967
I did some things, like:
Tile URL
https://ies-ows.jrc.ec.europa.eu/gwis?service=WMS&request=GetMap&layers=admin.countries_borders&styles=&format=image%2Fpng&transparent=true&version=1.1.1&singletile=false&width=256&height=256&srs=EPSG%3A3857&bbox={bbLeft},{bbBottom},{bbRight},{bbTop}
Extend converter
}
It's working in part. Tiles is loaded, but it's not on the right position.
At moment I'm stuck on this and I can't go ahead. Can someone help me with this?