Clearing the map

93 views
Skip to first unread message

Luís Henriques

unread,
May 21, 2018, 7:40:27 AM5/21/18
to mapsforge-dev
Hello everyone.

I'm creating an Android app within which the user can download new maps (*.map files).
After downloading or deleting maps, I wanted to update the map, but map.clearMap() doesn't work.
I can't get rid of the deleted map tiles. They remain on the map even after I delete the files.

I tried feeding it an empty tile source, using clearMap(), deleting all layers and even running onDestroy() on the mapView. Nothing works.

What am I missing?

Thank you very much.
I know this is an Android specific question, but I didn't know where else to post it.

Emux

unread,
May 21, 2018, 7:51:54 AM5/21/18
to mapsfo...@googlegroups.com
What map library Mapsforge or VTM?
Please write library name in topic titles.

If mean Mapsforge, when like add maps using a TileRendererLayer, when don't need them anymore can remove those layers and add new ones.

Can see RenderThemeChanger sample where this work flow is demonstrated.

--
Emux

Luís Henriques

unread,
May 21, 2018, 10:45:06 AM5/21/18
to mapsforge-dev
Sorry. I can't edit the topic title. I don't know why.

Thank you for your quick answer.
Yes, I am using MapsForge through the Graphhopper's example project.


Right now I'm creating a MultiMapFileTileSource instance and adding MapFileTileSource objects to it. Then I simply feed it to the map object.

I can't find any reference to a TileRendererLayer though.

Here is a simplification of my code:

MultiMapFileTileSource tileSource = new MultiMapFileTileSource();

// processing files from all valid maps
for (String currentArea : mapsInDirectory) {

 
...            

 
// loading map tiles for the current area
 
MapFileTileSource mapFileTileSource = new MapFileTileSource();
 mapFileTileSource
.setMapFile(new File(areaFolder, currentArea + ".map").getAbsolutePath());

 tileSource
.add(mapFileTileSource); // adding the current area map to the base map
}


VectorTileLayer l = mapView.map().setBaseMap(tileSource); // setting the base tile source on the map

...





Luís Henriques

unread,
May 21, 2018, 11:17:38 AM5/21/18
to mapsforge-dev
I finally found a solution.

It turns out my code wasn't even passing through the clearing function (oops) but the only way to truly clear the map it is to delete all layers beyond the first one (index 0).

Like so:

if (mapView.map().layers().size() > 1) {
 
for ( int i = 1; i < mapView.map().layers().size(); i ++ ) {
  mapView
.map().layers().remove(i);
 
}
}
mapView
.map().updateMap(true);

Which is still not ideal.

mapView.map().clear();

Would be much more useful.

I'll leave the solution here, though, for future reference.

Emux

unread,
May 21, 2018, 11:18:51 AM5/21/18
to mapsfo...@googlegroups.com
Latest GraphHopper sample uses VTM, not Mapsforge anymore.

Both are vector map libraries, main difference: VTM uses OpenGL rendering.

For VTM the same principles apply, can remove the layers not needed anymore and add new ones.

mapView.map().layers().remove(...);

BTW it's always useful to check the GettingStarted sample for the basics.

--
Emux

Emux

unread,
May 21, 2018, 11:21:26 AM5/21/18
to mapsfo...@googlegroups.com
map.clear() is totally different, better read the docs.

Regarding functionality, it's developers responsibility to know which exact layers add on map, to keep track of them and if needed to remove them via the API.

--
Emux

Luís Henriques

unread,
May 21, 2018, 11:42:17 AM5/21/18
to mapsforge-dev
Yeah, makes sense.

These dependencies are still a little confusing to me. Thank you for pointing me in the right direction.

Emux

unread,
May 21, 2018, 11:45:45 AM5/21/18
to mapsfo...@googlegroups.com
GraphHopper Android sample (which usually I maintain too :) ) is somehow complicated, including functionality for both VTM + GraphHopper.

That's why I mentioned the GettingStarted sample, as a basis to see the how a MapView is built and then proceed with more advanced topics.

--
Emux
Reply all
Reply to author
Forward
0 new messages