Arcgis runtime for Android 100.5 加載天地圖

加載高德地圖

說(shuō)明一下,什么時(shí)候加載高德地圖,什么時(shí)候加載天地圖

使用原生定位或者使用arcgis提供的LocationDisplay的定位時(shí)吨枉,需要加載天地圖,因?yàn)樵ㄎ环祷氐淖鴺?biāo)是wgs84的坐標(biāo)哄芜,而高德地圖是火星坐標(biāo)系(gcj02)是經(jīng)過(guò)偏移的貌亭,定位顯示會(huì)有偏移
使用百度定位或者高德定位,定位返回坐標(biāo)設(shè)置為gcj02時(shí)认臊,直接加載高德地圖圃庭,定位就不會(huì)有偏移


廢話不多說(shuō),上才藝

準(zhǔn)備

先自定義TianDiTuTiledLayerClass

import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
import com.esri.arcgisruntime.arcgisservices.TileInfo;
import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.layers.WebTiledLayer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 天地圖
 */

public class TianDiTuTiledLayerClass {
    //需要自己去申請(qǐng),綁定包名和SHA1,我這個(gè)你們用不了
    private static final String key = "11fc0ecfe024734754f0fb5952aa5c6f";
    private static final List<String> SubDomain = 
                         Arrays.asList(new String[]{"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"});

    private static final int DPI = 96;
    private static final int minZoomLevel = 1;
    private static final int maxZoomLevel = 18;
    private static final int tileWidth = 256;
    private static final int tileHeight = 256;
    private static final SpatialReference SRID_MERCATOR = SpatialReference.create(102100);

    private static final double X_MIN_MERCATOR = -20037508.3427892;
    private static final double Y_MIN_MERCATOR = -20037508.3427892;
    private static final double X_MAX_MERCATOR = 20037508.3427892;
    private static final double Y_MAX_MERCATOR = 20037508.3427892;
    private static final Point ORIGIN_MERCATOR = 
                         new Point(-20037508.3427892, 20037508.3427892, SRID_MERCATOR);
    private static final Envelope ENVELOPE_MERCATOR =
                                   new Envelope(X_MIN_MERCATOR,
                                                Y_MIN_MERCATOR, 
                                                X_MAX_MERCATOR, 
                                                Y_MAX_MERCATOR, 
                                                SRID_MERCATOR);

    private static final SpatialReference SRID_2000 = SpatialReference.create(4490);
    private static final double X_MIN_2000 = -180;
    private static final double Y_MIN_2000 = -90;
    private static final double X_MAX_2000 = 180;
    private static final double Y_MAX_2000 = 90;
    private static final Point ORIGIN_2000 = new Point(-180, 90, SRID_2000);
    private static final Envelope ENVELOPE_2000 = 
                         new Envelope(X_MIN_2000, 
                                               Y_MIN_2000, 
                                               X_MAX_2000, 
                                               Y_MAX_2000, 
                                               SRID_2000);

    private static final double[] SCALES = {
            2.958293554545656E8, 1.479146777272828E8,
            7.39573388636414E7, 3.69786694318207E7,
            1.848933471591035E7, 9244667.357955175,
            4622333.678977588, 2311166.839488794,
            1155583.419744397, 577791.7098721985,
            288895.85493609926, 144447.92746804963,
            72223.96373402482, 36111.98186701241,
            18055.990933506204, 9027.995466753102,
            4513.997733376551, 2256.998866688275,
            1128.4994333441375
    };
    private static final double[] RESOLUTIONS_MERCATOR = {
            78271.51696402048, 39135.75848201024,
            19567.87924100512, 9783.93962050256,
            4891.96981025128, 2445.98490512564,
            1222.99245256282, 611.49622628141,
            305.748113140705, 152.8740565703525,
            76.43702828517625, 38.21851414258813,
            19.109257071294063, 9.554628535647032,
            4.777314267823516, 2.388657133911758,
            1.194328566955879, 0.5971642834779395,
            0.298582141738970};
    private static final double[] RESOLUTIONS_2000 = {
            0.7031249999891485, 0.35156249999999994,
            0.17578124999999997, 0.08789062500000014,
            0.04394531250000007, 0.021972656250000007,
            0.01098632812500002, 0.00549316406250001,
            0.0027465820312500017, 0.0013732910156250009,
            0.000686645507812499, 0.0003433227539062495,
            0.00017166137695312503, 0.00008583068847656251,
            0.000042915344238281406, 0.000021457672119140645,
            0.000010728836059570307, 0.000005364418029785169};

    public static WebTiledLayer CreateTianDiTuTiledLayer(LayerType layerType) {
        String type = "";
        String tilematrixset = "";
        WebTiledLayer webTiledLayer = null;
        String mainUrl;
        TileInfo mainTileInfo;
        Envelope mainEnvelope;
        try {
            switch (layerType) {
                case TIANDITU_VECTOR_MERCATOR:
                    type = "vec";
                    tilematrixset = "w";
                    break;
                case TIANDITU_VECTOR_MERCATOR_LABLE:
                    type = "cva";
                    tilematrixset = "w";
                    break;
                case TIANDITU_VECTOR_2000:
                    type = "vec";
                    tilematrixset = "c";
                    break;
                case TIANDITU_VECTOR_2000_LABLE:
                    type = "cva";
                    tilematrixset = "c";
                    break;
                case TIANDITU_IMAGE_MERCATOR:
                    type = "img";
                    tilematrixset = "w";
                    break;
                case TIANDITU_IMAGE_MERCATOR_LABLE:
                    type = "cia";
                    tilematrixset = "w";
                    break;
                case TIANDITU_IMAGE_2000:
                    type = "img";
                    tilematrixset = "c";
                    break;
                case TIANDITU_IMAGE_2000_LABLE:
                    type = "cia";
                    tilematrixset = "c";
                    break;
                case TIANDITU_TERRAIN_MERCATOR:
                    type = "ter";
                    tilematrixset = "w";
                    break;
                case TIANDITU_TERRAIN_MERCATOR_LABLE:
                    type = "cta";
                    tilematrixset = "w";
                    break;
                case TIANDITU_TERRAIN_2000:
                    type = "ter";
                    tilematrixset = "c";
                    break;
                case TIANDITU_TERRAIN_2000_LABLE:
                    type = "cta";
                    tilematrixset = "c";
                    break;
            }
            mainUrl = "http://t0.tianditu.gov.cn/"
                    + type + "_" + tilematrixset + "/wmts?" +
                    "service=wmts" +
                    "&request=gettile" +
                    "&version=1.0.0" +
                    "&layer=" + type +
                    "&format=tiles" +
                    "&STYLE=default" +
                    "&tilematrixset=" + tilematrixset +
                    "&tilecol={col}" +
                    "&tilerow={row}" +
                    "&tilematrix={level}" +
                    "&tk=" + key;
            List<LevelOfDetail> mainLevelOfDetail = new ArrayList<LevelOfDetail>();
            Point mainOrigin;
            if (tilematrixset.equals("c")) {
                for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
                    LevelOfDetail item = 
                      new LevelOfDetail(i, RESOLUTIONS_2000[i - 1], SCALES[i - 1]);
                    mainLevelOfDetail.add(item);
                }
                mainEnvelope = ENVELOPE_2000;
                mainOrigin = ORIGIN_2000;
            } else {
                for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
                    LevelOfDetail item = 
                      new LevelOfDetail(i, RESOLUTIONS_MERCATOR[i - 1], SCALES[i - 1]);
                    mainLevelOfDetail.add(item);
                }
                mainEnvelope = ENVELOPE_MERCATOR;
                mainOrigin = ORIGIN_MERCATOR;
            }
            mainTileInfo = new TileInfo(
                    DPI,
                    TileInfo.ImageFormat.PNG24,
                    mainLevelOfDetail,
                    mainOrigin,
                    mainOrigin.getSpatialReference(),
                    tileHeight,
                    tileWidth
            );
            webTiledLayer = new WebTiledLayer(
                    mainUrl,
                    SubDomain,
                    mainTileInfo,
                    mainEnvelope);
            webTiledLayer.setName(type);
            webTiledLayer.loadAsync();
        } catch (Exception e) {
            e.getCause();
        }
        return webTiledLayer;
    }

    public enum LayerType {
        /**
         * 天地圖矢量墨卡托投影地圖服務(wù)
         */
        TIANDITU_VECTOR_MERCATOR,
        TIANDITU_VECTOR_MERCATOR_LABLE,
        /**
         * 天地圖矢量2000地圖服務(wù)
         */
        TIANDITU_VECTOR_2000,
        TIANDITU_VECTOR_2000_LABLE,

        /**
         * 天地圖影像墨卡托地圖服務(wù)
         */
        TIANDITU_IMAGE_MERCATOR,
        TIANDITU_IMAGE_MERCATOR_LABLE,

        /**
         * 天地圖影像2000地圖服務(wù)
         */
        TIANDITU_IMAGE_2000,
        TIANDITU_IMAGE_2000_LABLE,
        /**
         * 天地圖地形墨卡托地圖服務(wù)
         */
        TIANDITU_TERRAIN_MERCATOR,
        TIANDITU_TERRAIN_MERCATOR_LABLE,
        /**
         * 天地圖地形2000地圖服務(wù)
         */
        TIANDITU_TERRAIN_2000,
        TIANDITU_TERRAIN_2000_LABLE,
    }
}

地址拼接是看的天地圖官網(wǎng)給的例子剧腻,天地圖API傳送門(mén)

天地圖官方例子

注意

天地圖現(xiàn)在要去官網(wǎng)申請(qǐng)一個(gè)key才能用


申請(qǐng)key

申請(qǐng)后替換上面類(lèi)里的key

使用方法

使用的kotlin代碼拘央,應(yīng)該能看懂吧

        //去除水印
        ArcGISRuntimeEnvironment.setLicense("runtimelite,1000,rud4449636536,none,NKMFA0PL4S0DRJE15166")
        //去除logo
        mapView.isAttributionTextVisible = false
         //默認(rèn)底圖
        val webTiledLayer =
            TianDiTuTiledLayerClass.CreateTianDiTuTiledLayer(
                TianDiTuTiledLayerClass.LayerType.TIANDITU_VECTOR_MERCATOR
            )
        //標(biāo)注圖層
        val webTiledLayerLable =
            TianDiTuTiledLayerClass.CreateTianDiTuTiledLayer(
                TianDiTuTiledLayerClass.LayerType.TIANDITU_VECTOR_MERCATOR_LABLE
            )
        val basemap = Basemap()
        basemap.baseLayers.add(webTiledLayer)
        basemap.baseLayers.add(webTiledLayerLable)
        val arcGISMap = ArcGISMap(basemap)
        mapView.map = arcGISMap

至此就大功告成,需要添加三個(gè)權(quán)限,讀寫(xiě)文件是運(yùn)行時(shí)權(quán)限书在,別忘了

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

我自定義類(lèi)里只寫(xiě)了六種常用的底圖類(lèi)型灰伟,官方提供了
官方提供底圖

官方提供底圖

可自由擴(kuò)展,添加LayerType的枚舉類(lèi)型和

public static WebTiledLayer CreateTianDiTuTiledLayer(LayerType layerType) 

方法中的case就行儒旬,
代碼中的

對(duì)應(yīng)官網(wǎng)的

代碼中的

對(duì)應(yīng)官網(wǎng)的
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末栏账,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子栈源,更是在濱河造成了極大的恐慌挡爵,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,123評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件凉翻,死亡現(xiàn)場(chǎng)離奇詭異了讨,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)制轰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門(mén)前计,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人垃杖,你說(shuō)我怎么就攤上這事男杈。” “怎么了调俘?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,723評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵伶棒,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我彩库,道長(zhǎng)肤无,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,357評(píng)論 1 283
  • 正文 為了忘掉前任骇钦,我火速辦了婚禮宛渐,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘眯搭。我一直安慰自己窥翩,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布鳞仙。 她就那樣靜靜地躺著寇蚊,像睡著了一般。 火紅的嫁衣襯著肌膚如雪棍好。 梳的紋絲不亂的頭發(fā)上仗岸,一...
    開(kāi)封第一講書(shū)人閱讀 49,760評(píng)論 1 289
  • 那天允耿,我揣著相機(jī)與錄音,去河邊找鬼扒怖。 笑死右犹,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的姚垃。 我是一名探鬼主播念链,決...
    沈念sama閱讀 38,904評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼积糯!你這毒婦竟也來(lái)了掂墓?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,672評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤看成,失蹤者是張志新(化名)和其女友劉穎君编,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體川慌,經(jīng)...
    沈念sama閱讀 44,118評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡吃嘿,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了梦重。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片兑燥。...
    茶點(diǎn)故事閱讀 38,599評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖琴拧,靈堂內(nèi)的尸體忽然破棺而出降瞳,到底是詐尸還是另有隱情,我是刑警寧澤蚓胸,帶...
    沈念sama閱讀 34,264評(píng)論 4 328
  • 正文 年R本政府宣布挣饥,位于F島的核電站,受9級(jí)特大地震影響沛膳,放射性物質(zhì)發(fā)生泄漏扔枫。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評(píng)論 3 312
  • 文/蒙蒙 一锹安、第九天 我趴在偏房一處隱蔽的房頂上張望短荐。 院中可真熱鬧,春花似錦八毯、人聲如沸搓侄。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,731評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至芯侥,卻和暖如春泊交,著一層夾襖步出監(jiān)牢的瞬間乳讥,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,956評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工廓俭, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留云石,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,286評(píng)論 2 360
  • 正文 我出身青樓研乒,卻偏偏與公主長(zhǎng)得像汹忠,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子雹熬,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評(píng)論 2 348