许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  移动GIS开发之Esri地图2D和3D切换实现

移动GIS开发之Esri地图2D和3D切换实现

阅读数 16
点赞 0
article_banner


欢迎关注我的微信公众号“人小路远”哦,在这里我将会记录自己日常学习的点滴收获与大家分享,以后也可能会定期记录一下自己在外读博的所见所闻,希望大家喜欢,感谢支持!


解决 MapView和SceneView遮挡问题有两种思路,一种是利用setContentView切换layout,一种是把当前地图最小化为一个像素。本文以前者为例,第一个layout为activity_esri_map.xml,第二为activity_esri_scene.xml。

目录

一、新建地图控件

二、定义变量并加载地图

三、函数封装

四、点击运行查看效果


一、新建地图控件

在地图设计页面上新建三个Button,用于切换地图,两个2d一个3d。button1和button2为2d,button3为3d。

activity_esri_map.xml中如下:

<Button        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_marginEnd="30dp"        android:onClick="button1onclick"        android:id="@+id/button1"        android:text="@string/button1"        />        <Button        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_marginTop="40dp"        android:layout_marginEnd="30dp"        android:onClick="button2onclick"         android:id="@+id/button2"        android:text="@string/button2"        />     <Button        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_marginTop="80dp"        android:layout_marginEnd="30dp"        android:onClick="button3onclick"         android:id="@+id/button3"        android:text="@string/button3"        />     <com.esri.arcgisruntime.mapping.view.MapView        android:id="@+id/mapView"        android:layout_width="match_parent"        android:layout_height="match_parent" >    </com.esri.arcgisruntime.mapping.view.MapView>

activity_esri_scene.xml中把上面的MapView替换为SceneView

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

二、定义变量并加载地图

    private MapView mMapView;    private ArcGISMap mMap;    private Portal mPortal;    private PortalItem mPortalItem_map1;    private PortalItem mPortalItem_map2;    private PortalItem mPortalItem_scene;    private SceneView mSceneView;
@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_esri_map);        //查找并绑定名为mapView的容器        mMapView = findViewById(R.id.mapView);        //添加经纬格网        LatitudeLongitudeGrid grid = new LatitudeLongitudeGrid();        //在MapView上显示格网        mMapView.setGrid(grid);        // get the portal url for ArcGIS Online        mPortal = new Portal(getResources().getString(R.string.portal_url));          // get the pre-defined portal id and portal url        mPortalItem_map1 = new PortalItem(mPortal, getResources().getString(R.string.webmap_houses_with_mortgages_id));        // create a map from a PortalItem        mMap = new ArcGISMap(mPortalItem_map1);        // set the map to be displayed in this view        mMapView.setMap(mMap);      }

地图 链接  portal id

    <!-- arcgis online portal url -->    <string name="portal_url">http://www.arcgis.com/</string>     <!-- scenemap portal item id's --> <string name="buildings_brest">8eaff4f349d6420c99968107629246c4</string> <!-- webmap portal item id's -->    <string name="webmap_houses_with_mortgages_id">23fe7e8317ba4331b6ca72bf2a8eddb6</string>    <string name="webmap_usa_tapestry_segmentation_id">bf024b8d0b4b48f5a486070214e87c5f</string>

三、函数封装

//本处解决MaoView和SceneView遮挡问题使用的是setContentView切换layout的方法    //还有一种思路是把地图最小化为一个像素    public void button1onclick(View v){         setContentView(R.layout.activity_esri_map);        //查找并绑定名为mapView的容器        mMapView = findViewById(R.id.mapView);        //添加经纬格网        LatitudeLongitudeGrid grid = new LatitudeLongitudeGrid();        //在MapView上显示格网        mMapView.setGrid(grid);        // get the portal url for ArcGIS Online        mPortal = new Portal(getResources().getString(R.string.portal_url));        // get the pre-defined portal id and portal url        mPortalItem_map1 = new PortalItem(mPortal, getResources().getString(R.string.webmap_houses_with_mortgages_id));        // create a map from a PortalItem        mMap = new ArcGISMap(mPortalItem_map1);        // set the map to be displayed in this view        mMapView.setMap(mMap);    }     public void button2onclick(View v){         setContentView(R.layout.activity_esri_map);        //查找并绑定名为mapView的容器        mMapView = findViewById(R.id.mapView);        //添加经纬格网        LatitudeLongitudeGrid grid = new LatitudeLongitudeGrid();        //在MapView上显示格网        mMapView.setGrid(grid);        // get the portal url for ArcGIS Online        mPortal = new Portal(getResources().getString(R.string.portal_url));        // get the pre-defined portal id and portal url        mPortalItem_map2 = new PortalItem(mPortal, getResources().getString(R.string.webmap_usa_tapestry_segmentation_id));        // create a map from a PortalItem        mMap = new ArcGISMap(mPortalItem_map2);        // set the map to be displayed in this view        mMapView.setMap(mMap);    }                public void button3onclick(View v){        setContentView(R.layout.acttivity_esri_scene);        //查找并绑定名为sceneView的容器        mSceneView = findViewById(R.id.sceneView);        // get the portal url for ArcGIS Online        mPortal = new Portal(getResources().getString(R.string.portal_url));        // get the pre-defined portal id and portal url        mPortalItem_scene = new PortalItem(mPortal, getResources().getString(R.string.buildings_brest));        // create a map from a PortalItem        ArcGISScene scene = new ArcGISScene(mPortalItem_scene);        // set the map to be displayed in this view        mSceneView.setScene(scene);     }

四、点击运行查看效果


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空