AnsweredAssumed Answered

Arcgis SDK - How to load tile with mbbox url?

Question asked by nhatdear1988 on Dec 22, 2017

I have stuck with load a tile with its data :

- BaseUrl : http://geogratis.gc.ca/maps/CBMT?service=wms&version=1.1.1&request=GetMap&format=image/png&bgcolor=0xFFFFFF&exceptions=application/vnd.ogc.se_inimage&srs=EPSG:900913&layers=CBMT&bbox={MBBOX}&width=256&height=256
- Lat:56.130366
- Long: -106.346771
- Zoom level : 7


After calculation, the tile info in world map is :

- zoom : 7 / x : 26 / y : 39
- EPSG:900913 Extent: (-11897270.578531113, 7514065.628545966, -11271098.442818949, 8140237.764258131
- FinalUrl to get PNG Tile : http://geogratis.gc.ca/maps/CBMT?service=wms&version=1.1.1&request=GetMap&format=image/png&bgcolor=0xFFFFFF&exceptions=application/vnd.ogc.se_inimage&srs=EPSG:900913&layers=CBMT&bbox=-11897270.578531113,7514065.628545966,-11271098.442818949,8140237.764258131&width=256&height=256

My current solution is extend the `ServiceImageTiledLayer` class. There are 2 things to do

1. Override the `getTileUrl` with the final URL above
2. Define the TileInfo

private static TileInfo CreateTileInfo(CoordinateBoundingBox box)
{
    int dpi = 96;
    Envelope envelope  = new Envelope( box.minX,box.minY,box.maxX,box.maxY,  SpatialReferences.getWebMercator());
    ArrayList<LevelOfDetail> levels = new ArrayList<>();
    double resolution = envelope.getWidth() / 256;
    double scale = resolution * dpi * 39.37;
    for (int i = 0; i < 19; i++)
    {
        LevelOfDetail l = new LevelOfDetail(i, resolution, scale);
        levels.add(l);
        resolution /= 2;
        scale /= 2;
    }
    return new TileInfo(dpi, TileInfo.ImageFormat.PNG, levels, new Point( box.minX , box.maxY, SpatialReferences.getWebMercator()), SpatialReferences.getWebMercator(), 256, 256);
}

 

The map can display the tile, but the resolution and the scale seem not right.
Please help me to fix the TileInfo implementation.

Outcomes