Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Convert To Vector Maps #36

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions MapBoxAndroidDemo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'io.fabric.tools:gradle:1.+'
}
}

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'io.fabric'

repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 22
compileSdkVersion 23
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 14
versionName "1.7.4"
minSdkVersion 15
targetSdkVersion 23
versionCode 15
versionName "2.1.0"
}

/*
Expand All @@ -50,10 +50,12 @@ android {


dependencies {
compile 'com.android.support:gridlayout-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar'){
compile 'com.android.support:gridlayout-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:2.1.0@aar'){
transitive=true
}
compile 'com.crashlytics.android:crashlytics:1.+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
}
4 changes: 3 additions & 1 deletion MapBoxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.crashlytics.ApiKey" android:value="355ed2226e91828602605c24c8ac23dead96ba81"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,100 @@
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.crashlytics.android.Crashlytics;
import com.mapbox.mapboxsdk.api.ILatLng;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.overlay.Icon;
import com.mapbox.mapboxsdk.overlay.Marker;
import com.mapbox.mapboxsdk.overlay.UserLocationOverlay;
import com.mapbox.mapboxsdk.tileprovider.tilesource.*;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.views.util.TilesLoadedListener;
import io.fabric.sdk.android.Fabric;

public class MainActivity extends ActionBarActivity {

private MapView mv;
private UserLocationOverlay myLocationOverlay;
private String currentMap = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Crashlytics.start(this);
Fabric.with(this, new Crashlytics());

setContentView(R.layout.activity_main);

mv = (MapView) findViewById(R.id.mapview);
mv.setMinZoomLevel(mv.getTileProvider().getMinimumZoomLevel());
mv.setMaxZoomLevel(mv.getTileProvider().getMaximumZoomLevel());
mv.setCenter(mv.getTileProvider().getCenterCoordinate());
mv.setZoom(0);
currentMap = getString(R.string.streetMapId);
mv.setStyle(Style.MAPBOX_STREETS);
mv.setCenterCoordinate(new LatLng(0, 0));

// Show user location (purposely not in follow mode)
mv.setUserLocationEnabled(true);

mv.loadFromGeoJSONURL("https://gist.githubusercontent.com/tmcw/10307131/raw/21c0a20312a2833afeee3b46028c3ed0e9756d4c/map.geojson");
// setButtonListeners();
Marker m = new Marker(mv, "Edinburgh", "Scotland", new LatLng(55.94629, -3.20777));
m.setIcon(new Icon(this, Icon.Size.SMALL, "marker-stroked", "ee8a65"));
mv.addMarker(m);

m = new Marker(mv, "Stockholm", "Sweden", new LatLng(59.32995, 18.06461));
m.setIcon(new Icon(this, Icon.Size.LARGE, "city", "3887be"));
mv.addMarker(m);

m = new Marker(mv, "Prague", "Czech Republic", new LatLng(50.08734, 14.42112));
m.setIcon(new Icon(this, Icon.Size.MEDIUM, "land-use", "3bb2d0"));
mv.addMarker(m);

m = new Marker(mv, "Athens", "Greece", new LatLng(37.97885, 23.71399));
mv.addMarker(m);

m = new Marker(mv, "Tokyo", "Japan", new LatLng(35.70247, 139.71588));
m.setIcon(new Icon(this, Icon.Size.LARGE, "city", "3887be"));
mv.addMarker(m);

m = new Marker(mv, "Ayacucho", "Peru", new LatLng(-13.16658, -74.21608));
m.setIcon(new Icon(this, Icon.Size.LARGE, "city", "3887be"));
mv.addMarker(m);

m = new Marker(mv, "Nairobi", "Kenya", new LatLng(-1.26676, 36.83372));
m.setIcon(new Icon(this, Icon.Size.LARGE, "city", "3887be"));
mv.addMarker(m);

m = new Marker(mv, "Canberra", "Australia", new LatLng(-35.30952, 149.12430));
m.setIcon(new Icon(this, Icon.Size.LARGE, "city", "3887be"));
mv.addMarker(m);

mv.setOnTilesLoadedListener(new TilesLoadedListener() {
@Override
public boolean onTilesLoaded() {
return false;
}

@Override
public boolean onTilesLoadStarted() {
// TODO Auto-generated method stub
return false;
}
});
// mv.setVisibility(View.VISIBLE);
mv.setMyLocationEnabled(true);

// mv.loadFromGeoJSONURL("https://gist.githubusercontent.com/tmcw/10307131/raw/21c0a20312a2833afeee3b46028c3ed0e9756d4c/map.geojson");
mv.addMarker(new MarkerOptions().title("Edinburgh").snippet("Scotland").position(new LatLng(55.94629, -3.20777)));
mv.addMarker(new MarkerOptions().title("Stockholm").snippet("Sweden").position(new LatLng(59.32995, 18.06461)));
mv.addMarker(new MarkerOptions().title("Prague").snippet("Czech Republic").position(new LatLng(50.08734, 14.42112)));
mv.addMarker(new MarkerOptions().title("Athens").snippet("Greece").position(new LatLng(37.97885, 23.71399)));
mv.addMarker(new MarkerOptions().title("Tokyo").snippet("Japan").position(new LatLng(35.70247, 139.71588)));
mv.addMarker(new MarkerOptions().title("Ayacucho").snippet("Peru").position(new LatLng(-13.16658, -74.21608)));
mv.addMarker(new MarkerOptions().title("Nairobi").snippet("Kenya").position(new LatLng(-1.26676, 36.83372)));
mv.addMarker(new MarkerOptions().title("Canberra").snippet("Australia").position(new LatLng(-35.30952, 149.12430)));

Button bugsBut = changeButtonTypeface((Button) findViewById(R.id.bugsButton));
bugsBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://github.com/mapbox/mapbox-android-sdk/issues?state=open";
String url = "https://github.com/mapbox/mapbox-gl-native/issues?state=open";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
});
mv.onCreate(savedInstanceState);
}

@Override

/**
* Dispatch onStart() to all fragments. Ensure any created loaders are
* now started.
*/
@Override
protected void onStart() {
super.onStart();
mv.onStart();
}

@Override
protected void onDestroy() {
super.onDestroy();
mv.onDestroy();
}

/**
* Dispatch onResume() to fragments. Note that for better inter-operation
* with older versions of the platform, at the point of this call the
* fragments attached to the activity are <em>not</em> resumed. This means
* that in some cases the previous state may still be saved, not allowing
* fragment transactions that modify the state. To correctly interact
* with fragments in their proper state, you should instead override
* {@link #onResumeFragments()}.
*/
@Override
protected void onResume() {
super.onResume();
mv.onResume();
}

/**
* Dispatch onPause() to fragments.
*/
@Override
protected void onPause() {
super.onPause();
mv.onPause();
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
Expand All @@ -118,69 +113,40 @@ public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case R.id.menuItemStreets:
replaceMapView(getString(R.string.streetMapId));
mv.setStyle(Style.MAPBOX_STREETS);
return true;
case R.id.menuItemSatellite:
replaceMapView(getString(R.string.satelliteMapId));
return true;
case R.id.menuItemTerrain:
replaceMapView(getString(R.string.terrainMapId));
return true;
case R.id.menuItemOutdoors:
replaceMapView(getString(R.string.outdoorsMapId));
return true;
case R.id.menuItemWoodcut:
replaceMapView(getString(R.string.woodcutMapId));
mv.setStyle(Style.SATELLITE);
return true;
case R.id.menuItemPencil:
replaceMapView(getString(R.string.pencilMapId));
case R.id.menuItemEmerald:
mv.setStyle(Style.EMERALD);
return true;
case R.id.menuItemSpaceship:
replaceMapView(getString(R.string.spaceShipMapId));
case R.id.menuItemDark:
mv.setStyle(Style.DARK);
return true;
case R.id.menuItemLight:
mv.setStyle(Style.LIGHT);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

protected void replaceMapView(String layer) {

if (TextUtils.isEmpty(layer) || TextUtils.isEmpty(currentMap) || currentMap.equalsIgnoreCase(layer)) {
return;
}

ITileLayer source;
BoundingBox box;

source = new MapboxTileLayer(layer);

mv.setTileSource(source);
box = source.getBoundingBox();
mv.setScrollableAreaLimit(box);
mv.setMinZoomLevel(mv.getTileProvider().getMinimumZoomLevel());
mv.setMaxZoomLevel(mv.getTileProvider().getMaximumZoomLevel());
currentMap = layer;
/*
mv.setCenter(mv.getTileProvider().getCenterCoordinate());
mv.setZoom(0);
*/
}

private Button changeButtonTypeface(Button button) {
return button;
}

public LatLng getMapCenter() {
return mv.getCenter();
return mv.getCenterCoordinate();
}

public void setMapCenter(ILatLng center) {
mv.setCenter(center);
public void setMapCenter(LatLng center) {
mv.setCenterCoordinate(center);
}

/**
* Method to show settings in alert dialog
* On pressing Settings button will lauch Settings Options - GPS
* On pressing Settings button will launch Settings Options - GPS
*/
public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getBaseContext());
Expand Down
18 changes: 4 additions & 14 deletions MapBoxAndroidDemo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@


<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:mapid="@string/streetMapId"
mapbox:accessToken="@string/testAccessToken"/>

<ImageView android:layout_width="100dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/mblogo"
android:layout_marginTop="-10dp"
android:contentDescription="@string/mapbox"
android:id="@+id/imageView"/>
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:accessToken="@string/testAccessToken"/>

<Button
style="?android:attr/buttonStyleSmall"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
<item android:id="@+id/menuItemSatellite"
android:title="@string/satellite"/>

<item android:id="@+id/menuItemTerrain"
android:title="@string/terrain"/>
<item android:id="@+id/menuItemEmerald"
android:title="@string/emerald"/>

<item android:id="@+id/menuItemOutdoors"
android:title="@string/outdoors"/>
<item android:id="@+id/menuItemDark"
android:title="@string/dark"/>

<item android:id="@+id/menuItemWoodcut"
android:title="@string/woodcut"/>

<item android:id="@+id/menuItemPencil"
android:title="@string/pencil"/>

<item android:id="@+id/menuItemSpaceship"
android:title="@string/spaceShip"/>
<item android:id="@+id/menuItemLight"
android:title="@string/light"/>

</menu>
Loading