Permalink
Browse files

New projection systems: class TileSystem is now abstract and can be e…

…xtended (#1029)

* New projection systems: class TileSystem is now abstract and can be extended

New class:
* `TileSystemWebMercator`: the current implementation of a tile system in a Web Mercator projection

Impacted classes:
* `BookmarkSample`: now uses getters for min/max latitude/longitude
* `BoundBoxTest`: now uses getters for min/max latitude/longitude
* `BoundingBox`: now uses getters for min/max latitude/longitude
* `DomParserWms111`: now uses getters for min/max latitude/longitude
* `GeoPackageMapTileModuleProvider`: now uses getters for min/max latitude/longitude
* `GeoPointTest`: now uses getters for min/max latitude/longitude and other non static `TileSystem` methods
* `IconPlottingOverlay`: now uses getters for min/max latitude/longitude
* `LinearRing`: impacted the `getCenter` method
* `LinearRingTest`: now uses getters for min/max latitude/longitude
* `MapController`: now uses getters for min/max latitude/longitude
* `MapView`: created a `TileSystem` member with getter and setter, and a default `new TileSystemWebMercator()` value
* `MilStdPointPlottingOverlay`: now uses getters for min/max latitude/longitude
* `OpenStreetMapViewTest`: now uses getters for min/max latitude/longitude and other non static `TileSystem` methods
* `Overlay`: now uses getters for min/max latitude/longitude
* `PathProjection`: now uses non static `TileSystem` methods
* `Projection`: added a `TileSystem` in the constructor and as a member; now uses non static `TileSystem` methods
* `ProjectionTest`: impacted the new `TileSystem` parameter in the `Projection` constructor; now uses non static `TileSystem` methods
* `SampleAnimateTo`: now uses non static `TileSystem` methods
* `SampleAssetsOnlyRepetitionModes`: now uses getters for min/max latitude/longitude
* `SampleZoomToBounding`: now uses getters for min/max latitude/longitude and other non static `TileSystem` methods
* `microsoft.mappoint.TileSystem`: now uses non static `TileSystem` methods
* `org.osmdroid.util.TileSystem`: made it abstract, with 4 lat/lon to/from X01/Y01 methods and 4 min/max lat/lon getters; deprecated the min/max lat/lon members; removed the `static` keyword as much as possible in order to make the class extendable; renamed method `getX01FromLongitudeWithoutWrap` as `getX01FromLongitude` (same for `getY01FromLatitude`)
* `TileSystemTest`: now uses non static `TileSystem` methods of a `TileSystemWebMercator` instance

* Bug fix and new helper methods

Impacted classes:
* `BookmarkSample`: used the new `TileSystem.isValidLongitude/Latitude` methods
* `BoundingBox`: created a new default constructor without checks; used the new `TileSystem.isValid/Long/Lat/itude`, `TileSystem.toString/Long/Lat/itudeSpan` and `TileSystem.cleanLongitude` methods
* `MapController`: used the new `TileSystem.clean/Long/Lat/itude` methods; fixed a bug (calling `cleanLongitude` on a latitude); removed the private `cleanLongitude` method as we now use the `TileSystem` corresponding method
* `Projection`: used the new default `BoundingBox` constructor in order to avoid useless check crash
* `SampleZoomToBounding`: fixed a "360 vs. 2*maxlongitude" potential bug
* `SimpleFastPointOverlay`: used the new default `BoundingBox` constructor in order to avoid useless check crash
* `TileSystem`: created methods `cleanLongitude`, `cleanLatitude`, `isValidLongitude` and `isValidLatitude`; added some version comments

* MapView.getTileSystem() is now the TileSystem reference for the other classes

Main impacted class:
* `MapView`: member `mTileSystem` is now `static`

Impacted classes that now use `MapView.getTileSystem()` as `TileSystem` reference:
* `BoundingBox`
* `DomParserWms111`
* `GeoPackageMapTileModuleProvider`
* `LinearRing`
* `Overlay`
* `PathProjection`
* `SampleZoomToBounding`
  • Loading branch information...
monsieurtanuki authored and spyhunter99 committed May 28, 2018
1 parent ae8234c commit 8cae40361945637c8866fd011ae5f301cbbc9b48
Showing with 361 additions and 185 deletions.
  1. +2 −3 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/bookmarks/BookmarkSample.java
  2. +4 −5 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/drawing/IconPlottingOverlay.java
  3. +1 −1 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/events/SampleAnimateTo.java
  4. +6 −6 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/events/SampleZoomToBounding.java
  5. +4 −4 ...etMapViewer/src/main/java/org/osmdroid/samplefragments/milstd2525/MilStdPointPlottingOverlay.java
  6. +2 −2 ...wer/src/main/java/org/osmdroid/samplefragments/tileproviders/SampleAssetsOnlyRepetitionModes.java
  7. +5 −2 osmdroid-android-it/src/main/java/org/osmdroid/views/OpenStreetMapViewTest.java
  8. +7 −4 osmdroid-android/src/main/java/microsoft/mappoint/TileSystem.java
  9. +18 −16 osmdroid-android/src/main/java/org/osmdroid/util/BoundingBox.java
  10. +135 −51 osmdroid-android/src/main/java/org/osmdroid/util/TileSystem.java
  11. +54 −0 osmdroid-android/src/main/java/org/osmdroid/util/TileSystemWebMercator.java
  12. +7 −16 osmdroid-android/src/main/java/org/osmdroid/views/MapController.java
  13. +18 −1 osmdroid-android/src/main/java/org/osmdroid/views/MapView.java
  14. +20 −14 osmdroid-android/src/main/java/org/osmdroid/views/Projection.java
  15. +4 −2 osmdroid-android/src/main/java/org/osmdroid/views/overlay/LinearRing.java
  16. +3 −2 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Overlay.java
  17. +1 −1 ...roid-android/src/main/java/org/osmdroid/views/overlay/simplefastpoint/SimpleFastPointOverlay.java
  18. +4 −3 osmdroid-android/src/main/java/org/osmdroid/views/util/PathProjection.java
  19. +6 −4 osmdroid-android/src/test/java/org/osmdroid/util/BoundBoxTest.java
  20. +6 −4 osmdroid-android/src/test/java/org/osmdroid/util/GeoPointTest.java
  21. +7 −4 osmdroid-android/src/test/java/org/osmdroid/util/ProjectionTest.java
  22. +31 −30 osmdroid-android/src/test/java/org/osmdroid/util/TileSystemTest.java
  23. +4 −2 osmdroid-android/src/test/java/org/osmdroid/views/overlay/LinearRingTest.java
  24. +7 −4 ...roid-geopackage/src/main/java/org/osmdroid/gpkg/tiles/raster/GeoPackageMapTileModuleProvider.java
  25. +5 −4 osmdroid-wms/src/main/java/org/osmdroid/wms/DomParserWms111.java
@@ -9,7 +9,6 @@
import org.osmdroid.events.MapEventsReceiver;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.TileSystem;
import org.osmdroid.views.overlay.MapEventsOverlay;
import org.osmdroid.views.overlay.Marker;
@@ -90,9 +89,9 @@ public void onClick(View v) {
valid = false;
}
if (latD > TileSystem.MaxLatitude || latD < TileSystem.MinLatitude)
if (!mMapView.getTileSystem().isValidLatitude(latD))
valid = false;
if (lonD > TileSystem.MaxLongitude || lonD < TileSystem.MinLongitude)
if (!mMapView.getTileSystem().isValidLongitude(lonD))
valid = false;
if (valid) {
@@ -5,7 +5,6 @@
import android.view.MotionEvent;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.TileSystem;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Overlay;
@@ -54,10 +53,10 @@ public boolean onLongPress(final MotionEvent e, final MapView mapView) {
if (pt.getLongitude() > 180)
pt.setLongitude(pt.getLongitude()-360);
//latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
if (pt.getLatitude() > TileSystem.MaxLatitude)
pt.setLatitude(TileSystem.MaxLatitude);
if (pt.getLatitude() < TileSystem.MinLatitude)
pt.setLatitude(TileSystem.MinLatitude);
if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
pt.setLatitude(mapView.getTileSystem().getMinLatitude());
Marker m = new Marker(mapView);
m.setPosition(pt);
@@ -129,7 +129,7 @@ private void show(final int pIndex) {
final BoundingBox box = state.getBox();
final double lat = box.getCenterLatitude();
final double lon = box.getCenterLongitude();
final double zoom = TileSystem.getBoundingBoxZoom(box,
final double zoom = mMapView.getTileSystem().getBoundingBoxZoom(box,
mMapView.getWidth() - 2 * borderSizeInPixels, mMapView.getHeight() - 2 * borderSizeInPixels);
((MapController)mMapView.getController()).animateTo(new GeoPoint(lat, lon), zoom, 2000L);
Toast.makeText(getActivity(), state.getName(), Toast.LENGTH_SHORT).show();
@@ -10,7 +10,6 @@
import org.osmdroid.R;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.tileprovider.cachemanager.CacheManager;
import org.osmdroid.util.BoundingBox;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.TileSystem;
@@ -26,6 +25,7 @@
public class SampleZoomToBounding extends BaseSampleFragment implements View.OnClickListener {
private static final int border = 10;
private final TileSystem tileSystem = MapView.getTileSystem();
private Polygon polygon;
Button btnCache;
@@ -60,19 +60,19 @@ public void onClick(View v) {
case R.id.btnCache:
boolean ok = false;
while (!ok) {
final double south = getRandomLatitude(TileSystem.MinLatitude);
final double south = getRandomLatitude(mMapView.getTileSystem().getMinLatitude());
final double north = getRandomLatitude(south);
final double west = getRandomLongitude();
double east = getRandomLongitude();
final BoundingBox boundingBox = new BoundingBox(north, east, south, west);
final double zoom = TileSystem.getBoundingBoxZoom(boundingBox, mMapView.getWidth() - 2 * border, mMapView.getHeight() - 2 * border);
final double zoom = mMapView.getTileSystem().getBoundingBoxZoom(boundingBox, mMapView.getWidth() - 2 * border, mMapView.getHeight() - 2 * border);
ok = zoom >= mMapView.getMinZoomLevel() && zoom <= mMapView.getMaxZoomLevel();
if (ok) {
final String text = "with a border of " + border + " the computed zoom is " + zoom + " for box " + boundingBox;
Toast.makeText(getActivity(), text, Toast.LENGTH_LONG).show();
final List<GeoPoint> points = new ArrayList<>();
if (west > east) {
east += 2 * TileSystem.MaxLongitude;
east += 360;
}
addPoints(points, north, west, north, east);
addPoints(points, north, east, south, east);
@@ -133,10 +133,10 @@ private void addPoints(final List<GeoPoint> pPoints,
}
private double getRandomLongitude() {
return Math.random() * (TileSystem.MaxLongitude - TileSystem.MinLongitude) + TileSystem.MinLongitude;
return tileSystem.getRandomLongitude(Math.random());
}
private double getRandomLatitude(final double pMinLatitude) {
return Math.random() * (TileSystem.MaxLatitude - pMinLatitude) + pMinLatitude;
return tileSystem.getRandomLatitude(Math.random(), pMinLatitude);
}
}
@@ -54,10 +54,10 @@ public boolean onLongPress(final MotionEvent e, final MapView mapView) {
if (pt.getLongitude() > 180)
pt.setLongitude(pt.getLongitude() - 360);
//latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
if (pt.getLatitude() > TileSystem.MaxLatitude)
pt.setLatitude(TileSystem.MaxLatitude);
if (pt.getLatitude() < TileSystem.MinLatitude)
pt.setLatitude(TileSystem.MinLatitude);
if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
pt.setLatitude(mapView.getTileSystem().getMinLatitude());
String code = def.getSymbolCode().replace("*", "-");
//TODO if (!def.isMultiPoint())
@@ -56,8 +56,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
mMapView.setScrollableAreaLimitDouble(new BoundingBox(
TileSystem.MaxLatitude, TileSystem.MaxLongitude,
TileSystem.MinLatitude, TileSystem.MinLongitude));
mMapView.getTileSystem().getMaxLatitude(), mMapView.getTileSystem().getMaxLongitude(),
mMapView.getTileSystem().getMinLatitude(), mMapView.getTileSystem().getMinLongitude()));
} else {
mMapView.setScrollableAreaLimitDouble(null);
}
@@ -18,6 +18,7 @@
import org.osmdroid.tileprovider.util.Counters;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.TileSystem;
import org.osmdroid.util.TileSystemWebMercator;
import java.util.Random;
@@ -29,6 +30,8 @@
private static final Random random = new Random();
private static final TileSystem tileSystem = new TileSystemWebMercator();
public OpenStreetMapViewTest() {
super(StarterMapActivity.class);
Counters.reset();
@@ -70,14 +73,14 @@ public void test_toMapPixels_0_0() {
* @since 6.0.0
*/
private double getRandomLongitude() {
return TileSystem.getRandomLongitude(random.nextDouble());
return tileSystem.getRandomLongitude(random.nextDouble());
}
/**
* @since 6.0.0
*/
private double getRandomLatitude() {
return TileSystem.getRandomLatitude(random.nextDouble(), TileSystem.MinLatitude);
return tileSystem.getRandomLatitude(random.nextDouble(), tileSystem.getMinLatitude());
}
/**
@@ -1,6 +1,7 @@
package microsoft.mappoint;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.TileSystemWebMercator;
import android.graphics.Point;
@@ -11,6 +12,8 @@
@Deprecated
public final class TileSystem {
private static final TileSystemWebMercator tileSystem = new TileSystemWebMercator();
@Deprecated
public static final int primaryKeyMaxZoomLevel = org.osmdroid.util.TileSystem.primaryKeyMaxZoomLevel;
@@ -52,23 +55,23 @@ public static double MapScale(final double latitude, final int levelOfDetail,
@Deprecated
public static Point LatLongToPixelXY(double latitude, double longitude,
final int levelOfDetail, final Point reuse) {
return org.osmdroid.util.TileSystem.LatLongToPixelXY(latitude, longitude, levelOfDetail, reuse);
return tileSystem.LatLongToPixelXY(latitude, longitude, levelOfDetail, reuse);
}
@Deprecated
public static GeoPoint PixelXYToLatLong(final int pixelX, final int pixelY,
final int levelOfDetail, final GeoPoint reuse) {
return org.osmdroid.util.TileSystem.PixelXYToLatLong(pixelX, pixelY, levelOfDetail, reuse);
return tileSystem.PixelXYToLatLong(pixelX, pixelY, levelOfDetail, reuse);
}
@Deprecated
public static Point PixelXYToTileXY(final int pixelX, final int pixelY, final Point reuse) {
return org.osmdroid.util.TileSystem.PixelXYToTileXY(pixelX, pixelY, reuse);
return tileSystem.PixelXYToTileXY(pixelX, pixelY, reuse);
}
@Deprecated
public static Point TileXYToPixelXY(final int tileX, final int tileY, final Point reuse) {
return org.osmdroid.util.TileSystem.TileXYToPixelXY(tileX, tileY, reuse);
return tileSystem.TileXYToPixelXY(tileX, tileY, reuse);
}
@Deprecated
@@ -43,6 +43,13 @@ public BoundingBox(final double north, final double east, final double south, fi
set(north, east, south, west);
}
/**
* @since 6.0.2
* In order to avoid longitude and latitude checks that will crash
* in TileSystem configurations with a bounding box that doesn't include [0,0]
*/
public BoundingBox() {}
/**
* @since 6.0.0
*/
@@ -55,14 +62,15 @@ public void set(final double north, final double east, final double south, final
// 30 > 0 OK
// 30 < 0 not ok
if (north > TileSystem.MaxLongitude || north < TileSystem.MinLatitude)
throw new IllegalArgumentException("north must be less than " +TileSystem.MaxLongitude + " value was " + toString());
if (south < TileSystem.MinLatitude || south > TileSystem.MaxLatitude)
throw new IllegalArgumentException("south more than " + TileSystem.MinLatitude + " value was " + toString());
if (west < TileSystem.MinLongitude || west > TileSystem.MaxLongitude)
throw new IllegalArgumentException("west must be more than " + TileSystem.MinLongitude + " value was " + toString());
if (east > TileSystem.MaxLongitude || east < TileSystem.MinLongitude)
throw new IllegalArgumentException("east must be less than " + TileSystem.MaxLongitude + " value was " + toString());
final TileSystem tileSystem = org.osmdroid.views.MapView.getTileSystem();
if (!tileSystem.isValidLatitude(north))
throw new IllegalArgumentException("north must be in " + tileSystem.toStringLatitudeSpan());
if (!tileSystem.isValidLatitude(south))
throw new IllegalArgumentException("south must be in " + tileSystem.toStringLatitudeSpan());
if (!tileSystem.isValidLongitude(west))
throw new IllegalArgumentException("west must be in " + tileSystem.toStringLongitudeSpan());
if (!tileSystem.isValidLongitude(east))
throw new IllegalArgumentException("east must be in " + tileSystem.toStringLongitudeSpan());
}
public BoundingBox clone(){
@@ -135,15 +143,9 @@ public double getCenterLongitude() {
public static double getCenterLongitude(final double pWest, final double pEast) {
double longitude = (pEast + pWest) / 2.0;
if (pEast < pWest) {
longitude += TileSystem.MaxLongitude;
}
while (longitude > TileSystem.MaxLongitude) {
longitude -= 2 * TileSystem.MaxLongitude;
}
while (longitude < TileSystem.MinLongitude) {
longitude += 2 * TileSystem.MaxLongitude;
longitude += 180;
}
return longitude;
return org.osmdroid.views.MapView.getTileSystem().cleanLongitude(longitude);
}
/**
Oops, something went wrong.

0 comments on commit 8cae403

Please sign in to comment.