For traditional WMS and TMS services, the origin is in the bottom left. However, for most of the BIG map services (google, bing, etc.) it is in the top left. This is causing my tiles to render in the incorrect position for my own little service. Is it possible to set the Tile Origin for a custom map tile source? This is a proving to be a very annoying stumbling block -- in that I can't configure xamGeographicMap and that I can't configure my map service to correctly serve up the tiles in the correct order. I only need one to work as desired and I can move forward.
In another post I mentioned that I was able to get my map service to render with "gmaps" compatibility, however, my excitement fizzled when I discovered some kind of bug or configuration issue on the server that serves up the tiles incorrectly after a certain zoom level. I am attempting to use GeoServer, however, it does not yet provide a way to change the origin for my map service.
Hi Kristopher,
Are you talking about the coordinate system used in the XamGeographicMap versus what your custom tile service is using? Where the geomap works off a system that has tile (0,0) at the top-left and your service has (0,0) at the bottom-left? Currently this can't be changed. If you have written a custom MapTileSource for the geomap, in the GetTileLayers method it will ask you to provide tile URIs while giving you the X and Y coordinates of the tile it wants. These coordinates are based on the top-left origin system.
What you will need to do is transform the coordinates to a bottom-left system. So when the geomap asks for (0,0), you need to give it your (0,4) tile instead (assuming 4 is the maximum number of tiles for the current zoom level). You would do this inside your GetTileLayers method inside the custom MapTileSource.
Most of the time if I'm stuck on something, its causing I'm missing some obvious and simple solution. Your answer seems simple enough -- how are MaxX and MaxY calculated? Are they just powers of 2 based on the level?
It appears to be that way. The first level always seems to ask for a 2x2 tileset, the second level asks for 4x4, then 8x8, 16x16 etc.
Suggestion works like a charm.
int zoom = tileLevel - 8; int invY = (int)Math.Pow(2.0, zoom) - tilePositionY - 1;
int zoom = tileLevel - 8;
int invY = (int)Math.Pow(2.0, zoom) - tilePositionY - 1;
I just put that into GetTileLayers(). I guess if I was really worried about performance I could pre-calculate all of the powers of 2 into an int array at application startup and then just do a quick lookup with pow2[zoom].