本文介绍了如何使用 ArcGIS android SDK 向 MapView 添加标记或图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 graphicsLayer 向我的地图添加一些标记或图形,但我不能显示它们.

I'm trying to add some markers or graphic to my Map using graphicsLayer,but I can't show them.

这是我使用 ArcMap 从 .shp 文件转换而来的 .geodatabase 文件:http://1drv.ms/1OwrRm0

This is my .geodatabase file converted from .shp file using ArcMap:http://1drv.ms/1OwrRm0

谁能帮帮我!QQ

提前致谢.

这是我的代码:

package com.example.root.map;
import android.net.Uri;
import android.os.Bundle;
import com.esri.android.map.MapView;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;


import android.app.Activity;
import com.esri.android.map.*;
import com.esri.android.map.FeatureLayer;
import com.esri.android.map.GraphicsLayer;
import com.esri.core.geodatabase.Geodatabase;
import com.esri.core.geodatabase.GeodatabaseFeature;
import com.esri.core.geodatabase.GeodatabaseFeatureTable;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.map.Graphic;
import com.esri.core.renderer.SimpleRenderer;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.table.TableException;
import com.google.android.gms.appindexing.Action;
import android.graphics.Color;
import android.util.Log;


public class MainActivity extends Activity {
static final String TAG = "GGININDER";
MapView mMapView;
Geodatabase geodatabase;
GeodatabaseFeatureTable geodatabaseFeatureTable4, geodatabaseFeatureTable1, geodatabaseFeatureTable2, geodatabaseFeatureTable3;
FeatureLayer  featureLayer1, featureLayer2, featureLayer3, featureLayer4;

GraphicsLayer graphicsLayer;
Graphic pointGraphic;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Open the geodatabase file
    Geodatabase geodatabase, geodatabase1, geodatabase2, geodatabase3,geodatabase4;

    try {
        mMapView = (MapView) findViewById(R.id.map);
        geodatabase1 = new Geodatabase("/sdcard/Download/1.geodatabase");
        geodatabase2 = new Geodatabase("/sdcard/Download/2.geodatabase");
        geodatabase3 = new Geodatabase("/sdcard/Download/3.geodatabase");
        geodatabase4 = new Geodatabase("/sdcard/Download/4.geodatabase");


        //get the geodatabase feature table
        geodatabaseFeatureTable1 = geodatabase1.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable2 = geodatabase2.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable3 = geodatabase3.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable4 = geodatabase4.getGeodatabaseFeatureTableByLayerId(0);
        //create a feature layer



        featureLayer1 = new FeatureLayer(geodatabaseFeatureTable1);
        featureLayer2 = new FeatureLayer(geodatabaseFeatureTable2);
        featureLayer3 = new FeatureLayer(geodatabaseFeatureTable3);
        featureLayer4 = new FeatureLayer(geodatabaseFeatureTable4);
        //featureLayer3 = new FeatureLayer(null);



        mMapView.addLayer(featureLayer1);
        mMapView.addLayer(featureLayer2);
        mMapView.addLayer(featureLayer3);
        mMapView.addLayer(featureLayer4);


        SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CROSS);
        graphicsLayer = new GraphicsLayer();
        Point point = new Point(5,5);
        pointGraphic = new Graphic(point, simpleMarker);
        graphicsLayer.addGraphic(pointGraphic);
        mMapView.addLayer(graphicsLayer);


    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
}

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

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

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

@Override
public void onStart() {
    super.onStart();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Main Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.example.root.map/http/host/path")
    );
}

@Override
public void onStop() {
    super.onStop();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Main Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.example.root.map/http/host/path")
    );

}
}

推荐答案

只需更改坐标:

Point point = new Point(121.5, 24);

您的地理数据库要素都在台湾,但 (5, 5) 不在.当我将您的代码与 (121.5, 24) 一起使用时,我在地图上看到了一个红十字图形.

Your geodatabase features are all in Taiwan, but (5, 5) is not. When I use your code with (121.5, 24), I see a red cross graphic on the map.

这篇关于如何使用 ArcGIS android SDK 向 MapView 添加标记或图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:46