0

I'm new to ArcGIS runtime SDK and I want to add path(polyline) on the map after giving coordinates where to draw.. But not displaying the path on the map and even not occur any error.

MapView mMapView = null;

// The basemap switching menu items.
MenuItem mStreetsMenuItem = null;
MenuItem mTopoMenuItem = null;
MenuItem mGrayMenuItem = null;
MenuItem mOceansMenuItem = null;

// Create MapOptions for each type of basemap.
final MapOptions mTopoBasemap = new MapOptions(MapType.TOPO);
final MapOptions mStreetsBasemap = new MapOptions(MapType.STREETS);
final MapOptions mGrayBasemap = new MapOptions(MapType.GRAY);
final MapOptions mOceansBasemap = new MapOptions(MapType.OCEANS);

ArcGISTiledMapServiceLayer tms = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

// The current map extent, use to set the extent of the map after switching basemaps.
Polygon mCurrentMapExtent = null;
GraphicsLayer mLocationLayer;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gis2);


    // Retrieve the map and initial extent from XML layout
    mMapView = (MapView) findViewById(R.id.map);
    mLocationLayer = new GraphicsLayer();

    mMapView.addLayer(tms);
    // Set the Esri logo to be visible, and enable map to wrap around date line.
    mMapView.setEsriLogoVisible(false);
    mMapView.enableWrapAround(true);

   SimpleLineSymbol lineSymbol = new SimpleLineSymbol(Color.GREEN, 3, SimpleLineSymbol.STYLE.DASH);
 Polyline lineGeometry = new Polyline();
 lineGeometry.startPath(-302557, 7570663);
 lineGeometry.lineTo(-302959, 7570868);
 lineGeometry.lineTo(-303042, 7571220);
 lineGeometry.lineTo(-302700, 7571803);
 lineGeometry.lineTo(-304043, 7576654);
 lineGeometry.lineTo(-300544, 7585289);
 lineGeometry.lineTo(-294365, 7592435);
 lineGeometry.lineTo(-290122, 7594445);
 lineGeometry.lineTo(-285283, 7595488); 
 Graphic lineGraphic = new Graphic(lineGeometry, lineSymbol);
 mLocationLayer.addGraphic(lineGraphic);

    // Set a listener for map status changes; this will be called when switching basemaps.
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

        private static final long serialVersionUID = 1L;


        @Override
        public void onStatusChanged(Object source, STATUS status) {
            // Set the map extent once the map has been initialized, and the basemap is added
            // or changed; this will be indicated by the layer initialization of the basemap layer. As there is only
            // a single layer, there is no need to check the source object.
            if ((source == mMapView) && (status == STATUS.INITIALIZED)) {
                boolean mIsMapLoaded = true;
            }
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items from the Menu XML to the action bar, if present.
    getMenuInflater().inflate(R.menu.menu_gis2, 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);
    }
}


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


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

Two issues with your code:

  1. You don't add the GraphicsLayer to the MapView
  2. The Polyline you are adding to the GraphicsLayer is in the wrong spatial reference (should be 102100 (3857))

Graphic Layers do not support on-the-fly reprojection. When you add a GraphicsLayer to your MapView you must ensure the spatial reference is the same that is defined on the MapView. You need to ensure that the graphics you add to your graphics layer have coordinates matching the spatial reference, otherwise the graphics may not show up on the map. I have adjusted your code slightly below:

    Envelope initExtent = new Envelope(-10868502.895856911, 4470034.144641369, -10837928.084542884, 4492965.25312689);
    mMapView.setExtent(initExtent, 5);

    ArcGISTiledMapServiceLayer tms = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

    mMapView.addLayer(tms);

    mLocationLayer = new GraphicsLayer();
    mMapView.addLayer(mLocationLayer);

    // Set the Esri logo to be visible, and enable map to wrap around date line.
    mMapView.setEsriLogoVisible(false);
    mMapView.enableWrapAround(true);

    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(Color.GREEN, 3, SimpleLineSymbol.STYLE.DASH);
    Polyline lineGeometry = new Polyline();
    lineGeometry.startPath(-10860000, 4475000);
    lineGeometry.lineTo(-10875000, 4475000);
    lineGeometry.lineTo(-10875000, 4488000);
    final Graphic lineGraphic = new Graphic(lineGeometry, lineSymbol);
    mLocationLayer.addGraphic(lineGraphic);
  • Superb... It worked for me. thnk u :-) – Thili Bu Mar 15 '15 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.