Skip to content

Commit

Permalink
Merge branch 'master' into bug/#701
Browse files Browse the repository at this point in the history
  • Loading branch information
spyhunter99 committed Sep 10, 2017
2 parents 3342e2f + 60c9b06 commit 2886321
Show file tree
Hide file tree
Showing 73 changed files with 50,092 additions and 501 deletions.
1 change: 1 addition & 0 deletions OpenStreetMapViewer/build.gradle
Expand Up @@ -35,6 +35,7 @@ dependencies {
compile project(':osmdroid-android')
compile project(':osmdroid-geopackage')
compile project(':osmdroid-mapsforge')
compile project(':osmdroid-wms')

compile 'com.github.angads25:filepicker:1.1.1'

Expand Down
@@ -1,6 +1,7 @@
package org.osmdroid.bugtestfragments;

import android.util.Log;
import android.widget.Toast;

import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.tileprovider.modules.IFilesystemCache;
Expand All @@ -13,6 +14,12 @@
*/

public class Bug445Caching extends BaseSampleFragment {

private static final GeoPoint center = new GeoPoint(52.2742, 0.21130);
private static final int minZoom = 10; // should be high enough so that download is needed (cf. archive)
private static final int maxZoom = 16; // should be 16 or lower due to osm tile server policy (there is no systematic cache of tiles on server for zoom 17+)
private static final int initialZoom = minZoom - 1;

@Override
public String getSampleTitle() {
return "Bug 445 Ensure Caching works";
Expand All @@ -27,8 +34,7 @@ protected void addOverlays() {
writer.purgeCache();

}
mMapView.getController().setCenter(new GeoPoint(52.2742, 0.21130));
mMapView.getController().setZoom(17);
setZoomAndCenter(initialZoom);
}

public void runTestProcedures() throws Exception {
Expand All @@ -38,45 +44,45 @@ public void runTestProcedures() throws Exception {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mMapView.getController().setZoom(1);
Toast.makeText(getActivity(), "downloading from zoom level " + minZoom + " to " + maxZoom, Toast.LENGTH_SHORT).show();
setZoomAndCenter(initialZoom);
}
});

final int minExpected = getMinTileExpected();

writer.purgeCache();
final long count = getDbCount();
if (count != 0)
throw new Exception("purge should remove all tiles, but " + count + " were found");

checkDownload(17, minExpected);
checkDownload(18, minExpected);
checkDownload(19, minExpected);
for (int zoom = minZoom ; zoom <= maxZoom ; zoom ++) {
checkDownload(zoom);
}

getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mMapView.getController().setZoom(1);
Toast.makeText(getActivity(), "testing cache from zoom level " + minZoom + " to " + maxZoom, Toast.LENGTH_SHORT).show();
setZoomAndCenter(initialZoom);
}
});

mMapView.setUseDataConnection(false);
mMapView.getTileProvider().clearTileCache();

checkCache(17);
checkCache(18);
checkCache(19);
for (int zoom = minZoom ; zoom <= maxZoom ; zoom ++) {
checkCache(zoom);
}
}

/**
* @since 6.0
* @since 5.6.6
*/
private void checkDownload(final int pZoomLevel, final int pMinExpected) throws Exception{
private void checkDownload(final int pZoomLevel) throws Exception{
final long countBefore = getDbCount();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mMapView.getController().setZoom(pZoomLevel);
Toast.makeText(getActivity(), "checking download for zoom level " + pZoomLevel, Toast.LENGTH_SHORT).show();
setZoomAndCenter(pZoomLevel);
}
});
try {
Expand All @@ -86,23 +92,24 @@ public void run() {
}
final long countAfter = getDbCount();
final long count = countAfter - countBefore;
if (count < pMinExpected) {
final int minExpected = getMinTileExpected(pZoomLevel);
if (count < minExpected) {
throw new Exception(
"only fetched " + count + " tiles"
+ " for zoom level " + pZoomLevel
+ " but " + pMinExpected + " were expected");
+ " but " + minExpected + " were expected");
}
Log.i(TAG, "checkDownload ok for zoom level " + pZoomLevel);
}

/**
* @since 6.0
* @since 5.6.6
*/
private void checkCache(final int pZoomLevel) throws Exception{
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mMapView.getController().setZoom(pZoomLevel);
setZoomAndCenter(pZoomLevel);
}
});
try {
Expand All @@ -120,30 +127,40 @@ public void run() {
}

/**
* @since 6.0
* @since 5.6.6
*/
private int getMinTileExpected() {
private int getMinTileExpected(final int pZoomLevel) {
final int maxPerZoom = 1 << pZoomLevel;
Log.i(TAG, "max per zoom " + maxPerZoom);
final int width = mMapView.getWidth();
Log.i(TAG, "width " + width);
final int height = mMapView.getHeight();
Log.i(TAG, "height " + height);
final int tileSize = TileSystem.getTileSize();
Log.i(TAG, "tile size " + tileSize);
final int minCols = width / tileSize + (width % tileSize == 0 ? 0 : 1);
final int minCols = Math.min(maxPerZoom, width / tileSize + (width % tileSize == 0 ? 0 : 1));
Log.i(TAG, "min cols " + minCols);
final int minRows = height / tileSize + (height % tileSize == 0 ? 0 : 1);
final int minRows = Math.min(maxPerZoom, height / tileSize + (height % tileSize == 0 ? 0 : 1));
Log.i(TAG, "min rows " + minRows);
final int minExpected = minCols * minRows;
Log.i(TAG, "min expected " + minExpected);
return minExpected;
}

/**
* @since 6.0
* @since 5.6.6
*/
private long getDbCount() {
final long count=writer.getRowCount(mMapView.getTileProvider().getTileSource().name());
Log.i(TAG, "downloaded " + count + " tiles so far");
return count;
}

/**
* @since 5.6.6
*/
private void setZoomAndCenter(final int pZoomLevel) {
mMapView.getController().setZoom(pZoomLevel);
mMapView.getController().setCenter(center);
}
}
Expand Up @@ -155,14 +155,18 @@ private void purgeCache() {

@Override
public void run() {
if (cache==null)
return;
List<SqlTileWriterExt.SourceCount> sources = cache.getSources();
final StringBuilder sb = new StringBuilder("Source: tile count\n");
if (sources.isEmpty())
sb.append("None");
for (int i = 0; i < sources.size(); i++) {
sb.append(sources.get(i).source + ": " + sources.get(i).rowCount + "\n");
}
long expired = cache.getRowCountExpired();
long expired = 0;
if (cache!=null)
expired = cache.getRowCountExpired();
sb.append("Expired tiles: " + expired);

this.runOnUiThread(new Runnable() {
Expand Down
Expand Up @@ -18,6 +18,8 @@
import org.osmdroid.samplefragments.cache.SampleSqliteOnly;
import org.osmdroid.samplefragments.animations.AnimatedMarkerTimer;
import org.osmdroid.samplefragments.data.AsyncTaskDemoFragment;
import org.osmdroid.samplefragments.geopackage.GeopackageFeatureTiles;
import org.osmdroid.samplefragments.geopackage.GeopackageFeatures;
import org.osmdroid.samplefragments.data.Gridlines2;
import org.osmdroid.samplefragments.data.HeatMap;
import org.osmdroid.samplefragments.data.SampleGridlines;
Expand Down Expand Up @@ -51,11 +53,14 @@
import org.osmdroid.samplefragments.location.SampleHeadingCompassUp;
import org.osmdroid.samplefragments.location.SampleMyLocationWithClick;
import org.osmdroid.samplefragments.location.SampleRotation;
import org.osmdroid.samplefragments.tileproviders.GeopackageSample;
import org.osmdroid.samplefragments.geopackage.GeopackageSample;
import org.osmdroid.samplefragments.tileproviders.MapsforgeTileProviderSample;
import org.osmdroid.samplefragments.tileproviders.OfflinePickerSample;
import org.osmdroid.samplefragments.tileproviders.SampleAssetsOnly;
import org.osmdroid.samplefragments.tileproviders.SampleOfflineGemfOnly;
import org.osmdroid.samplefragments.tilesources.NasaWms111Source;
import org.osmdroid.samplefragments.tilesources.NasaWms130Source;
import org.osmdroid.samplefragments.tilesources.NasaWmsSrs;
import org.osmdroid.samplefragments.tilesources.SampleBingHybrid;
import org.osmdroid.samplefragments.tilesources.SampleBingRoad;
import org.osmdroid.samplefragments.tilesources.SampleCopyrightOverlay;
Expand All @@ -67,6 +72,7 @@
import org.osmdroid.samplefragments.tilesources.SampleMapQuest;
import org.osmdroid.samplefragments.tileproviders.SampleOfflineOnly;
import org.osmdroid.samplefragments.tilesources.SampleOpenSeaMap;
import org.osmdroid.samplefragments.tilesources.SampleWMSSource;
import org.osmdroid.samplefragments.tilesources.SampleWhackyColorFilter;
import org.osmdroid.samplefragments.tilesources.SepiaToneTiles;

Expand Down Expand Up @@ -213,7 +219,11 @@ private SampleFactory() {
mSamples.add(SampleOfflineGemfOnly.class);
//58
mSamples.add(DrawPolygon.class);
mSamples.add(SampleWMSSource.class);

//mSamples.add(NasaWms111Source.class);
//mSamples.add(NasaWms130Source.class);
//mSamples.add(NasaWmsSrs.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD )
mSamples.add(AnimatedMarkerHandler.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
Expand All @@ -226,8 +236,11 @@ private SampleFactory() {
if (Build.VERSION.SDK_INT >= 9)
mSamples.add(OfflinePickerSample.class);
//59
if (Build.VERSION.SDK_INT >= 14)
if (Build.VERSION.SDK_INT >= 14) {
mSamples.add(GeopackageSample.class);
mSamples.add(GeopackageFeatures.class);
mSamples.add(GeopackageFeatureTiles.class);
}
}

public void addSample(Class<? extends BaseSampleFragment> clz) {
Expand Down
Expand Up @@ -126,7 +126,7 @@ private void touch_up() {
GeoPoint iGeoPoint = (GeoPoint) projection.fromPixels(pts.get(i).x, pts.get(i).y);
geoPoints.add(iGeoPoint);
}
//TODO run the double pucker algorithm to reduce the points for performance reasons
//TODO run the dougles pucker algorithm to reduce the points for performance reasons
if (geoPoints.size() > 2) {
//only plat a line unless there's at least one item
switch (drawingMode) {
Expand Down
@@ -1,21 +1,33 @@
package org.osmdroid.samplefragments.events;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

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;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Polygon;

import java.util.ArrayList;
import java.util.List;

/**
* Created by alex on 10/4/16.
*/
public class SampleZoomToBounding extends BaseSampleFragment implements View.OnClickListener {

private static final int border = 10;

private final Polygon polygon = new Polygon();
Button btnCache;
@Override
public String getSampleTitle() {
Expand All @@ -32,6 +44,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
btnCache.setOnClickListener(this);
btnCache.setText("Zoom to bounds");

polygon.setStrokeColor(Color.parseColor("#990000FF"));
polygon.setStrokeWidth(2);
polygon.setFillColor(Color.parseColor("#330000FF"));
mMapView.getOverlays().add(polygon);

return root;
}

Expand All @@ -40,11 +57,38 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCache:
BoundingBox box = new BoundingBox(47d, -76d, 46d, -77d);
mMapView.zoomToBoundingBox(box, true);
boolean ok = false;
while (!ok) {
final double south = getRandomLatitude(TileSystem.MinLatitude);
final double north = getRandomLatitude(south);
final double west = getRandomLongitude();
final 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);
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<>();
points.add(new GeoPoint(north, east));
points.add(new GeoPoint(north, west));
points.add(new GeoPoint(south, west));
points.add(new GeoPoint(south, east));
polygon.setPoints(points);
mMapView.invalidate();
mMapView.zoomToBoundingBox(boundingBox, false, border);
}
}
break;

}
}

private double getRandomLongitude() {
return Math.random() * (TileSystem.MaxLongitude - TileSystem.MinLongitude) + TileSystem.MinLongitude;
}

private double getRandomLatitude(final double pMinLatitude) {
return Math.random() * (TileSystem.MaxLatitude - pMinLatitude) + pMinLatitude;
}
}

0 comments on commit 2886321

Please sign in to comment.