1

I'm using ArcGIS for Android, version 10.1. I'm trying to add mapping technology to an existing system, and all Activities are created in-code instead of using XML files. This is something I cannot change.

I've found that when creating MapViews in this way, they will not initialise until they have been displayed on the screen. I've tried to force the view to behave as though it has been displayed on the screen, using code such as:

this.map = new MapView(context);
map.setOnStatusChangedListener(mapStatusListener);

this.baseLayer = new ArcGISTiledMapServiceLayer(basemap);
baseLayer.setOnStatusChangedListener(basemapStatusListener);
map.addLayer(baseLayer);


linearLayout = new LinearLayout(context);
linearLayout.addView(map, new LayoutParams(300, 300));
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
linearLayout.measure(spec, spec);
linearLayout.layout(0, 0, linearLayout.getWidth(), linearLayout.getHeight());

I then have the mapStatusListener which will remove the MapView from linearLayout as soon as it is initialised, freeing up the MapView to be displayed in the interface.

To pre-emp the question "just add it to the interface to make it initialise", one of the ways we are using the maps is to draw it to a bitmap instead of drawing the whole map object. Using MapViews produced tearing in the interface when scrolling, and there are likely to be multiple maps on-screen in our application. I expect that redrawing an image will be far less expensive than redrawing the MapView with all its layers, etc. Therefore, I want to draw the image off-screen and recycle the map itself, only using the image. In this scenario, there is no reason for the MapView itself to ever be drawn on the screen.

I believe almost all of my current problems could be solved if I could initialise the map off-screen, but I'm stuck on how to achieve this.

1

If you are not interacting with the map or have the need to update the map image you can use the ArcGIS Server REST API to fetch the image.

Example returning a JSON object

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/export?bbox=-185.3,-28.8,-59.5,118.1&f=json

The response should look similar to the following:

{"href":"http://sampleserver1b.arcgisonline.com/arcgisoutput/_ags_map86b9b1e88b3f4b02ae1294e7a31f8fd2.png","width":400,"height":400,"extent":{"xmin":-195.85,"ymin":-28.8,"xmax":-48.95,"ymax":118.1,"spatialReference":{"wkid":4269}},"scale":154341676.161175}

Use the image returned as your static map.

  • That's useful to know, and might solve one of my problems. I'll check that out, thank you. – user21230 Aug 26 '13 at 11:52

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.