VTM - How draw circle with VTM on map

207 views
Skip to first unread message

Pablo Ernesto Miro Martinez

unread,
Jan 20, 2020, 2:05:17 PM1/20/20
to Mapsforge & VTM
Hello 
I need to draw a circle similar to the radius shown in the GPS, with the particularity that the user determines that radius, showing on the map this circle.

Mapa Paradas Cercanas.png

Attached is an image of what I want to obtain.

Emux

unread,
Jan 20, 2020, 2:16:55 PM1/20/20
to mapsfo...@googlegroups.com
If mean the location accuracy circle, it's already available in the 2 location layers, demonstrated in LocationActivity and LocationTextureActivity samples.

If mean circle overlays can use the CircleDrawable or PointDrawable (with buffer), demonstrated in VectorLayerActivity sample.

--
Emux

Pablo Nicitel

unread,
Jun 8, 2020, 9:10:11 AM6/8/20
to Mapsforge & VTM
Hi,

I would like to draw a circle in VTM (a lot of them), but I can not find any workable example. It is not possible to import org.oscim.layers.vector.geometries.PointDrawable or CircleDrawable as in mentioned examples from your post.
How can I do it? Where can I find an example? 
thank you

Dňa pondelok, 20. januára 2020 20:16:55 UTC+1 Emux napísal(a):

Emux

unread,
Jun 8, 2020, 9:37:29 AM6/8/20
to mapsfo...@googlegroups.com
> It is not possible to import org.oscim.layers.vector.geometries.PointDrawable or CircleDrawable as in mentioned examples from your post.

It is possible as demonstrated in above examples.

Always study the integration guide, to see how to include JTS geometries.

--
Emux

Pablo Nicitel

unread,
Jun 8, 2020, 10:51:56 AM6/8/20
to Mapsforge & VTM
Great, it works, thank you.
Now I need to add to each individual circle a Tap event. How can I do it? I found something like ItemizedLayer here https://github.com/mapsforge/vtm/blob/master/vtm-android-example/src/org/oscim/android/test/MarkerOverlayActivity.java , but it is for Markers. Is it possible to apply it for CircleDrawable? Is there an example? I didnt find it.

thank you

Dňa pondelok, 8. júna 2020 15:37:29 UTC+2 Emux napísal(a):

Emux

unread,
Jun 8, 2020, 10:59:32 AM6/8/20
to mapsfo...@googlegroups.com
See PathOverlayActivity example, it works similarly for every geometry type.

--
Emux

Pablo Nicitel

unread,
Jun 8, 2020, 6:21:48 PM6/8/20
to Mapsforge & VTM
I was able to implement the onGesture event on VectorLayer only. Not directly on the CircleDrawable. I created 1000 circles in 1000 vector layers (it wasnt working correctly when I added it to only one vector layer). Now question is how to identify tapped circle when the onGesture event is on VectorLayer?
I want to select a circle and do something e.g. change color... so I need a reference to the CircleDrawable e.g. index... 

Here is my current code:


for (int i = 0; i < 1000; i++) {
VectorLayer vectorLayer = new VectorLayer(mapView.map()) {
@Override
public boolean onGesture(Gesture g, MotionEvent e) {
if (g instanceof Gesture.Tap) {
if (contains(e.getX(), e.getY())) {
Toast.makeText(getApplicationContext(), "VectorLayer tap\n" + mapView.map().viewport().fromScreenPoint(e.getX(), e.getY()), Toast.LENGTH_SHORT).show();
return true;

}
}
return false;
}
};

GeoPoint point = new GeoPoint(48.5 + i/100.0,18.5);
CircleDrawable hillCircle = new CircleDrawable(point, 0.2, c_style);
vectorLayer.add(hillCircle);
Circle_arr.add(hillCircle);
VecLayers_arr.add(vectorLayer);
mapView.map().layers().add(vectorLayer);
}
Circle_arr.get(1).setStyle(b_style);

thank you

Dňa pondelok, 8. júna 2020 16:59:32 UTC+2 Emux napísal(a):

Emux

unread,
Jun 9, 2020, 3:18:12 AM6/9/20
to mapsfo...@googlegroups.com
Layers participate in gestures, not their contents, like geometries or vector tiles.

Why not write your own implementation of onGesture + contains methods?

There you can customize them according to your own needs,
check geometry which contains the gesture and other things.

--
Emux

Pablo Nicitel

unread,
Jun 9, 2020, 4:10:41 AM6/9/20
to Mapsforge & VTM
Hi Emux, 
can you be more specific or send a link to an example? My idea was to use the code you see in my previous post and in the onGesture part to get circle and change the color using setStyle() method on the CircleDrawable, but I havnt found a way how to get the CircleDrawable from the tapped vectorLayer. Is this correct approach? If yes, can you write me how to get the CircleDrawable  from tapped vector layer (inside the onGesture part)?
Or do you mean I should write my own implementaion of VectorLayer and add there a method to get CircleDrawable  from it?

thx

Dňa utorok, 9. júna 2020 9:18:12 UTC+2 Emux napísal(a):

Emux

unread,
Jun 9, 2020, 4:17:37 AM6/9/20
to mapsfo...@googlegroups.com
It's impossible to have examples for every possible user request.
The basics exist and then developers must proceed with their ideas.

You can override VectorLayer.onGesture and use your own "contains" there,
where you can know in the for loop which drawable succeeds the checks.
(just study the default contains code and customize it)

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