ArcGISDynamicMapServiceLayer ams = new ArcGISDynamicMapServiceLayer(SERVER_URL); mMapView.addLayer(ams);
Do you check in the onstatuschangedlistener or in your method with mapview.isloaded() if if the map is loaded?
http://resources.arcgis.com/en/help/android-sdk/concepts/index.html#/Add_layer_to_map/01190000000n000000/You have to check if the map is actually loaded, before you can do anything with its layers etc..
MapView mMapView; static final String SERVER_URL = "http://localhost:8399/arcgis/rest/services/room/MapServer"; ArcGISDynamicMapServiceLayer ams; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMapView = (MapView) findViewById(R.id.map); status = (TextView) findViewById(R.id.status); mMapView.setMapBackground(0xffffff, 0xffffff, 10, 10); ams = new ArcGISDynamicMapServiceLayer(SERVER_URL); mMapView.addLayer(ams); mMapView.setOnLongPressListener(new OnLongPressListener() { private static final long serialVersionUID = 1L; public void onLongPress(float x, float y) { if(mMapView.isLoaded()){ ArcGISLayerInfo[] layers = ams.getLayers(); //this layer is what I want if(layers[1].isVisible()) layers[1].setVisible(false); } } }); }
... if(mMapView.isLoaded()){ ArcGISLayerInfo[] layers = ams.getLayers(); //this layer is what I want if(layers[1].isVisible()) layers[1].setVisible(false); } } }); } ...
... if(mMapView.isLoaded()){ ArcGISLayerInfo[] layers = ams.getLayers(); //this layer is what I want if(layers[1].isVisible()) layers[1].setVisible(false); } } }); }
if(mMapView.isLoaded()){ Layers[] layers = mMapView.getLayers(); //this layer is what I want if(layers[1].isVisible()) layers[1].setVisible(false); }
You need to get the layers from the mapview not the ams. If a layer (ArcGISDynamic/ArcGISTiled,...) is not directly in a mapview it will not be loaded and you can't work with it. Your code would have to look something like this: if(mMapView.isLoaded()){ Layers[] layers = mMapView.getLayers(); //this layer is what I want if(layers[1].isVisible()) layers[1].setVisible(false); }
Ah ok. Could be tricky.You could try to cast the desired Layer element back to a ArcGISDynamicmapservicelayer. Remove the "old" one from the mapview. Change your visibilitys of the the layer and re-add it to the mapview. I don't know if this works. Maybe also debugging the longpress method. MapView.isLoaded() could be a little funny on what it reports in earlier versions of the SDK.I guess andygup could help you better with this...
Bundle extras = intent.getExtras(); ArrayList<Integer> checkedlyrs =extras.getIntegerArrayList("checkedlayers"); //list of layers to show from layers_activity by TOC index number for (int i = 0; i < dynamicMapServiceLayer.getAllLayers().length; i++) { dynamicMapServiceLayer.getAllLayers().setVisible(false); //set all layers off } for (int i = 0; i < checkedlyrs.size(); i++) { dynamicMapServiceLayer.getAllLayers()[checkedlyrs.get(i)].setVisible(true); //set checked layers visible } dynamicMapServiceLayer.refresh(); return;
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.