New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Multiple MapView's apparently not supported? #194

Open
mar-v-in opened this Issue Oct 2, 2016 · 13 comments

Comments

Projects
None yet
5 participants
@mar-v-in

mar-v-in commented Oct 2, 2016

I see various issues when having multiple MapView's on Android at the same time:

  1. Sometimes, the text is not rendered correctly, there is only a black box where text is supposed to be
  2. Sometimes, parts of the map are not rendered (lines and/or areas).
  3. Sometimes, wrong symbols are put in place
  4. Sometimes, it just crashes.

Is it intended to support multiple map views at the same time?

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Oct 2, 2016

Collaborator

Could be due to shared static data among the map views.

If you want to provide a pull request example for Samples, in order to have it live and check it.

Collaborator

devemux86 commented Oct 2, 2016

Could be due to shared static data among the map views.

If you want to provide a pull request example for Samples, in order to have it live and check it.

mar-v-in added a commit to mar-v-in/vtm that referenced this issue Oct 2, 2016

Multi Map Sample
As proposed in mapsforge#194
@mar-v-in

This comment has been minimized.

Show comment
Hide comment
@mar-v-in

mar-v-in Oct 2, 2016

Set of screenshots done using the new sample just provided via PR: http://imgur.com/a/2b4TW

mar-v-in commented Oct 2, 2016

Set of screenshots done using the new sample just provided via PR: http://imgur.com/a/2b4TW

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Oct 2, 2016

Collaborator

I improved slightly the multi map example with separate preferences.
Note: it keeps crashing on emulator, working with artifacts on device.

Collaborator

devemux86 commented Oct 2, 2016

I improved slightly the multi map example with separate preferences.
Note: it keeps crashing on emulator, working with artifacts on device.

@andreynovikov

This comment has been minimized.

Show comment
Hide comment
@andreynovikov

andreynovikov Nov 14, 2016

MapView on Android uses GLSurfaceView. GLSurfaceViews can not overlap:
https://groups.google.com/forum/#!topic/android-developers/COffLpanlz0

andreynovikov commented Nov 14, 2016

MapView on Android uses GLSurfaceView. GLSurfaceViews can not overlap:
https://groups.google.com/forum/#!topic/android-developers/COffLpanlz0

@mathieudebrito

This comment has been minimized.

Show comment
Hide comment
@mathieudebrito

mathieudebrito Nov 14, 2016

Hi Andrey, you can use mapview.setZOrderOnTop(true) on the map on the top
to make it work. You can also use mapview.setZOrderMediaOverlay(true);.
I have a working sample.

mathieudebrito commented Nov 14, 2016

Hi Andrey, you can use mapview.setZOrderOnTop(true) on the map on the top
to make it work. You can also use mapview.setZOrderMediaOverlay(true);.
I have a working sample.

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Nov 14, 2016

Collaborator

@andreynovikov thanks for the info.
So they mention not overlapping, what about having them side by side?

Collaborator

devemux86 commented Nov 14, 2016

@andreynovikov thanks for the info.
So they mention not overlapping, what about having them side by side?

@mathieudebrito

This comment has been minimized.

Show comment
Hide comment
@mathieudebrito

mathieudebrito Jan 26, 2017

Hi guys,

I made a working sample of fragments stack showing different mapviews (as previously said, using mapview.setZOrderMediaOverlay(true);).
It works perfectly until you pop a fragment: coming back to the mapview of the previous fragment, it all works fine except labels.

Any ideas ? Where can I find the possible shared data in order to debug ?

device-2017-01-26-150944

mathieudebrito commented Jan 26, 2017

Hi guys,

I made a working sample of fragments stack showing different mapviews (as previously said, using mapview.setZOrderMediaOverlay(true);).
It works perfectly until you pop a fragment: coming back to the mapview of the previous fragment, it all works fine except labels.

Any ideas ? Where can I find the possible shared data in order to debug ?

device-2017-01-26-150944

@ocsike

This comment has been minimized.

Show comment
Hide comment
@ocsike

ocsike Apr 17, 2017

Hi,
Possible solution for black label. It's work for me
onResume event add: mLabelLayer.update();
and onPause event add mLabelLayer.clearLabels(); mMap.render();

Where mLabelLayer is a LabelLayer instance and mMap is a Map

ocsike commented Apr 17, 2017

Hi,
Possible solution for black label. It's work for me
onResume event add: mLabelLayer.update();
and onPause event add mLabelLayer.clearLabels(); mMap.render();

Where mLabelLayer is a LabelLayer instance and mMap is a Map

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Apr 17, 2017

Collaborator

@ocsike where do you use those statements, have you managed to work with MultiMapActivity example?

Collaborator

devemux86 commented Apr 17, 2017

@ocsike where do you use those statements, have you managed to work with MultiMapActivity example?

@ocsike

This comment has been minimized.

Show comment
Hide comment
@ocsike

ocsike Apr 19, 2017

Yes, but is not perfect solution. Black labels are show when move or zoom the map, but not continuous and not all situation.
Here is a code:

public class MultiMapActivity extends Activity {
    private MapView mMapView1, mMapView2;
    private MapPreferences mPrefs1, mPrefs2;
	
	private LabelLayer map1LabelLayer;
	private LabelLayer map2LabelLayer;
	private Map map1; 
	private Map map2;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Tile.SIZE = Tile.calculateTileSize(getResources().getDisplayMetrics().scaledDensity);
        setContentView(R.layout.activity_map_multi);

        setTitle(getClass().getSimpleName());

        // 1st map view
        mMapView1 = (MapView) findViewById(R.id.mapView1);
        map1 = mMapView1.map();
        mPrefs1 = new MapPreferences(MultiMapActivity.class.getName() + "1", this);
        VectorTileLayer baseLayer1 = map1.setBaseMap(new OSciMap4TileSource());
		map1LabelLayer = new LabelLayer(map1, baseLayer1);
        map1.layers().add(new BuildingLayer(map1, baseLayer1));
        map1.layers().add(map1LabelLayer);
        map1.setTheme(VtmThemes.DEFAULT);

        // 2nd map view
        mMapView2 = (MapView) findViewById(R.id.mapView2);
        map2 = mMapView2.map();
        mPrefs2 = new MapPreferences(MultiMapActivity.class.getName() + "2", this);
        VectorTileLayer baseLayer2 = map2.setBaseMap(new OSciMap4TileSource());
		map2LabelLayer = new LabelLayer(map2, baseLayer2);
		
        map2.layers().add(new BuildingLayer(map2, baseLayer2));
        map2.layers().add(map2LabelLayer);
        map2.setTheme(VtmThemes.DEFAULT);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mPrefs1.load(mMapView1.map());
        mMapView1.onResume();

        mPrefs2.load(mMapView2.map());
        mMapView2.onResume();
		
		
		map2LabelLayer.update();
		map1LabelLayer.update();
    }

    @Override
    protected void onPause() {
        super.onPause();

        mMapView1.onPause();
        mPrefs1.save(mMapView1.map());

        mMapView2.onPause();
        mPrefs2.save(mMapView2.map());
		
		map2LabelLayer.clearLabels(); 
		map2.render();
		
		map1LabelLayer.clearLabels(); 
		map1.render();
		
    }
}

2017_04_19_08 55 29

ocsike commented Apr 19, 2017

Yes, but is not perfect solution. Black labels are show when move or zoom the map, but not continuous and not all situation.
Here is a code:

public class MultiMapActivity extends Activity {
    private MapView mMapView1, mMapView2;
    private MapPreferences mPrefs1, mPrefs2;
	
	private LabelLayer map1LabelLayer;
	private LabelLayer map2LabelLayer;
	private Map map1; 
	private Map map2;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Tile.SIZE = Tile.calculateTileSize(getResources().getDisplayMetrics().scaledDensity);
        setContentView(R.layout.activity_map_multi);

        setTitle(getClass().getSimpleName());

        // 1st map view
        mMapView1 = (MapView) findViewById(R.id.mapView1);
        map1 = mMapView1.map();
        mPrefs1 = new MapPreferences(MultiMapActivity.class.getName() + "1", this);
        VectorTileLayer baseLayer1 = map1.setBaseMap(new OSciMap4TileSource());
		map1LabelLayer = new LabelLayer(map1, baseLayer1);
        map1.layers().add(new BuildingLayer(map1, baseLayer1));
        map1.layers().add(map1LabelLayer);
        map1.setTheme(VtmThemes.DEFAULT);

        // 2nd map view
        mMapView2 = (MapView) findViewById(R.id.mapView2);
        map2 = mMapView2.map();
        mPrefs2 = new MapPreferences(MultiMapActivity.class.getName() + "2", this);
        VectorTileLayer baseLayer2 = map2.setBaseMap(new OSciMap4TileSource());
		map2LabelLayer = new LabelLayer(map2, baseLayer2);
		
        map2.layers().add(new BuildingLayer(map2, baseLayer2));
        map2.layers().add(map2LabelLayer);
        map2.setTheme(VtmThemes.DEFAULT);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mPrefs1.load(mMapView1.map());
        mMapView1.onResume();

        mPrefs2.load(mMapView2.map());
        mMapView2.onResume();
		
		
		map2LabelLayer.update();
		map1LabelLayer.update();
    }

    @Override
    protected void onPause() {
        super.onPause();

        mMapView1.onPause();
        mPrefs1.save(mMapView1.map());

        mMapView2.onPause();
        mPrefs2.save(mMapView2.map());
		
		map2LabelLayer.clearLabels(); 
		map2.render();
		
		map1LabelLayer.clearLabels(); 
		map1.render();
		
    }
}

2017_04_19_08 55 29

@mathieudebrito

This comment has been minimized.

Show comment
Hide comment
@mathieudebrito

mathieudebrito Apr 28, 2017

I tried your solution @ocsike but for me it's same with or without update()/clear()

Do anyone have any idea of when this issue will be addressed ?
This is really annoying when using the Android Backstack. because even if you have only one mapview, it gets messed up when just resuming the fragment. And when using multiple mapviews, it's just not usable anymore :p

mathieudebrito commented Apr 28, 2017

I tried your solution @ocsike but for me it's same with or without update()/clear()

Do anyone have any idea of when this issue will be addressed ?
This is really annoying when using the Android Backstack. because even if you have only one mapview, it gets messed up when just resuming the fragment. And when using multiple mapviews, it's just not usable anymore :p

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Apr 28, 2017

Collaborator

@mathieudebrito doesn't the fragment example in samples work?

Collaborator

devemux86 commented Apr 28, 2017

@mathieudebrito doesn't the fragment example in samples work?

@mathieudebrito

This comment has been minimized.

Show comment
Hide comment
@mathieudebrito

mathieudebrito Apr 28, 2017

@devemux86 Indeed, it works with a single fragment.
But when we pause and resume multiple times using the fragment backstack, the map gets messed up :p

But it's also very annoying when using a main map as first fragment, and use secondary maps in others fragments. At this time, the map is always messed up.

NOTE: Because the map breaks out using fragment backstack, I'm forced to use another map libraries (osmdroid) for secondary maps

mathieudebrito commented Apr 28, 2017

@devemux86 Indeed, it works with a single fragment.
But when we pause and resume multiple times using the fragment backstack, the map gets messed up :p

But it's also very annoying when using a main map as first fragment, and use secondary maps in others fragments. At this time, the map is always messed up.

NOTE: Because the map breaks out using fragment backstack, I'm forced to use another map libraries (osmdroid) for secondary maps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment