安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

SceneView

Runtime100是用了一个GeoView类作为地图的基类直接继承于ViewGroup,然后MapView和SceneView分别作为二维和三维地图的容器继承于GeoView。

其实把SceneView当做MapView,把ArcGISScene当做ArcGISMap就行,于是我们简单尝试下。首先是在XML文件里添加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>
public class SceneViewActivity extends AppCompatActivity {

    private SceneView mSceneView;

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

        mSceneView = (SceneView) findViewById(R.id.sceneview);

        ArcGISScene arcGISScene = new ArcGISScene();
        mSceneView.setScene(arcGISScene);
    }

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

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

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

运行下,看看效果:
安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

可以看出其实SceneView的基本底图就是一个地球,然后我们给它设置个瓦片图层作为底图:


        mSceneView = (SceneView) findViewById(R.id.sceneview);

        ArcGISScene arcGISScene = new ArcGISScene();
        ArcGISTiledLayer arcGISTiledLayer = new ArcGISTiledLayer(
                "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
        Basemap basemap = new Basemap(arcGISTiledLayer);
        arcGISScene.setBasemap(basemap);
        mSceneView.setScene(arcGISScene);

安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

可以看出这其实就是把一个切片图层展示在地球上,可以进行三维操作而已。

展示三维场景(ArcGISScene)

三维通过接近真实世界的角度来可视化数据信息
三维场景的使用类似于MapView和ArcGISMap,二维数据皆可加入三维场景
三维场景不同于二维,其具备高程表面(elevation surface)

无高程表面(elevation surface)

安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

  private SceneView mSceneView;

    private String brest_buildings = " http://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer";

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

        mSceneView = (SceneView) findViewById(R.id.sceneView);

        ArcGISScene scene = new ArcGISScene();
        scene.setBasemap(Basemap.createImagery());
        mSceneView.setScene(scene);

        // add a scene service to the scene for viewing buildings
        ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(brest_buildings);
        scene.getOperationalLayers().add(sceneLayer);

        // 设置三维场景视角镜头(camera)
        Camera camera = new Camera(48.378, -4.494, 200, 345, 65, 0);
        mSceneView.setViewpointCamera(camera);
    }

使用高程表面(ArcGISTiledElevationSource、RasterElevationSource)

ArcGISTiledElevationSource:将在线服务作为高程表面
RasterElevationSource:将本地DEM文件作为高程表面

  private SceneView mSceneView;

    private String elevation_image_service = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";

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

        mSceneView = (SceneView) findViewById(R.id.sceneView);

        ArcGISScene scene = new ArcGISScene();
        scene.setBasemap(Basemap.createImagery());
        mSceneView.setScene(scene);

        ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(elevation_image_service);
        scene.getBaseSurface().getElevationSources().add(elevationSource);

        Camera camera = new Camera(28.4, 83.9, 10010.0, 10.0, 80.0, 0.0);
        mSceneView.setViewpointCamera(camera);
    }

安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

设置三维场景视角镜头(camera)

纬度(Latitude)、经度(longitude)和高程(elevation)

Heading:镜头水平朝向
0度表示指北,从0度逐渐增加,镜头顺时针旋转,360度回到0度指北。

Pitch:镜头垂直朝向
0度表示垂直俯视地球,从0度逐渐增加,镜头沿其水平朝向,从俯视地球朝天空旋转,360度回到0度俯视地球。

  public Camera(double latitude, double longitude, double altitude, double heading, 
  double pitch, double roll)

表面置放模式(LayerSceneProperties.SurfacePlacement)

与二维不同的是,通过GraphicsOverlay添加空间要素时,需要设置表面置放模式,默认为DRAPED。

DRAPED:空间要素紧贴场景表面(surface layer),不考虑空间要素的高程值(Z-values)
ABSOLUTE:空间要素通过其高程值(Z-values)设置距离球体表面(海平面)的高度
RELATIVE:空间要素通过其高程值(Z-values)设置距离场景表面(surface layer)的高度

球体表面和场景表面的差异在于是否使用高程表面,若不使用高程表面ABSOLUTE和RELATIVE在三维场景中展示的位置相同。

安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

 private SceneView mSceneView;

    private String elevation_image_service = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";

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

        mSceneView = (SceneView) findViewById(R.id.sceneView);

        // create a scene and add a basemap to it
        ArcGISScene agsScene = new ArcGISScene();
        agsScene.setBasemap(Basemap.createImagery());
        mSceneView.setScene(agsScene);

        // add base surface for elevation data
        ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(elevation_image_service);
        agsScene.getBaseSurface().getElevationSources().add(elevationSource);

        // add a camera and initial camera position
        Camera camera = new Camera(53.04, -4.04, 1300, 0, 90.0, 0);
        mSceneView.setViewpointCamera(camera);

        // create overlays with elevation modes
        GraphicsOverlay drapedOverlay = new GraphicsOverlay();
        drapedOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.DRAPED);
        mSceneView.getGraphicsOverlays().add(drapedOverlay);

        GraphicsOverlay relativeOverlay = new GraphicsOverlay();
        relativeOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.RELATIVE);
        mSceneView.getGraphicsOverlays().add(relativeOverlay);

        GraphicsOverlay absoluteOverlay = new GraphicsOverlay();
        absoluteOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.ABSOLUTE);
        mSceneView.getGraphicsOverlays().add(absoluteOverlay);

        // create point for graphic location
        Point point = new Point(-4.04, 53.06, 1000, camera.getLocation().getSpatialReference());

        // create a red (0xFFFF0000) circle symbol
        SimpleMarkerSymbol circleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF0000, 10);

        // create a text symbol for each elevation mode
        TextSymbol drapedText = new TextSymbol(10, "DRAPED", 0xFFFFFFFF, TextSymbol.HorizontalAlignment.LEFT,
                TextSymbol.VerticalAlignment.MIDDLE);
        TextSymbol relativeText = new TextSymbol(10, "RELATIVE", 0xFFFFFFFF, TextSymbol.HorizontalAlignment.LEFT,
                TextSymbol.VerticalAlignment.MIDDLE);
        TextSymbol absoluteText = new TextSymbol(10, "ABSOLUTE", 0xFFFFFFFF, TextSymbol.HorizontalAlignment.LEFT,
                TextSymbol.VerticalAlignment.MIDDLE);

        // add the point graphic and text graphic to the corresponding graphics
        // overlay
        drapedOverlay.getGraphics().add(new Graphic(point, circleSymbol));
        drapedOverlay.getGraphics().add(new Graphic(point, drapedText));

        relativeOverlay.getGraphics().add(new Graphic(point, circleSymbol));
        relativeOverlay.getGraphics().add(new Graphic(point, relativeText));

        absoluteOverlay.getGraphics().add(new Graphic(point, circleSymbol));
        absoluteOverlay.getGraphics().add(new Graphic(point, absoluteText));
    }

PortalItem

mSceneView = findViewById(R.id.sceneView);

        // get the portal url and portal item from ArcGIS online
        Portal portal = new Portal("http://www.arcgis.com/", false);
        PortalItem portalItem = new PortalItem(portal, "a13c3c3540144967bc933cb5e498b8e4");

        ArcGISScene scene = new ArcGISScene(portalItem);
        mSceneView.setScene(scene);

安卓智能地图开发:展示三维场景 - ArcGIS Runtime SDK for Android

三维场景中的可视化

三维场景(SceneView 、ArcGISScene)中具备更多的符号化方式来传递信息,包括SimpleMarkerSceneSymbol、ModelMarkerSymbol、DistanceCompositeSceneSymbol以及空间要素拉伸。

上一篇:threejs edior跟写代码结合


下一篇:给倒水小游戏写的暴力破解exe