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.