TileDownloaders and MyLocationOverlay changes

1,180 views
Skip to first unread message

Stefan Tauner

unread,
Jul 7, 2012, 11:09:30 AM7/7/12
to mapsfo...@googlegroups.com
Hello!

I started implementing an App to help verifying OGD (Open Government
Data) before importing it to OSM by playing around with mapsforge 0.3.0.
Due to the already made changes in mapsforge's trunk i decided to
migrate to 0.3.1 early after getting the most fundamental things to
work.

I am now looking for a replacement of the tile downloader classes. Are
you aware of any decent existing libraries (maybe even with tms or wms
support) that i could get to interface with mapsforge (and how)?

The removal of the CircleOverlay is a bit of a mystery to me. Of course
the MyLocationOverlay eases life quite a bit, but OTOH not even the
paints of the fill and stroke or the update interval are customizable
anymore. :/ I can live with that (if i couldnt i would make local
changes and try to get them upstream of course ;) but i would like to
know the reason for that decision and why the CircleOverlay was not just
subclassed by MyLocationOverlay?

Do you have any ideas how i could speed up the emulator when rendering
the .map? Would reducing the area included help or would i have to
reduce the complexity/number of elements per area?

Thanks!
--
Kind regards/Mit freundlichen Grüßen, Stefan Tauner

Stefan Tauner

unread,
Jul 8, 2012, 3:20:07 AM7/8/12
to mapsfo...@googlegroups.com, Stefan Tauner
Rediculous tiny patches to test the reaction of the community :)

Stefan Tauner (2):
MyLocationOverlay: use a lower bound when drawing the cricle
MyLocationOverlay: allow customization of the circle paints

.../android/maps/overlay/MyLocationOverlay.java | 26 +++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)

--
Kind regards, Stefan Tauner

Stefan Tauner

unread,
Jul 8, 2012, 3:20:08 AM7/8/12
to mapsfo...@googlegroups.com, Stefan Tauner
This allows for testing of the overlay in the Android emulator even without a
drawable (the emulator reports an accuracy of 0, so the circle is invisible).

Signed-off-by: Stefan Tauner <stefan...@gmx.at>
---
.../android/maps/overlay/MyLocationOverlay.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java b/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
index 0fa4e93..6fd9080 100644
--- a/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
+++ b/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
@@ -39,6 +39,7 @@ import android.os.Bundle;
public class MyLocationOverlay implements LocationListener, Overlay {
private static final int UPDATE_DISTANCE = 0;
private static final int UPDATE_INTERVAL = 1000;
+ private static final int MIN_CIRCLE_DIA = 5;

/**
* @param location
@@ -167,7 +168,10 @@ public class MyLocationOverlay implements LocationListener, Overlay {
GeoPoint geoPoint = locationToGeoPoint(location);
this.marker.setGeoPoint(geoPoint);
this.circle.setGeoPoint(geoPoint);
- this.circle.setRadius(location.getAccuracy());
+ float diameter = location.getAccuracy();
+ if(diameter < MIN_CIRCLE_DIA)
+ diameter = MIN_CIRCLE_DIA;
+ this.circle.setRadius(diameter);

if (this.centerAtNextFix || this.snapToLocationEnabled) {
this.centerAtNextFix = false;

Stefan Tauner

unread,
Jul 8, 2012, 3:20:09 AM7/8/12
to mapsfo...@googlegroups.com, Stefan Tauner
I did not understand why there is a drawable and a circle possible at the same
time, hence i just delegated the original constructor to the new one with the
paints. Also, the get*Paint* functions should probably be renamed if this gets
merged.

Signed-off-by: Stefan Tauner <stefan...@gmx.at>
---
.../android/maps/overlay/MyLocationOverlay.java | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java b/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
index 6fd9080..b277ce8 100644
--- a/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
+++ b/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java
@@ -85,11 +85,27 @@ public class MyLocationOverlay implements LocationListener, Overlay {
* @param drawable
* a drawable to display at the current location (might be null).
*/
- public MyLocationOverlay(Context context, MapView mapView, Drawable drawable) {
+ public MyLocationOverlay(Context context, MapView mapView, Drawable drawable){
+ this(context, mapView, drawable, getCirclePaintFill(), getCirclePaintStroke());
+ }
+
+ /**
+ * @param context
+ * a reference to the application context.
+ * @param mapView
+ * the {@code MapView} on which the location will be displayed.
+ * @param drawable
+ * a drawable to display at the current location (might be null).
+ @param circleFill
+ * the {@code Paint} used to draw the filling of the circle that represents the current location.
+ @param circleStroke
+ * the {@code Paint} used to draw the stroke of the circle that represents the current location.
+ */
+ public MyLocationOverlay(Context context, MapView mapView, Drawable drawable, Paint circleFill, Paint circleStroke) {
this.mapView = mapView;
this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
this.marker = new Marker(null, drawable);
- this.circle = new Circle(null, 0, getCirclePaintFill(), getCirclePaintStroke());
+ this.circle = new Circle(null, 0, circleFill, circleStroke);
}

/**

Thilo Mühlberg

unread,
Jul 8, 2012, 5:05:16 PM7/8/12
to mapsfo...@googlegroups.com
Hi Stefan,

as you have already found out, tile downloading is no longer supported
in the latest mapsforge map development version. We rather want to focus
on improving the offline map rendering. You might download and display
tiles via an overlay, but there is no template for that.

Displaying circles in an overlay is easy, in fact it is even easier with
the new overlay API (see
https://code.google.com/p/mapsforge/issues/detail?id=286). As this is
work in progress, the wiki documentation has not yet been updated. But
you can take a look at one of our example activities which draws ten
thousand circles via the new overlay API on top of the Berlin map -
please refer to:
https://code.google.com/p/mapsforge/source/browse/trunk/Applications/Android/Samples/src/org/mapsforge/applications/android/samples/OverlayBenchmark.java

The emulator performance just sucks, i don't know how this could be
improved. Using a smaller .map file probably doesn't make a difference.
Try to get a real Android device, even a cheap one will run faster ...

Greetings,
Thilo
signature.asc

Thilo Mühlberg

unread,
Jul 8, 2012, 5:17:37 PM7/8/12
to mapsfo...@googlegroups.com
I cannot say that i like your solution. Using a hard-coded 5 makes no
sense to me. Why 5? Why not 10? Why not make it customizable? Why use a
min-radius at all? The idea of the circle is to display the accuracy. If
the location fix is perfectly accurate, then there is no need for a circle.

You can display any drawable at the center of the circle (the actual
location position) to highlight the current position of the user on the
map. That's actually how it is implemented in the AdvancedMapViewer for
example. Abusing the circle for that purpose is poor design. You can
even pass a drawable to the MyLocationOverlay constructor which will be
displayed at the location coordinates.
(https://code.google.com/p/mapsforge/source/browse/trunk/mapsforge-map/src/main/java/org/mapsforge/android/maps/overlay/MyLocationOverlay.java)

The Android API allows you to set any accuracy you like
(http://developer.android.com/reference/android/location/Location.html#setAccuracy%28float%29),
if you need to test that. Testing on a real device with real GPS data
would be even better.

Regards,
Thilo
signature.asc

Stefan Tauner

unread,
Jul 9, 2012, 1:14:28 PM7/9/12
to mapsfo...@googlegroups.com, thilo.m...@gmail.com
On Sun, 08 Jul 2012 23:05:16 +0200
Thilo Mühlberg <thilo.m...@gmail.com> wrote:

> as you have already found out, tile downloading is no longer supported
> in the latest mapsforge map development version. We rather want to focus
> on improving the offline map rendering. You might download and display
> tiles via an overlay, but there is no template for that.

I totally understand why you did choose to do so and i am not arguing
against it, but for the users of your library it was a very convenient
feature and they (and myself ;) have to replace the functionality,
hence my question.

Since the overlays became more lightweight (i.e. losing the
one thread per overlay architecture and using a single-threaded
OverlayController instead), i guess if one of the overlays needs to
download the tiles at draw time it would impact the overall
responsiveness quite significantly, making it worthwhile to implement a
background job for prefetching... on its own thread again. Do you agree?
Maybe we could make it possible to customize the decision if an
overlay should be scheduled on its own thread or not? From what i have
seen this is probably not too easy, maybe adding a single background
thread would be easier and sufficient...

> Displaying circles in an overlay is easy, in fact it is even easier with
> the new overlay API (see
> https://code.google.com/p/mapsforge/issues/detail?id=286). As this is
> work in progress, the wiki documentation has not yet been updated. But
> you can take a look at one of our example activities which draws ten
> thousand circles via the new overlay API on top of the Berlin map -
> please refer to:
> https://code.google.com/p/mapsforge/source/browse/trunk/Applications/Android/Samples/src/org/mapsforge/applications/android/samples/OverlayBenchmark.java

Oh i am fully aware of how it works and i am using it already
successfully to overlay vienna with 3354 circles :)
The question regarding CircleOverlay was more targeted at the fact that
the current MyLocationOverlay is much less customizable than the
previous solution with CircleOverlay and MyLocationListener. Will you
make MyLocationOverlay more customizable? Would you take patches for
that if not?

>
> The emulator performance just sucks, i don't know how this could be
> improved. Using a smaller .map file probably doesn't make a difference.

That implies that the determining factor of performance is the number
of pixels drawn, is that correct?

> Try to get a real Android device, even a cheap one will run faster ...

That would of course make sense in terms of performance, but it is
quite hard to test different resolutions/screen sizes/android versions
with a single device ;)
and there is none that fits my needs yet :/

Corey Wallis

unread,
Jul 9, 2012, 7:45:45 PM7/9/12
to mapsfo...@googlegroups.com
Hi,

Just wanted to note my thoughts on the issue of tile downloading. I'm
quite happy for Tile downloading to not be a part of the mapsforge
library. My main use for mapsforge is in the Serval Maps[1]
application which needs to be able to render maps completely offline.

The ability to render maps offline, and the binary map file format,
are the two main features which initially drew us to the mapsforge
library. Granted our use case is a little unique, maps sharing data
using a mesh network, but I'm sure there are other users who don't
need tile downloading functionality either.

We will need to develop our own classes for downloading the binary
files, and sharing these across the mesh, which is fine as it gives us
the greatest degree of control.

I guess what I'm saying is that while there are users of mapsforge who
found the tile downloading feature convenient, there are other such as
us who are OK with it being removed from the library.

With thanks.

-Corey


[1] http://developer.servalproject.org/dokuwiki/doku.php?id=content:servalmaps:main_page

andrea antonello

unread,
Jul 10, 2012, 3:04:47 AM7/10/12
to mapsfo...@googlegroups.com
Hi,
I agree with you, and that is the great thing of open source. And I
mean it even if I am one of those for whom the tile download
functionality is mandatory.

Consider also that the tile functionality can give you access to WMS
and TMS servers and allow to cache the tiles for offline use. So while
I also came to mapsforge with the geopaparazzi project mainly because
of vector functionality, I can't live without rasters. Tiles give me
the possibility to load maps related to my domain and that otherwise
would be too heavy for a mobile device (see a couple of examples here:
http://code.google.com/p/geopaparazzi/wiki/Tiles4Geopaparazzi3#Example_tilesets_loaded
).

So currently I am forced to stick with the latest version of mapsforge
that allows tiles downloading and fix bugs when they come along. My
hope is still that at some point a tile plugin will appear and I will
be able to move on to the next version.

Just to add another usecase,
Cheers,
Andrea

Thilo Mühlberg

unread,
Jul 11, 2012, 5:29:57 PM7/11/12
to mapsfo...@googlegroups.com
> Since the overlays became more lightweight (i.e. losing the
> one thread per overlay architecture and using a single-threaded
> OverlayController instead), i guess if one of the overlays needs to
> download the tiles at draw time it would impact the overall
> responsiveness quite significantly, making it worthwhile to implement a
> background job for prefetching... on its own thread again. Do you agree?
> Maybe we could make it possible to customize the decision if an
> overlay should be scheduled on its own thread or not? From what i have
> seen this is probably not too easy, maybe adding a single background
> thread would be easier and sufficient...
The problem with asynchronous overlays is that each of them needs its
own double-buffed bitmap to draw on. The previous overlay architecture
was designed in this way and the huge memory consumption was one of its
major drawbacks.

Although one could think of an architecture where each overlay defines
via a simple constructor flag whether it wants to be drawn in a separate
thread or not, this would make everything much more complicate and
potentially hard to debug. I am pretty sure that we can cover at least
80% of all use cases without that. A custom overlay may use its own
threads to download or pre-fetch some data, but the actual drawing
process of the canvas should be synchronized and single-threaded.

> The question regarding CircleOverlay was more targeted at the fact that
> the current MyLocationOverlay is much less customizable than the
> previous solution with CircleOverlay and MyLocationListener. Will you
> make MyLocationOverlay more customizable? Would you take patches for
> that if not?
The whole new overlay implementation is still work in progress. Of
course you can always hand in patches, but maybe you should first ask
for the requested feature or method. I might decide to just add it if i
like it which can save both of us plenty of time. And if i don't like
it, i will explain you why and together we might find an even better
solution. Lets try to avoid you writing patches which i then refuse. ;-)

>> The emulator performance just sucks, i don't know how this could be
>> improved. Using a smaller .map file probably doesn't make a difference.
>
> That implies that the determining factor of performance is the number
> of pixels drawn, is that correct?
The performance depends on many aspects. The number of drawn pixels is
definitely important, but also the amount of read and decoded vector
data, the complexity of the render-theme, the status of the caches ...

Greetings,
Thilo

signature.asc

Thilo Mühlberg

unread,
Jul 12, 2012, 10:30:42 AM7/12/12
to mapsfo...@googlegroups.com
Hello Stefan,

i have just changed the MyLocationOverlay in revision r2040
(http://code.google.com/p/mapsforge/source/detail?r=2040) and added the
second constructor as you suggested. Thanks for your help.

For the future, please attach patches to your emails instead of inlining
them. This makes it more convenient for me to handle them.

Greetings,
Thilo


On 08/07/12 09:20, Stefan Tauner wrote:
signature.asc

Stefan Tauner

unread,
Jul 13, 2012, 2:10:11 PM7/13/12
to mapsfo...@googlegroups.com, thilo.m...@gmail.com
On Thu, 12 Jul 2012 16:30:42 +0200
Thilo Mühlberg <thilo.m...@gmail.com> wrote:

> i have just changed the MyLocationOverlay in revision r2040
> (http://code.google.com/p/mapsforge/source/detail?r=2040) and added the
> second constructor as you suggested. Thanks for your help.
>
> For the future, please attach patches to your emails instead of inlining
> them. This makes it more convenient for me to handle them.

thanks for integrating my idea!

Sorry about the inline patch, i have added the 'attach' option to my
gitconfig for the mapsforge clone; that should take care of it in the
future. do you prefer me to also open an issue for them (at least if
they get bigger) or does that just create overhead for all of us?

btw after rebasing to r2056 today i noticed that all nodes with
railway=station (afaics) have their symbol rendered way too big (about
50m in diameter).

Thilo Mühlberg

unread,
Jul 13, 2012, 2:40:20 PM7/13/12
to mapsfo...@googlegroups.com
> Sorry about the inline patch, i have added the 'attach' option to my
> gitconfig for the mapsforge clone; that should take care of it in the
> future. do you prefer me to also open an issue for them (at least if
> they get bigger) or does that just create overhead for all of us?
Unless you are providing a very simple code change or example, i think
opening a new issue is better. We can then discuss the pros and cons and
set all attributes like type and priority accordingly. We can also add
links to all closed issues in the changelog wiki article.

> btw after rebasing to r2056 today i noticed that all nodes with
> railway=station (afaics) have their symbol rendered way too big (about
> 50m in diameter).
That was a bug introduced by some major refactoring i did yesterday in
the render-theme module. It is already fixed in revision r2058. 8-)

Cheers,
Thilo


signature.asc

Stefan Tauner

unread,
Jul 16, 2012, 3:29:08 PM7/16/12
to mapsfo...@googlegroups.com, thilo.m...@gmail.com
On Fri, 13 Jul 2012 20:40:20 +0200
Thilo Mühlberg <thilo.m...@gmail.com> wrote:

> > Sorry about the inline patch, i have added the 'attach' option to my
> > gitconfig for the mapsforge clone; that should take care of it in the
> > future. do you prefer me to also open an issue for them (at least if
> > they get bigger) or does that just create overhead for all of us?
> Unless you are providing a very simple code change or example, i think
> opening a new issue is better. We can then discuss the pros and cons and
> set all attributes like type and priority accordingly. We can also add
> links to all closed issues in the changelog wiki article.

will do then...

> > btw after rebasing to r2056 today i noticed that all nodes with
> > railway=station (afaics) have their symbol rendered way too big (about
> > 50m in diameter).
> That was a bug introduced by some major refactoring i did yesterday in
> the render-theme module. It is already fixed in revision r2058. 8-)

right i missed that update. it is indeed ok again (tested with r2078).
if it is not too much of a hassle could you add a mapsforge-commit
mailing list please?
http://code.google.com/p/support/wiki/FAQ#Google_Groups explains a few bits

Thilo Mühlberg

unread,
Jul 16, 2012, 4:14:22 PM7/16/12
to mapsfo...@googlegroups.com
> if it is not too much of a hassle could you add a mapsforge-commit
> mailing list please?
We had that already once in the past, but we removed it again after a
while as nobody was really using it. I rather recommend using the
project feeds, there is a separate one only for source changes, see:
https://code.google.com/feeds/p/mapsforge/svnchanges/basic

Greetings,
Thilo

signature.asc

marko

unread,
Aug 7, 2012, 1:18:03 AM8/7/12
to mapsfo...@googlegroups.com
Hi Thilo, could you post some examples about how to use MyLocationOverlay in mapsforge? Please.
Currently I am developing a project for my school and I need to show the location of the user. I have not been able to implement MyLocationOverlay on a Android project.
Greetings Marco Galicia

Thilo Mühlberg

unread,
Aug 9, 2012, 1:13:57 PM8/9/12
to mapsfo...@googlegroups.com
Hello Marco,

is there a reason why you address me personally? The idea of a public
mailing list is that many people share their knowledge, ask questions
and help each other. My time is too limited to answer each and every
question. Have you searched in the archive of the mailing list?

Regarding your question: take a look at the AdvancedMapViewer
application in our repository
(trunk/Applications/Android/AdvancedMapViewer) to see a working example
of how to use the MyLocationOverlay class in combination with the latest
development version of mapsforge. The wiki article
GettingStartedDevelopers explains you how to check out and build that
manually.

Cheers,
Thilo
signature.asc
Reply all
Reply to author
Forward
0 new messages