[VTM][Android] VectorLayer update problem

35 views
Skip to first unread message

Jaca

unread,
Mar 18, 2021, 4:43:21 AMMar 18
to Mapsforge & VTM
Hi Emux, ;-)


I have a problem with the VectorLayer. Could You check why a shape on the VectorLayer doesn't display very often after starting VectorLayerActivity?

Use VectorLayerActivity from vtm-android-example and:
1. change number of shapes to one
2. increase size of shape
3. change position to fixed GeoPoint(0.0f, 0.0f)
4. run example several times...

The map needs to be moved to refresh (and display shape) very often.

ps. I'm testing modified VectorLayerActivity from vtm-master which has vectorLayer.update().

Emux

unread,
Mar 18, 2021, 4:47:23 AMMar 18
to mapsfo...@googlegroups.com
> I'm testing modified VectorLayerActivity from vtm-master which has vectorLayer.update().

The sample with the vectorLayer.update() shows one or multiple shapes every time it runs.

--
Emux

Jaca

unread,
Mar 18, 2021, 5:03:17 AMMar 18
to Mapsforge & VTM
...but vectorLayer.update() doesn't work 10/10 (100%) startups. I've the same issue on my app when it starts up.

Emux

unread,
Mar 18, 2021, 5:09:45 AMMar 18
to mapsfo...@googlegroups.com
I can only try the sample and it shows the shapes every time it starts in my tests.

(but needs the update call in the right place)

--
Emux

Jaca

unread,
Mar 18, 2021, 5:59:34 AMMar 18
to Mapsforge & VTM
Take a look.
VectorLayerActivity.mp4

Emux

unread,
Mar 18, 2021, 6:12:09 AMMar 18
to mapsfo...@googlegroups.com
Like already mentioned, I cannot reproduce it.

You can also try the following calls after adding all layers:

map.render();

or

map.clearMap();

--
Emux

Jaca

unread,
Mar 18, 2021, 6:48:10 AMMar 18
to Mapsforge & VTM
Workaround:

Style.Builder sb = Style.builder()
.buffer(0.5)
.fillColor(Color.RED)
.fillAlpha(0.2f);

for (int i = 0; i < 1; i++) {
Style style = sb.buffer(10.0)
.fillColor(Color.RED)
.fillAlpha(0.5f)
.build();

vectorLayer.add(new PointDrawable(0, 0, style));

}
//vectorLayer.update();
mMap.postDelayed(new Runnable() { <<----

@Override
public void run() {
vectorLayer.update();
}
}, 100);

mMap.layers().add(vectorLayer);

Emux

unread,
Mar 18, 2021, 6:50:57 AMMar 18
to mapsfo...@googlegroups.com
It is important to call the vectorLayer.update() at the end (like in the sample)
and then everything should work like with the example.

--
Emux

Jaca

unread,
Mar 18, 2021, 7:10:45 AMMar 18
to Mapsforge & VTM
As You see, I've vectorLayer.update() in Runnable and it started working 100/100. :-)

Jaca

unread,
Mar 18, 2021, 7:14:27 AMMar 18
to Mapsforge & VTM
...and my app too.

Emux

unread,
Mar 18, 2021, 7:15:13 AMMar 18
to mapsfo...@googlegroups.com
It may depend on your implementation or Android or device or ...

There are many factors and applications should use library API accordingly.

Anyway it is nice that you found a solution for your case.

--
Emux

Jaca

unread,
Mar 18, 2021, 7:33:28 AMMar 18
to Mapsforge & VTM
Tested on Galaxy S9+ and Galaxy Note 10. Please note that the issue only occurs when the map is starting. After this the map refreshes properly by vectorLayer.update() (without Runnable).

Thank You for Your work.

Jaca

unread,
Mar 18, 2021, 10:39:07 AMMar 18
to Mapsforge & VTM
Next (better) solution:

mMap.events.bind(new org.oscim.map.Map.UpdateListener() {

    @Override
    public void onMapEvent(Event e, MapPosition mapPosition) {
       if (e == Map.CLEAR_EVENT) {
          vectorLayer.update();
       }
    }
});

ps. Probably the problem is related to map initialization time (map is busy while executing vectorLayer.update()).
Reply all
Reply to author
Forward
0 new messages