Skip to content

Commit

Permalink
Multi-map MapFileTileSource.setPriority (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 authored Feb 26, 2025
1 parent 8fbe711 commit 7a1e0f8
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next version

- Multi-map `MapFileTileSource.setPriority` [#1176](https://github.com/mapsforge/vtm/pull/1176)
- Color filter theme resources [#1175](https://github.com/mapsforge/vtm/pull/1175)
- `ThemeCallback.getBitmap`
- Update JTS, OkHttp dependencies [#1172](https://github.com/mapsforge/vtm/pull/1172) [#1173](https://github.com/mapsforge/vtm/pull/1173)
Expand Down
2 changes: 2 additions & 0 deletions vtm-playground/src/org/oscim/test/MapsforgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void createLayers() {
for (File mapFile : mapFiles) {
MapFileTileSource mapFileTileSource = new MapFileTileSource();
mapFileTileSource.setMapFile(mapFile.getAbsolutePath());
if ("world.map".equalsIgnoreCase(mapFile.getName()))
mapFileTileSource.setPriority(-1);
tileSource.add(mapFileTileSource);
}
//tileSource.setDeduplicate(true);
Expand Down
20 changes: 20 additions & 0 deletions vtm/src/org/oscim/core/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ public BoundingBox(List<GeoPoint> geoPoints) {
this.maxLongitudeE6 = maxLon;
}

/**
* @param latitude the latitude coordinate in degrees.
* @param longitude the longitude coordinate in degrees.
* @return true if this BoundingBox contains the given coordinates, false otherwise.
*/
public boolean contains(double latitude, double longitude) {
return this.getMinLatitude() <= latitude && this.getMaxLatitude() >= latitude
&& this.getMinLongitude() <= longitude && this.getMaxLongitude() >= longitude;
}

/**
* @param latitudeE6 the latitude coordinate in microdegrees (degrees * 10^6).
* @param longitudeE6 the longitude coordinate in microdegrees (degrees * 10^6).
* @return true if this BoundingBox contains the given coordinates, false otherwise.
*/
public boolean contains(int latitudeE6, int longitudeE6) {
return this.minLatitudeE6 <= latitudeE6 && this.maxLatitudeE6 >= latitudeE6
&& this.minLongitudeE6 <= longitudeE6 && this.maxLongitudeE6 >= longitudeE6;
}

/**
* @param geoPoint the point whose coordinates should be checked.
* @return true if this BoundingBox contains the given GeoPoint, false
Expand Down
77 changes: 75 additions & 2 deletions vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ public class MapDatabase implements ITileDataSource {

private boolean deduplicate;

/**
* Priority of this MapDatabase. A higher number means a higher priority. Negative numbers have a special
* meaning, they should only be used for so-called background maps. Data from background maps is only read
* if no other map has provided a (complete) map tile. The most famous example of a background map is a
* low-resolution world map. The default priority is 0.
*/
private int priority = 0;

public MapDatabase(MapFileTileSource tileSource) throws IOException {
mTileSource = tileSource;
try {
Expand Down Expand Up @@ -426,6 +434,31 @@ void setDeduplicate(boolean deduplicate) {
this.deduplicate = deduplicate;
}

/**
* Returns the priority of this MapDatabase. A higher number means a higher priority. Negative numbers
* have a special meaning, they should only be used for so-called background maps. Data from background
* maps is only read if no other map has provided a (complete) map tile. The most famous example of a
* background map is a low-resolution world map.
*
* @return The priority of this MapDatabase. Default is 0.
*/
public int getPriority() {
return priority;
}

/**
* Sets the priority of this MapDatabase. A higher number means a higher priority. Negative numbers have
* a special meaning, they should only be used for so-called background maps. Data from background maps is
* only read if no other map has provided a (complete) map tile. The most famous example of a background
* map is a low-resolution world map. The default priority is 0.
*
* @param priority Priority of this MapDatabase. Negative number means background map priority (see above
* for the description).
*/
public void setPriority(int priority) {
this.priority = priority;
}

private void setTileClipping(QueryParameters queryParameters, SubFileParameter subFileParameter,
long currentRow, long currentCol) {
long numRows = queryParameters.toBlockY - queryParameters.fromBlockY;
Expand Down Expand Up @@ -1239,8 +1272,48 @@ public void restrictToZoomRange(int minZoom, int maxZoom) {
* @return true if tile is part of database.
*/
public boolean supportsTile(Tile tile) {
return tile.getBoundingBox().intersects(mTileSource.getMapInfo().boundingBox)
&& (tile.zoomLevel >= this.zoomLevelMin && tile.zoomLevel <= this.zoomLevelMax);
return supportsArea(tile.getBoundingBox(), tile.zoomLevel);
}

/**
* Returns true if MapDatabase contains a complete tile.
*
* @param tile tile to be rendered.
* @return true if complete tile is part of database.
*/
public boolean supportsFullTile(Tile tile) {
return supportsFullArea(tile.getBoundingBox(), tile.zoomLevel);
}

/**
* Returns true if MapDatabase covers (even partially) certain area in required zoom level.
*
* @param boundingBox area we test
* @param zoomLevel zoom level we test
* @return true if area is part of the database.
*/
public boolean supportsArea(BoundingBox boundingBox, int zoomLevel) {
return boundingBox.intersects(mTileSource.getMapInfo().boundingBox)
&& (zoomLevel >= this.zoomLevelMin && zoomLevel <= this.zoomLevelMax);
}

/**
* Returns true if MapDatabase covers certain area completely in required zoom level.
*
* @param boundingBox area we test
* @param zoomLevel zoom level we test
* @return true if complete area is part of the database.
*/
public boolean supportsFullArea(BoundingBox boundingBox, int zoomLevel) {
final BoundingBox bbox1 = mTileSource.getMapInfo().boundingBox;
final BoundingBox bbox2 = boundingBox;
return bbox1.intersects(bbox2)
&& zoomLevel >= this.zoomLevelMin
&& zoomLevel <= this.zoomLevelMax
&& bbox1.contains(bbox2.maxLatitudeE6, bbox2.maxLongitudeE6)
&& bbox1.contains(bbox2.minLatitudeE6, bbox2.minLongitudeE6)
&& bbox1.contains(bbox2.maxLatitudeE6, bbox2.minLongitudeE6)
&& bbox1.contains(bbox2.minLatitudeE6, bbox2.maxLongitudeE6);
}

/**
Expand Down
33 changes: 33 additions & 0 deletions vtm/src/org/oscim/tiling/source/mapfile/MapFileTileSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public class MapFileTileSource extends TileSource implements IMapFileTileSource
private String preferredLanguage;
private Callback callback;

/**
* Priority of this MapFileTileSource. A higher number means a higher priority. Negative numbers have a special
* meaning, they should only be used for so-called background maps. Data from background maps is only read
* if no other map has provided a (complete) map tile. The most famous example of a background map is a
* low-resolution world map. The default priority is 0.
*/
private int priority = 0;

public MapFileTileSource() {
this(Viewport.MIN_ZOOM_LEVEL, Viewport.MAX_ZOOM_LEVEL);
}
Expand Down Expand Up @@ -106,6 +114,31 @@ public void setPreferredLanguage(String preferredLanguage) {
this.preferredLanguage = preferredLanguage;
}

/**
* Returns the priority of this MapFileTileSource. A higher number means a higher priority. Negative numbers
* have a special meaning, they should only be used for so-called background maps. Data from background
* maps is only read if no other map has provided a (complete) map tile. The most famous example of a
* background map is a low-resolution world map.
*
* @return The priority of this MapFileTileSource. Default is 0.
*/
public int getPriority() {
return priority;
}

/**
* Sets the priority of this MapFileTileSource. A higher number means a higher priority. Negative numbers have
* a special meaning, they should only be used for so-called background maps. Data from background maps is
* only read if no other map has provided a (complete) map tile. The most famous example of a background
* map is a low-resolution world map. The default priority is 0.
*
* @param priority Priority of this MapFileTileSource. Negative number means background map priority (see above
* for the description).
*/
public void setPriority(int priority) {
this.priority = priority;
}

@Override
public OpenResult open() {
if (mapFileInputStream == null && !options.containsKey("file"))
Expand Down
Loading

0 comments on commit 7a1e0f8

Please sign in to comment.