Skip to content

Multi-map improvements - #1582

Merged
devemux86 merged 6 commits into
mapsforge:masterfrom
Sublimis:layers01
Nov 27, 2024
Merged

devemux86 merged 6 commits into
mapsforge:masterfrom
Sublimis:layers01

Conversation

@Sublimis

@Sublimis Sublimis commented Nov 26, 2024 •

Copy link
Copy Markdown
Contributor

* MultiMapDataStore.DataPolicy.RETURN_AUTOFILL: Return data from all datasets in the sequence that support a tile, up to the one that contains data for the entire tile (usually a world map). In other words, once a dataset fills the entire tile, the remaining datasets are not processed for that tile.

Here we are solving the following multi-map artifacts:

  1. Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

  2. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

  3. Return data from all maps that overlap on a tile

Motivation: Prevent ugly gaps at the edges of the map when the map does not cover the tile completely, and we have a background world map that should easily cover this gap. Additionally, prevent the land areas of the (low-res) world map from "peeking" behind the land areas of a (hi-res) main map, when the main map can provide the entire tile itself.

These problems can be easily seen in the Android application sample MultiMapLowResWorld.

… datasets in the sequence that support a tile, up to the one that contains data for the entire tile (usually a world map). In other words, once a dataset fills the entire tile, the remaining datasets are not processed for that tile.
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Can you show screenshots with the difference?

once a dataset fills the entire tile, the remaining datasets are not processed for that tile

Note that world map supports all tiles BUT does not have all or detailed data.

At least until someone provides a world map with more data:

So the small maps with detailed data are more important in rendering.
World map is only useful at small zoom levels as shown in MultiMapLowResWorld.

@Sublimis

Copy link
Copy Markdown
Contributor Author

Note that world map supports all tiles BUT does not have all or detailed data.

At least until someone provides a world map with more data:

* [Provide a low detail world map #319 (comment)](https://github.com/mapsforge/mapsforge/issues/319#issuecomment-61953086)

* [World map devemux86/cruiser#101](https://github.com/devemux86/cruiser/discussions/101)

So the small maps with detailed data are more important in rendering. World map is only useful at small zoom levels as shown in MultiMapLowResWorld.

Note, when map files are added by priority, world map will be the last to be processed, and only if none of the previous maps provided an entire tile:

multiMapDataStore = new MultiMapDataStore(MultiMapDataStore.DataPolicy.RETURN_AUTOFILL);
MapFile mapFile1 = (MapFile) getMapFile1();
mapFile1.restrictToZoomRange((byte) 8, Byte.MAX_VALUE);
multiMapDataStore.addMapDataStore(mapFile1, true, true);
multiMapDataStore.addMapDataStore(getMapFile2(), false, false);

@Sublimis

Sublimis commented Nov 26, 2024 •

Copy link
Copy Markdown
Contributor Author

Before the change. The gap visible in the first screenshot, the zoom level at which the world map no longer provided tiles.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis I edited your post with the screenshots to put them together for easy reading.
You check it and see the img rule that is useful to avoid filling the posts with large images. 🙂

<img src="..." width="...%"/>

@devemux86

Copy link
Copy Markdown
Collaborator

It is still not clear what is the difference between before vs after.
For example we see a different map with master (not rectangle):

@Sublimis

Sublimis commented Nov 26, 2024 •

Copy link
Copy Markdown
Contributor Author

It is still not clear what is the difference between before vs after. For example we see a different map with master (not rectangle):

Zoom in a bit more (twice) on the edge of the map, until scale shows "5 km". Our map was taken from here, but the exact map shouldn't matter much: https://www.openandromaps.org/en/downloads/europe

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Is is about the rectangle at OAM map edges?
Mapsforge maps do not have it.
Where does it come from? Is it in the map data?

Note: it is easier to test with a small map (with sea) like Azores.

@Sublimis

Copy link
Copy Markdown
Contributor Author

Map source doesn't matter, as long as you find zoom level >10 and an edge with incomplete tile. Ok, we can try Azores or anything else.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Try to also reproduce it with Mapsforge maps.

@Sublimis

Copy link
Copy Markdown
Contributor Author

No problem 🙂 Azores map from mapsforge server:

20241126-azores-before1 20241126-azores-before2

@Sublimis

Sublimis commented Nov 26, 2024 •

Copy link
Copy Markdown
Contributor Author

No problem 🙂 Azores map from mapsforge server:

The second image just shows the zoom center! (You must pan around a bit to find the map edge)

@Sublimis

Copy link
Copy Markdown
Contributor Author

Here you can see nicely how the low resolution world map is peeking out from behind the main high resolution map. It also looks uglier when hill shading is used.

20241126-azores-before3-1

@Sublimis

Copy link
Copy Markdown
Contributor Author

With this PR applied:

20241126-azores-after3

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks, I understand now, I was looking at different things! 🙂

@devemux86

devemux86 commented Nov 26, 2024 •

Copy link
Copy Markdown
Collaborator

@Sublimis

  • Does the order of opened map files matter?
    As we shouldn't expect apps to open multiple map files in a specific order.

  • RETURN_AUTOFILL can be bit confusing as name (especially "auto").
    Is there a better name?

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis What happens with adjacent maps where each map has a part of the data of their shared tile?
Does break only return the data of one map?

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis

Does the order of opened map files matter?
As we shouldn't expect apps to open multiple map files in a specific order.

The order of opened maps matters, if we add the world map first, then it covers everything.

What happens with adjacent maps where each map has a part of the data of their shared tile?
Does break only return the data of one map?

Indeed, this does not seem to work properly.

For example, opening the maps of Austria and Switzerland in this order.
With AUTOFILL their shared tile is filled with only Austria data compared to ALL:

AUTOFILL
AUTOFILL
ALL
ALL

@Sublimis

Copy link
Copy Markdown
Contributor Author
* Does the order of opened map files matter?

Yes, maps should be inserted in order of precedence for this to function as advertised. Or at the very least, the world map (if used) should be inserted last. Anyone using the RETURN_FIRST is already doing this. If a user who consciously chooses to use the RETURN_AUTOFILL flag sees artifacts like the above, they will simply change the order of the inserted maps. (This should be put as a note in the description of the flag, if not already clear enough).

  As we shouldn't expect apps to open multiple map files in a specific order.

This is incorrect. Anyone who uses the RETURN_FIRST flag already pays attention to the order of the maps inserted if there is a chance that more than one map can serve a particular tile, which is often the case. Especially if they are using the world map, which overlaps all the other maps.

* `RETURN_AUTOFILL` can be bit confusing as name (especially "auto").
  Is there a better name?

Since the library decides ("automatically") when a tile is "filled", the name seems appropriate. We don't have a better name, if anyone can think of a better name, please suggest it!

* Can you also add this flag in desktop Samples?

Yes

@Sublimis

Copy link
Copy Markdown
Contributor Author

The order of opened maps matters, if we add the world map first, then it covers everything.

What happens with adjacent maps where each map has a part of the data of their shared tile?
Does break only return the data of one map?

Indeed, this does not seem to work properly.

It is working exactly as advertised. Note, this flag is not a replacement for RETURN_ALL!

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Indeed RETURN_FIRST is not really very useful, as it produces half filled multi maps.
Why open the maps of Austria and Switzerland and see only Austria on their borders?

Also this new flag seems to have a very specific use, like world map + 1 country on top?
As seen above multiple countries will not work properly.

Please let's revert the samples to master code, as ALL is what most users would use.

@Sublimis

Copy link
Copy Markdown
Contributor Author

For your example above to work "correctly" with the AUTOFILL flag (i.e. to return data from both maps), neither map should claim to have data for an entire tile that it doesn't actually have. But that then becomes "just" a question of implementation details, i.e. how to get the exact map boundaries (currently this is a rough rectangle). That's why this flag is currently most useful with a world map.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis We also need to think about the performance of the map.
Heavy calculations with thousands of map data on shared tiles can have negative results.

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Indeed RETURN_FIRST is not really very useful, as it produces half filled multi maps. Why open the maps of Austria and Switzerland and see only Austria on their borders?

It seems you should think this through some more. Do take your time. RETURN_FIRST is useful when the user knows the maps they throw into the MultiMapDataStore are disjoint, i.e. not overlapping anywhere (if not using the world map). If they use the world map, this will also work, as the user will see their country as expected, but when they go to entirely different part of the world they will see the world map.

@Sublimis

Sublimis commented Nov 26, 2024 •

Copy link
Copy Markdown
Contributor Author

Also note that no one is forcing anyone to use the new flag. It has its own benefit that no other flag covers. They all have artifacts in a common useful scenario as shown above.

The new flag is in addition to the current flags and does not change their current behavior in any way.

The sample application can be reverted to RETURN_ALL, no problem. However, there is no performance difference between the two flags for the sample application. The new flag will be slightly faster.

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis We also need to think about the performance of the map. Heavy calculations with thousands of map data on shared tiles can have negative results.

This doesn't really have anything to do with the new flag, does it? It may only be faster than RETURN_ALL, or exactly the same. The new flag can never be slower than RETURN_ALL.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis I meant that users usually open maps of neighboring countries.
Of course there could be other use cases of the map library. 🙂

@Sublimis

Copy link
Copy Markdown
Contributor Author

By the way, we first tried to implement such functionality at the "layer level", i.e. use RETURN_ALL (without limiting the zoom level of the world map), but somehow force the sea layer of the more important map to be drawn on top of the less important (world) map, to prevent coastline artifacts. However, we learned that ALL sea layers are hard-coded as layer zero, so no go. Maybe this is a part of the library that could also be improved in the future, but we will almost certainly not deal with it.

We also first used the name RETURN_SEQUENTIAL for the new flag, but this name doesn't really say much. That's why there are some boolean sequential parameters in the code, in case you were wondering. We should probably rename that.

The RETURN_AUTOFILL flag is perhaps best described as a "fixed" version of RETURN_FIRST; it behaves the same unless the tile is incomplete (partially drawn), in which case it will try to load more data (unlike RETURN_FIRST).

Also, our opinion is that no one should ever look at a map that doesn't have a world background when zoomed out, especially considering that the current world map is so lightweight. But that's just us 🙂

@Sublimis

Sublimis commented Nov 27, 2024 •

Copy link
Copy Markdown
Contributor Author

Let's recap and propose a slightly different, more universal approach.

Here we are solving the following multi-map artifacts:

  1. Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

  2. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

Now we also want to satisfy this useful condition:

  1. Return data from all maps that overlap on a tile

The proposal is to provide the ability to assign priority to the inserted map. By default, this can be 0 for all maps (so that no code changes are required from the user). Then return all data (just like RETURN_ALL would do), but sorted by priority. If a map has priority <0, return its data only if the tile is not yet filled by other maps. We can call this a background map priority.

Such functionality can even be implemented without introducing a new flag. By default it will behave just like the RETURN_ALL is behaving right now.

However, we could also introduce a small auxiliary functionality so that users of the RETURN_ALL + world map can immediately benefit from removing the "peeking coastline" artifact: The library could detect when a map is called "world.map" and automatically assign it a negative priority.

What do you think?

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks for the detailed description.

A universal solution seems better, so opening azores + austria + switzerland + world
would work correctly in all cases:

  • Coastline of Azores
  • Common tiles of Austria and Switzerland

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis It is also important if we manage not to break how the public API works.
As it is already used in many applications.

1. Fix: Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

2. Fix. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

3. (RETURN_ALL) Return data from all maps that overlap on a tile while respecting the two points above: Map priorities via MapDataStore.setPriority()
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Can you change the title and the description of the pull request?

@devemux86

devemux86 commented Nov 27, 2024 •

Copy link
Copy Markdown
Collaborator

@Sublimis It does not work if we don't set priority.
Also desktop samples does not work.

java.lang.IllegalArgumentException: Duplicate map database
    at org.mapsforge.map.datastore.MultiMapDataStore.addMapDataStore(MultiMapDataStore.java:70)
    at org.mapsforge.samples.android.MultiMapLowResWorld.onCreate(MultiMapLowResWorld.java:86)

1. Fix: Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

2. Fix. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

3. (RETURN_ALL) Return data from all maps that overlap on a tile while respecting the two points above: Map priorities via MapDataStore.setPriority(). MapFile named "world.map" is automatically assigned some very negative priority.
@Sublimis

Sublimis commented Nov 27, 2024 •

Copy link
Copy Markdown
Contributor Author

There, that should do it.

image

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis It does not work if we don't set priority. Also desktop samples does not work.

java.lang.IllegalArgumentException: Duplicate map database
    at org.mapsforge.map.datastore.MultiMapDataStore.addMapDataStore(MultiMapDataStore.java:70)
    at org.mapsforge.samples.android.MultiMapLowResWorld.onCreate(MultiMapLowResWorld.java:86)

Fixed that, please try now with the latest code.

@Sublimis Sublimis changed the title New MultiMapDataStore.DataPolicy: RETURN_AUTOFILL Multi-map improvements Nov 27, 2024
if ("world.map".equalsIgnoreCase(mapFile.getName())) {
// Some random (very) negative value no one will use
setPriority(Integer.MIN_VALUE + 374);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis We should not do this inside the library.
This must be done by the apps that know the map content.

Also, the map names are not fixed, they can be changed freely.
For example paws.cz has europe_admin map.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let's put this in the sample apps? They do assume particular map names, so it seems appropriate, especially for the Android sample app that has "world.map" hardcoded right there in plain sight.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis Let's put it only in the sample apps.
Android has it, we can also put it in desktop samples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, only AWT sample app should need such auxiliary functionality, since Android app sets the priority manually.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis We can set it manually on desktop samples as well, just like on Android.
They are just examples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually better like this, without assuming that the world.map file should be present, so the user decides which files to use. Because desktop sample has no startup menu like the Android app, it's just a single app.

1. Fix: Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

2. Fix. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

3. (RETURN_ALL) Return data from all maps that overlap on a tile while respecting the two points above: Map priorities via MapDataStore.setPriority().
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Now it seems to work ok in all cases.
If it is complete, we can merge it?

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Now it seems to work ok in all cases. If it is complete, we can merge it?

Yes, nothing more to add 👍

@Sublimis

Copy link
Copy Markdown
Contributor Author

Wait, maybe to clarify comments a bit.

1. Fix: Low-res map coastline peeks out from behind high-res map (RETURN_ALL issue)

2. Fix. Incomplete tile returned on map edge (RETURN_FIRST issue; RETURN_ALL has this issue only when zoom levels are limited as in the sample app)

3. (RETURN_ALL) Return data from all maps that overlap on a tile while respecting the two points above: Map priorities via MapDataStore.setPriority().
@Sublimis

Copy link
Copy Markdown
Contributor Author

Done.

@devemux86 devemux86 added this to the 0.23.0 milestone Nov 27, 2024
@devemux86
devemux86 merged commit 8844f65 into mapsforge:master Nov 27, 2024
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants