Skip to content

Commit

Permalink
Merge pull request #1818 from garvankeeley/dev
Browse files Browse the repository at this point in the history
Fix #1800: Open-source builds use non-existent mapquest tiles, use MapBox instead
  • Loading branch information
garvankeeley authored Jul 17, 2017
2 parents ad41b8a + 49e822f commit a0321a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ android {

buildConfigField "boolean", "ROBOLECTRIC", "false"
buildConfigField "String", "MOZILLA_API_KEY", "\"\""
buildConfigField "String", "TILE_SERVER_URL", "\"\""

buildConfigField "boolean", "LABEL_MAP_TILES", "false"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.mozstumbler.BuildConfig;
import org.mozilla.mozstumbler.R;
import org.mozilla.mozstumbler.client.ClientPrefs;
import org.mozilla.mozstumbler.client.MainApp;
Expand All @@ -53,7 +52,6 @@
import org.mozilla.osmdroid.tileprovider.MapTile;
import org.mozilla.osmdroid.tileprovider.tilesource.ITileSource;
import org.mozilla.osmdroid.tileprovider.tilesource.OnlineTileSourceBase;
import org.mozilla.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.mozilla.osmdroid.tileprovider.tilesource.XYTileSource;
import org.mozilla.osmdroid.util.GeoPoint;
import org.mozilla.osmdroid.views.MapView;
Expand Down Expand Up @@ -362,7 +360,6 @@ void setHighBandwidthMap(boolean hasNetwork, boolean isHighBandwidth) {
isHighBandwidth = true; // use this as initial default
}

final boolean isMLSTileStore = (BuildConfig.TILE_SERVER_URL != null);
final boolean hasHighResMap = mLowResMapOverlayHighZoom == null && mMap.getTileProvider().getTileSource() == mHighResMapSource;
final boolean hasLowResMap = mLowResMapOverlayHighZoom != null;

Expand All @@ -381,16 +378,17 @@ void setHighBandwidthMap(boolean hasNetwork, boolean isHighBandwidth) {
// Force GC to cleanup underlying LRU caches in overlay
System.gc();

if (!isMLSTileStore) {
mHighResMapSource = TileSourceFactory.MAPQUESTOSM;
} else {
mHighResMapSource = new XYTileSource(AbstractMapOverlay.MLS_MAP_TILE_BASE_NAME,

mHighResMapSource = new XYTileSource(AbstractMapOverlay.MLS_MAP_TILE_BASE_NAME,
null, 1, AbstractMapOverlay.MAX_ZOOM_LEVEL_OF_MAP,
AbstractMapOverlay.TILE_PIXEL_SIZE,
AbstractMapOverlay.FILE_TYPE_SUFFIX_PNG,
new String[]{BuildConfig.TILE_SERVER_URL});
}
System.gc();
AppGlobals.MAPBOX_TILE_URLS) {
public String getTileURLString(MapTile aTile) {
return super.getTileURLString(aTile) + "?access_token=" + AppGlobals.MAPBOX_ACCESS_CODE;
}
};
System.gc();
mMap.setTileSource(mHighResMapSource);
} else if (!isHighBandwidth && !hasLowResMap) {
// Unhooking the highres map means we should nullify it and force GC
Expand All @@ -401,9 +399,9 @@ void setHighBandwidthMap(boolean hasNetwork, boolean isHighBandwidth) {
mMap.setTileSource(new BlankTileSource());

mLowResMapOverlayLowZoom = new LowResMapOverlay(AbstractMapOverlay.TileResType.LOWER_ZOOM,
this.getActivity(), isMLSTileStore, mMap);
this.getActivity(), mMap);
mLowResMapOverlayHighZoom = new LowResMapOverlay(AbstractMapOverlay.TileResType.HIGHER_ZOOM,
this.getActivity(), isMLSTileStore, mMap);
this.getActivity(), mMap);

updateOverlayBaseLayer(mMap.getZoomLevel());
}
Expand Down Expand Up @@ -508,11 +506,7 @@ public void toggleScanning(MenuItem menuItem) {

private void showCopyright() {
TextView copyrightArea = (TextView) mRootView.findViewById(R.id.copyright_area);
if (BuildConfig.TILE_SERVER_URL == null) {
copyrightArea.setText(getActivity().getString(R.string.map_copyright_fdroid));
} else {
copyrightArea.setText(getActivity().getString(R.string.map_copyright_moz));
}
copyrightArea.setText(getActivity().getString(R.string.map_copyright_moz));
}

private void updateCenterButtonIcon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,34 @@
import android.content.Context;
import android.graphics.Color;

import org.mozilla.mozstumbler.BuildConfig;
import org.mozilla.osmdroid.ResourceProxy;
import org.mozilla.mozstumbler.service.AppGlobals;
import org.mozilla.osmdroid.tileprovider.tilesource.ITileSource;
import org.mozilla.osmdroid.tileprovider.tilesource.XYTileSource;
import org.mozilla.osmdroid.tileprovider.util.SimpleInvalidationHandler;
import org.mozilla.osmdroid.views.MapView;

import org.mozilla.osmdroid.tileprovider.MapTile;

public class LowResMapOverlay extends AbstractMapOverlay {
public static final int LOW_ZOOM_LEVEL = 11;

public LowResMapOverlay(TileResType type, final Context aContext, boolean isMLSTileStore, MapView mapView) {
public LowResMapOverlay(TileResType type, final Context aContext, MapView mapView) {
super(aContext);

final int zoomLevel = (type == TileResType.HIGHER_ZOOM) ?
AbstractMapOverlay.getDisplaySizeBasedMinZoomLevel() : LOW_ZOOM_LEVEL;

ITileSource mapTileSource;
if (isMLSTileStore) {
mapTileSource = new XYTileSource(MLS_MAP_TILE_BASE_NAME, null,
zoomLevel, zoomLevel,
AbstractMapOverlay.TILE_PIXEL_SIZE,
AbstractMapOverlay.FILE_TYPE_SUFFIX_PNG,
new String[]{BuildConfig.TILE_SERVER_URL});
} else {
mapTileSource = new XYTileSource("MapquestOSM", ResourceProxy.string.mapquest_osm,
zoomLevel, zoomLevel,
AbstractMapOverlay.TILE_PIXEL_SIZE, ".jpg", new String[]{
"http://otile1.mqcdn.com/tiles/1.0.0/map/",
"http://otile2.mqcdn.com/tiles/1.0.0/map/",
"http://otile3.mqcdn.com/tiles/1.0.0/map/",
"http://otile4.mqcdn.com/tiles/1.0.0/map/"});
}

ITileSource mapTileSource = new XYTileSource(MLS_MAP_TILE_BASE_NAME, null,
zoomLevel, zoomLevel,
AbstractMapOverlay.TILE_PIXEL_SIZE,
AbstractMapOverlay.FILE_TYPE_SUFFIX_PNG,
AppGlobals.MAPBOX_TILE_URLS) {
public String getTileURLString(MapTile aTile) {
return super.getTileURLString(aTile) + "?access_token=" + AppGlobals.MAPBOX_ACCESS_CODE;
}
};

this.setLoadingBackgroundColor(Color.TRANSPARENT);
mTileProvider.setTileRequestCompleteHandler(new SimpleInvalidationHandler(mapView));
mTileProvider.setTileSource(mapTileSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

public class AppGlobals {

public static final String MAPBOX_ACCESS_CODE = "pk.eyJ1IjoibW96aWxsYS13ZWJwcm9kIiwiYSI6ImNqMml4MXNhaTAwMjgzM28yYXRqbjlmZmkifQ.OfL6NY7noQth9mbbN_tDbA";
public static final String MAPBOX_LAYER_TYPE = "mapbox.streets";
public static final String[] MAPBOX_TILE_URLS = new String[]{
"http://a.tiles.mapbox.com/v4/" + AppGlobals.MAPBOX_LAYER_TYPE + "/",
"http://b.tiles.mapbox.com/v4/" + AppGlobals.MAPBOX_LAYER_TYPE + "/",
"http://c.tiles.mapbox.com/v4/" + AppGlobals.MAPBOX_LAYER_TYPE + "/",
"http://d.tiles.mapbox.com/v4/" + AppGlobals.MAPBOX_LAYER_TYPE + "/"
};

/* All intent actions start with this string. Only locally broadcasted. */
public static final String ACTION_NAMESPACE = "org.mozilla.mozstumbler.intent.action";

Expand Down

0 comments on commit a0321a9

Please sign in to comment.