当前位置:首页 » 《关注互联网》 » 正文

arcgis for android 入门与提高(二)显示二维地图_郝大大的博客

25 人参与  2021年08月30日 16:03  分类 : 《关注互联网》  评论

点击全文阅读


1、上一节讲了 arcgis for android 入门与提高(一)配置环境https://blog.csdn.net/HB_Programmer/article/details/119967868,接下来看看如何显示二维地图。

2、基于Android Studio,我们打开AndroidManifest.xml,添加网络权限和二维控件支持

<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

3、在activity_main.xml新建MapView

<com.esri.arcgisruntime.mapping.view.MapView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mapview"/>

4、导入包

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

5、核心代码: 

ArcGISRuntimeEnvironment.setApiKey("在dashboard创建的一个很长的key");
mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
mMapView.setMap(map);
mMapView.setViewpoint(new Viewpoint(34.056295, -117.195800, 10000));
@Override
protected void onPause() {
  mMapView.pause();
  super.onPause();
}

@Override
protected void onResume() {
  super.onResume();
  mMapView.resume();
}

@Override
protected void onDestroy() {
  mMapView.dispose();
  super.onDestroy();
}

6、完整代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidgistest">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidGISTest">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.esri.arcgisruntime.mapping.view.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/mapview"/>

</LinearLayout>
package com.example.androidgistest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

public class MainActivity extends AppCompatActivity {

    MapView mMapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArcGISRuntimeEnvironment.setApiKey("");
        mMapView = findViewById(R.id.mapview);
        mMapView.setAttributionTextVisible(false);//去logo

        ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
        mMapView.setMap(map);
        mMapView.setViewpoint(new Viewpoint(34.056295, -117.195800, 10000));

    }

    @Override
    protected void onPause() {
        mMapView.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        mMapView.dispose();
        super.onDestroy();
    }
}

7、效果

8、下一节讲解 arcgis for android 入门与提高(三)显示三维场景https://blog.csdn.net/HB_Programmer/article/details/119985939

欢迎订阅专栏!


点击全文阅读


本文链接:http://zhangshiyu.com/post/26614.html

入门  提高  代码  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1