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.
- Loading branch information
Showing
9 changed files
with
246 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"properties": { | ||
"description": "Ford's\nTheater", | ||
"icon": "theatre" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.038659, 38.931567] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "The\nGaslight", | ||
"icon": "theatre" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.003168, 38.894651] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "Horrible\nHarry's", | ||
"icon": "bar" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.090372, 38.881189] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "Bike\nParty", | ||
"icon": "bicycle" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.052477, 38.943951] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "Rockabilly\nRockstars", | ||
"icon": "music" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.031706, 38.914581] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "District\nDrum Tribe", | ||
"icon": "music" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.020945, 38.878241] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { | ||
"description": "Motown\nMemories", | ||
"icon": "music" | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [-77.007481, 38.876516] | ||
} | ||
}] | ||
} |
129 changes: 129 additions & 0 deletions
129
...ain/java/com/mapbox/mapboxandroiddemo/examples/styles/VariableLabelPlacementActivity.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,129 @@ | ||
package com.mapbox.mapboxandroiddemo.examples.styles; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.Toast; | ||
|
||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
import com.mapbox.mapboxsdk.maps.Style; | ||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer; | ||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; | ||
|
||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get; | ||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_BOTTOM; | ||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_LEFT; | ||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_RIGHT; | ||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_TOP; | ||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_AUTO; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textJustify; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRadialOffset; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; | ||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textVariableAnchor; | ||
|
||
|
||
/** | ||
* To increase the chance of high-priority labels staying visible, provide the map | ||
* renderer a list of preferred text anchor positions via | ||
* {@link com.mapbox.mapboxsdk.style.layers.PropertyFactory#textVariableAnchor(String[])}. | ||
*/ | ||
public class VariableLabelPlacementActivity extends AppCompatActivity { | ||
|
||
private static final String GEOJSON_SRC_ID = "poi_source_id"; | ||
private static final String POI_LABELS_LAYER_ID = "poi_labels_layer_id"; | ||
private MapView mapView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Mapbox access token is configured here. This needs to be called either in your application | ||
// object or in the same activity which contains the mapview. | ||
Mapbox.getInstance(this, getString(R.string.access_token)); | ||
|
||
// This contains the MapView in XML and needs to be called after the access token is configured. | ||
setContentView(R.layout.activity_style_variable_text_placement); | ||
|
||
mapView = findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(new OnMapReadyCallback() { | ||
@Override | ||
public void onMapReady(@NonNull final MapboxMap mapboxMap) { | ||
|
||
GeoJsonSource source = new GeoJsonSource(GEOJSON_SRC_ID); | ||
source.setUrl("asset://poi_places.geojson"); | ||
|
||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.LIGHT) | ||
.withSource(source) | ||
// Adds a SymbolLayer to display POI labels | ||
.withLayer(new SymbolLayer(POI_LABELS_LAYER_ID, GEOJSON_SRC_ID) | ||
.withProperties( | ||
textField(get("description")), | ||
textSize(17f), | ||
textColor(Color.RED), | ||
textVariableAnchor( | ||
new String[]{TEXT_ANCHOR_TOP, TEXT_ANCHOR_BOTTOM, TEXT_ANCHOR_LEFT, TEXT_ANCHOR_RIGHT}), | ||
textJustify(TEXT_JUSTIFY_AUTO), | ||
textRadialOffset(0.5f))), | ||
new Style.OnStyleLoaded() { | ||
@Override | ||
public void onStyleLoaded(@NonNull final Style style) { | ||
Toast.makeText(VariableLabelPlacementActivity.this, | ||
getString(R.string.zoom_map_in_and_out_variable_label_instruction), | ||
Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// Add the mapView lifecycle to the activity's lifecycle methods | ||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
MapboxAndroidDemo/src/main/res/layout/activity_style_variable_text_placement.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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
mapbox:mapbox_cameraTargetLat="38.907" | ||
mapbox:mapbox_cameraTargetLng="-77.04" | ||
mapbox:mapbox_cameraZoom="11.15"/> | ||
|
||
</FrameLayout> |
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
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