Skip to content

Commit 6213096

Browse files
Support for centering map on start location from servers.json
1 parent 044b211 commit 6213096

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/src/main/java/org/open311/android/MapActivity.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.mapbox.mapboxsdk.maps.MapboxMap;
3838
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
3939

40+
import org.codeforamerica.open311.facade.data.City;
4041
import org.open311.android.adapters.GeocoderAdapter;
4142
import org.open311.android.helpers.Utils;
4243
import org.open311.android.widgets.GeocoderView;
@@ -82,6 +83,7 @@ private enum source {
8283
protected void onCreate(Bundle savedInstanceState) {
8384

8485
super.onCreate(savedInstanceState);
86+
8587
// Mapbox access token only needs to be configured once in your app
8688
MapboxAccountManager.start(this, getString(R.string.mapbox_api_key));
8789
setContentView(R.layout.activity_map);
@@ -97,6 +99,14 @@ protected void onCreate(Bundle savedInstanceState) {
9799
mapView.getMapAsync(new OnMapReadyCallback() {
98100
@Override
99101
public void onMapReady(MapboxMap mapboxMap) {
102+
City city = City.fromString(getString(R.string.open311_endpoint));
103+
if (city.getMap() != null) {
104+
LatLng point = new LatLng(city.getMap().getLat(), city.getMap().getLon());
105+
mapboxMap.setCameraPosition(new CameraPosition.Builder()
106+
.target(point)
107+
.zoom(new Double(city.getMap().getZoom()))
108+
.build());
109+
}
100110
map = mapboxMap;
101111
map.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
102112
@Override
@@ -209,7 +219,6 @@ private void updateAddress(Address result) {
209219
TextView AddressLine = (TextView) findViewById((R.id.address));
210220
TextView CoordsLine = (TextView) findViewById((R.id.coords));
211221
assert AddressLine != null;
212-
//AddressLine.setText(Utils.addressString(address));
213222
AddressLine.setText(Utils.formatAddress(address));
214223
assert CoordsLine != null;
215224
String coordText = String.format(Locale.getDefault(), "(%f, %f)", latitude, longitude);

app/src/main/res/layout/activity_map.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
android:layout_width="fill_parent"
2020
android:layout_height="fill_parent"
2121
mapbox:access_token="@string/mapbox_api_key"
22-
mapbox:center_latitude="41.885"
23-
mapbox:center_longitude="-87.679"
2422
mapbox:style_url="@string/style_mapbox_streets"
25-
mapbox:tilt="0"
26-
mapbox:zoom="12" />
23+
mapbox:tilt="0" />
2724

2825
</RelativeLayout>
2926

@@ -37,6 +34,7 @@
3734
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
3835

3936
<android.support.v7.widget.LinearLayoutCompat xmlns:app="http://schemas.android.com/apk/res-auto"
37+
android:id="@+id/addressdialog"
4038
android:layout_width="match_parent"
4139
android:layout_height="match_parent"
4240
android:layout_marginEnd="70dp"
@@ -45,7 +43,6 @@
4543
android:layout_marginStart="10dp"
4644
android:layout_marginTop="10dp"
4745
android:foregroundGravity="bottom"
48-
android:id="@+id/addressdialog"
4946
android:orientation="vertical">
5047

5148
<TextView

org.codeforamerica.open311

0 commit comments

Comments
 (0)