jxmapviewer2
jxmapviewer2 copied to clipboard
tile size other than 256 using url with center lat/long
Thank you for this amazing lib !
I try to use it with goole maps static api and others provider. With these tiles providers, we have to use a center latitude,longitude
(version 2.3 from maven)
It works well with tile of 256px with the following code, but with other tile size the map displayed is not ok. Have you ever done some test with other tile size ??? 512 or 640, does it works ??? Is there any other change to do if the tile size change ????
MyTileFactoryInfo myTileFactoryInfo = new MyTileFactoryInfo("Google", 1, 20, 20, 256, true,true,"https://maps.googleapis.com/maps/api/staticmap", ....
in TileFactoryInfo Class I use this code to convert x/y to lat/long
public String getTileUrl(int x, int y, int zoom)
{
zoom = getTotalMapZoom() - zoom;
double xtile = x + 0.5;
double ytile = y + 0.5;
double n = Math.pow(2.0,zoom);
double lon_deg = ((xtile / n) * 360.0) - 180.0;
double lat_rad = Math.atan(Math.sinh(Math.PI * (1 - 2 * ytile / n)));
double lat_deg = (lat_rad * 180.0) / Math.PI;
...
}
Hello Lionel, I do not know how google maps provides the tiles. Are you sure they are provided as 512px images?
In any case, why would you want that? Is there an advantage of using bigger tiles?
Hello Martin, you can get googlemaps tiles with : https://maps.googleapis.com/maps/api/staticmap¢er=[LAT],[LONG]&key=[MY_KEY]&maptype=roadmap&size=256x256 Free key can be obtained at : https://developers.google.com/maps/documentation/static-maps/?hl=de It works well with the getTileUrl function posted above.
But with size=512x512, it doesn't works, tiles displayed are not correct.
I need to use 512x512 (or 640x640) which are the large dimension provided by google for free.
On each tile google add a watermark on the bootom, so with larger tiles this watermark is less annoying for example if the map size if around 4 tiles.
I can reproduce the problem. See the linked commit above. It looks like the tile rendering is correct.
The displayed images have overlapping content, so it's probably the computation of lat/lon values from the X and Y values that isn't correct for other tile sizes. Where did you get the formulas from?
I found the formula here : https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_bounding_box See Python - Tile numbers to lon./lat.
Hello martin, have you found some times to add support for tiles largest than 256px ??? It will be very interesting to support lots of tiles prividers with request with center lat/long (google, tomtom, herewego, mapquest,....)
I investigated a little and could not find any obvious error. If you have the time, it would be great if you could have a look yourself and open a PR for it.
Thanks, I did not found where the tile size was involved or any obvious error...
I found the error ... and more ... the Google Maps API aims at providing one single tile that covers the entire viewport. It therefore cuts off small bits of text reaching into the visible area. As a result the tiles are not really ... well .. tiling.
Is there anything OpenStreetMap does not cover? If so, you might want to try Nokia Here. The quality is impressive and it supports 512x512 tiles, too.