《ArcGIS Runtime SDK for Android开发笔记》——(13)、图层扩展方式加载Google地图

1、前言

http://mt2.google.cn/vt/lyrs=m@225000000&hl=zh-CN&gl=cn&x=420&y=193&z=9&s=Galil

通过图层扩展类的方式加载Google地图的是我们通常获取Google地图的一种方式,根据这种方式我们可以通过拼接地图瓦片Url字符串获取瓦片数据,关于Google瓦片算法的解析网上有很多,以下仅列出博客地址,及具体实现类。

Google瓦片地图算法解析 :http://blog.csdn.net/hugoandpig/article/details/7719307

转载请注明出处:http://www.cnblogs.com/gis-luq/p/5443498.html 

2、Google地图的自定义扩展类

package com.seraph.collect.BaseComp.MapLayer;

import java.util.Map;
import java.util.concurrent.RejectedExecutionException;

import android.util.Log;

import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;

/**
 *Google地图加载
 */
public class GoogleMapLayer extends TiledServiceLayer {

    private int minLevel = 0;
    private int maxLevel = 19;

    private String[] subDomains = new String[] { "mt1", "mt2", "mt3" };

    private double[] scales = new double[] { 591657527.591555,
            295828763.79577702, 147914381.89788899, 73957190.948944002,
            36978595.474472001, 18489297.737236001, 9244648.8686180003,
            4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289,
            288895.277144, 144447.638572, 72223.819286, 36111.909643,
            18055.954822, 9027.9774109999998, 4513.9887049999998, 2256.994353,
            1128.4971760000001 };
    private double[] resolutions = new double[] { 156543.03392800014,
            78271.516963999937, 39135.758482000092, 19567.879240999919,
            9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
            1222.9924525624949, 611.49622628138, 305.748113140558,
            152.874056570411, 76.4370282850732, 38.2185141425366,
            19.1092570712683, 9.55462853563415, 4.7773142679493699,
            2.3886571339746849, 1.1943285668550503, 0.59716428355981721,
            0.29858214164761665 };

    private Point origin = new Point(-20037508.342787, 20037508.342787);

    private int dpi = 96;

    private int tileWidth = 256;
    private int tileHeight = 256;

    public GoogleMapLayer() {
        super(true);
        this.init();
    }

    private void init() {
        try {
            getServiceExecutor().submit(new Runnable() {
                public void run() {
                    GoogleMapLayer.this.initLayer();
                }
            });
        } catch (RejectedExecutionException rejectedexecutionexception) {
            Log.e("Google Map Layer", "initialization of the layer failed.",
                    rejectedexecutionexception);
        }
    }

    protected byte[] getTile(int level, int col, int row) throws Exception {
        if (level > maxLevel || level < minLevel)
            return new byte[0];
        String subDomain = subDomains[(level + col + row) % subDomains.length];
    
     //构建待拼接字符串
     String _mapType = "m@225000000"; String url = "http://" + subDomain + ".google.cn/vt/lyrs=" + _mapType + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; Map<String, String> map = null; return com.esri.core.internal.io.handler.a.a(url, map); } protected void initLayer() { if (getID() == 0L) { nativeHandle = create(); changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS .fromInt(-1000)); } else { this.setDefaultSpatialReference(SpatialReference.create(102113)); this.setFullExtent(new Envelope(-22041257.773878, -32673939.6727517, 22041257.773878, 20851350.0432886)); this.setTileInfo(new TileInfo(origin, scales, resolutions, scales.length, dpi, tileWidth, tileHeight)); super.initLayer(); } } }

 

posted on 2016-04-28 17:34  gis-luq  阅读(3171)  评论(1编辑  收藏  举报