This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from mapbox/landuse-styling
Land use example example
- Loading branch information
Showing
11 changed files
with
259 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...oxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/LandUseStylingActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package com.mapbox.mapboxandroiddemo.labs; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.getbase.floatingactionbutton.FloatingActionButton; | ||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
import com.mapbox.mapboxsdk.style.layers.FillLayer; | ||
|
||
import static com.mapbox.mapboxsdk.style.layers.Filter.eq; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; | ||
|
||
public class LandUseStylingActivity extends AppCompatActivity { | ||
private static final String TAG = LandUseStylingActivity.class.getSimpleName(); | ||
|
||
private MapView mapView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_lab_land_use_styling); | ||
|
||
mapView = (MapView) findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(new OnMapReadyCallback() { | ||
@Override | ||
public void onMapReady(final MapboxMap mapboxMap) { | ||
|
||
FillLayer schoolLayer = new FillLayer("school-layer", "composite"); | ||
schoolLayer.setSourceLayer("landuse"); | ||
schoolLayer.setProperties( | ||
fillColor(Color.parseColor("#f6f6f4")) | ||
); | ||
schoolLayer.setFilter(eq("class", "school")); | ||
mapboxMap.addLayer(schoolLayer); | ||
|
||
FillLayer hospitalLayer = new FillLayer("hospital-layer", "composite"); | ||
hospitalLayer.setSourceLayer("landuse"); | ||
hospitalLayer.setProperties( | ||
fillColor(Color.parseColor("#eceeed")) | ||
); | ||
hospitalLayer.setFilter(eq("class", "hospital")); | ||
mapboxMap.addLayer(hospitalLayer); | ||
|
||
FloatingActionButton toggleParks = (FloatingActionButton) findViewById(R.id.fab_toggle_parks); | ||
toggleParks.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
FillLayer parks = mapboxMap.getLayerAs("parks"); | ||
if (parks != null) { | ||
|
||
if (!colorsEqual(parks.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxGreen))) { | ||
parks.setProperties( | ||
fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxGreen)) | ||
); | ||
} else { | ||
parks.setProperties( | ||
fillColor(Color.parseColor("#eceeed")) | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
FloatingActionButton toggleSchools = (FloatingActionButton) findViewById(R.id.fab_toggle_schools); | ||
toggleSchools.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
FillLayer schools = mapboxMap.getLayerAs("school-layer"); | ||
if (schools != null) { | ||
if (schools.getFillColor().isValue() && | ||
!colorsEqual(schools.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxYellow))) { | ||
schools.setProperties( | ||
fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxYellow)) | ||
); | ||
} else { | ||
schools.setProperties( | ||
fillColor(Color.parseColor("#f6f6f4")) | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
FloatingActionButton toggleHospital = (FloatingActionButton) findViewById(R.id.fab_toggle_hospital); | ||
toggleHospital.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
FillLayer hospital = mapboxMap.getLayerAs("hospital-layer"); | ||
if (hospital != null) { | ||
if (hospital.getFillColor().isValue() && | ||
!colorsEqual(hospital.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxPurple))) { | ||
hospital.setProperties( | ||
fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxPurple)) | ||
); | ||
} else { | ||
hospital.setProperties( | ||
fillColor(Color.parseColor("#eceeed")) | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
private boolean colorsEqual(int a, int b) { | ||
boolean equal = Math.abs(Color.red(a) - Color.red(b)) <= 10 && | ||
Math.abs(Color.green(a) - Color.green(b)) <= 10 && | ||
Math.abs(Color.blue(a) - Color.blue(b)) <= 10; | ||
|
||
Log.i(TAG, String.format("Comparing colors: %s, %s (%s, %s ,%s => %s)", | ||
a, | ||
b, | ||
Math.abs(Color.red(a) - Color.red(b)), | ||
Math.abs(Color.green(a) - Color.green(b)), | ||
Math.abs(Color.blue(a) - Color.blue(b)), | ||
equal) | ||
); | ||
return equal; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
MapboxAndroidDemo/src/main/res/drawable/fab_label_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="@color/black_semi_transparent"/> | ||
<padding | ||
android:left="16dp" | ||
android:top="4dp" | ||
android:right="16dp" | ||
android:bottom="4dp"/> | ||
<corners | ||
android:radius="2dp"/> | ||
</shape> |
59 changes: 59 additions & 0 deletions
59
MapboxAndroidDemo/src/main/res/layout/activity_lab_land_use_styling.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:fab="http://schemas.android.com/apk/res-auto" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".labs.LandUseStylingActivity"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
mapbox:center_latitude="51.7525" | ||
mapbox:center_longitude="-1.2606" | ||
mapbox:style_url="@string/style_light" | ||
mapbox:zoom="11"/> | ||
|
||
<com.getbase.floatingactionbutton.FloatingActionsMenu | ||
android:id="@+id/multiple_actions" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="end|bottom" | ||
android:layout_margin="16dp" | ||
fab:fab_addButtonColorNormal="@color/mapboxRed" | ||
fab:fab_addButtonColorPressed="@color/mapboxWhite" | ||
fab:fab_addButtonPlusIconColor="@color/mapboxWhite" | ||
fab:fab_labelStyle="@style/menu_labels_style"> | ||
|
||
<com.getbase.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/fab_toggle_schools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
fab:fab_colorNormal="@color/mapboxRed" | ||
fab:fab_colorPressed="@color/mapboxWhite" | ||
fab:fab_size="mini" | ||
fab:fab_title="Schools"/> | ||
|
||
<com.getbase.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/fab_toggle_parks" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
fab:fab_colorNormal="@color/mapboxRed" | ||
fab:fab_colorPressed="@color/mapboxWhite" | ||
fab:fab_size="mini" | ||
fab:fab_title="Parks"/> | ||
|
||
<com.getbase.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/fab_toggle_hospital" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
fab:fab_colorNormal="@color/mapboxRed" | ||
fab:fab_colorPressed="@color/mapboxWhite" | ||
fab:fab_size="mini" | ||
fab:fab_title="Hospitals"/> | ||
|
||
</com.getbase.floatingactionbutton.FloatingActionsMenu> | ||
</android.support.design.widget.CoordinatorLayout> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters