《ArcGIS Runtime SDK for Android開發筆記》——(13)、圖層擴展方式加載Google地圖

一、前言

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

經過圖層擴展類的方式加載Google地圖的是咱們一般獲取Google地圖的一種方式,根據這種方式咱們能夠經過拼接地圖瓦片Url字符串獲取瓦片數據,關於Google瓦片算法的解析網上有不少,如下僅列出博客地址,及具體實現類。java

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

轉載請註明出處:http://www.cnblogs.com/gis-luq/p/5443498.html 算法

二、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(); } } }
相關文章
相關標籤/搜索