为什么我不能使用ArcGIS在Android Studio中更改FeatureLayer上的坐标?

时间:2015-09-25 10:29:48

标签: android coordinates arcgis

我想用this方式添加FeatureLayer来映射TWD97坐标, 但它无法显示要素图层。 任何人都可以教我吗?请。

MainActivity.java:

public class MainActivity extends AppCompatActivity {

private MapView mMapView = null;
ArcGISFeatureLayer mFeatureLayer;
GraphicsLayer mGraphicsLayer;
boolean mIsMapLoaded;
String mFeatureServiceURL;
private GeodatabaseFeatureServiceTable featureServiceTable;
public FeatureLayer featureLayer;

//底图切换菜单项。

private MenuItem mStreetsMenuItem = null;
private MenuItem mTopoMenuItem = null;
private MenuItem mGrayMenuItem = null;
private MenuItem mOceansMenuItem = null;

//为每种类型的底图创建MapOptions。

private final MapOptions mTopoBasemap = new MapOptions(MapOptions.MapType.TOPO);
private final MapOptions mStreetsBasemap = new MapOptions(MapOptions.MapType.STREETS);
private final MapOptions mGrayBasemap = new MapOptions(MapOptions.MapType.GRAY);
private final MapOptions mOceansBasemap = new MapOptions(MapOptions.MapType.OCEANS);

//当前地图范围,用于在切换底图后设置地图范围。

private Polygon mCurrentMapExtent = null;


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

    // Retrieve the map and initial extent from XML layout
    mMapView = (MapView) findViewById(R.id.map);
    // Get the feature service URL from values->strings.xml
  //  mFeatureServiceURL = this.getResources().getString(R.string.featureServiceURL);


    featureServiceTable =new GeodatabaseFeatureServiceTable("http://urbanplan.kcg.gov.tw/arcgis/rest/services/KPA/KPAGIS/MapServer",1);
// you can set the spatial reference of the table here
// if not set, the service's spatial reference will be used
    featureServiceTable.setSpatialReference(SpatialReference.create(3824));

// initialize the table asynchronously
    featureServiceTable.initialize(
            new CallbackListener<GeodatabaseFeatureServiceTable.Status>() {

                @Override
                public void onError(Throwable e) {
                    // report/handle error as desired
                    System.out.println(featureServiceTable.getInitializationError());
                }

                @Override
                public void onCallback(GeodatabaseFeatureServiceTable.Status status) {
                    if (status == GeodatabaseFeatureServiceTable.Status.INITIALIZED) {
                        featureLayer = new FeatureLayer(featureServiceTable);
                        mMapView.addLayer(featureLayer);

                    }
                }
            });

// Set the Esri logo to be visible, and enable map to wrap around date line.

    mMapView.setEsriLogoVisible(true);
    mMapView.enableWrapAround(true);

// Set a listener for map status changes; this will be called when switching basemaps.

    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

        private static final long serialVersionUID = 1L;

        public void onStatusChanged(Object source, STATUS status) {

            if ((source == mMapView) && (status == STATUS.INITIALIZED)) {
                SpatialReference mapSR = mMapView.getSpatialReference();
                featureServiceTable = new GeodatabaseFeatureServiceTable("http://urbanplan.kcg.gov.tw/arcgis/rest/services/KPA/KPAGIS/MapServer", 1);
// set the table's spatial reference to be the same as the map's

                featureServiceTable.setSpatialReference(mapSR);
                SpatialReference mercatorWeb = SpatialReference.create(102443);
                Point ll = (Point)GeometryEngine.project(new Point(173367.6392423616,2503301.5586915114), mercatorWeb, mMapView.getSpatialReference());
                Point ur = (Point) GeometryEngine.project(new Point(240513.44330668132, 2575415.8908960395), mercatorWeb, mMapView.getSpatialReference());
                Envelope ext = new Envelope(ll.getX(), ll.getY(), ur.getX(), ur.getY());
                mMapView.setExtent(ext);
                mIsMapLoaded = true;
            }
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    // Get the basemap switching menu items.
    mStreetsMenuItem = menu.getItem(0);
    mTopoMenuItem = menu.getItem(1);
    mGrayMenuItem = menu.getItem(2);
    mOceansMenuItem = menu.getItem(3);

    // Also set the topo basemap menu item to be checked, as this is the default.
    mTopoMenuItem.setChecked(true);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Save the current extent of the map before changing the map.
    mCurrentMapExtent = mMapView.getExtent();


    // Handle menu item selection.
    switch (item.getItemId()) {
        case R.id.World_Street_Map:
            mMapView.setMapOptions(mStreetsBasemap);
            mStreetsMenuItem.setChecked(true);
            return true;
        case R.id.World_Topo:
            mMapView.setMapOptions(mTopoBasemap);
            mTopoMenuItem.setChecked(true);
            return true;
        case R.id.Gray:
            mMapView.setMapOptions(mGrayBasemap);
            mGrayMenuItem.setChecked(true);
            return true;
        case R.id.Ocean_Basemap:
            mMapView.setMapOptions(mOceansBasemap);
            mOceansMenuItem.setChecked(true);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

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

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

0 个答案:

没有答案