Skip to content

Commit 0f6c39f

Browse files
Migrate to mapzen-android-sdk 1.0.6 (#702)
* Migrate to mapzen-android-sdk 1.0.6 * Use camera api
1 parent ee833df commit 0f6c39f

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ gradle.startParameter.getTaskNames().each { task ->
128128
dependencies {
129129
compile 'com.android.support:appcompat-v7:23.4.0'
130130
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
131-
compile 'com.mapzen:mapzen-android-sdk:1.0.5'
131+
compile 'com.mapzen:mapzen-android-sdk:1.0.6'
132132
compile('com.mapzen.android:pelias-android-sdk:0.7.1') {
133133
exclude group: 'javax.annotation:javax', module: 'javax.annotation-api'
134134
}

app/src/main/kotlin/com/mapzen/erasermap/controller/MainActivity.kt

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Intent
77
import android.content.SharedPreferences
88
import android.content.pm.PackageManager
99
import android.graphics.Point
10+
import android.graphics.PointF
1011
import android.graphics.drawable.Drawable
1112
import android.os.Bundle
1213
import android.os.Handler
@@ -29,6 +30,7 @@ import android.widget.Toast
2930
import com.mapzen.android.MapView
3031
import com.mapzen.android.MapzenMap
3132
import com.mapzen.android.lost.api.LocationServices
33+
import com.mapzen.android.model.CameraType
3234
import com.mapzen.erasermap.CrashReportService
3335
import com.mapzen.erasermap.EraserMapApplication
3436
import com.mapzen.erasermap.R
@@ -91,9 +93,6 @@ class MainActivity : AppCompatActivity(), MainViewController,
9193
@JvmStatic val MAP_DATA_PROP_NAME = "name"
9294
@JvmStatic val DIRECTION_LIST_ANIMATION_DURATION = 300L
9395
@JvmStatic val PERMISSIONS_REQUEST: Int = 1
94-
@JvmStatic val SCENE_CAMERA = "cameras"
95-
@JvmStatic val SCENE_CAMERA_ISOMETRIC = "{isometric: {type: isometric}}"
96-
@JvmStatic val SCENE_CAMERA_PERSPECTIVE = "{perspective: {type: perspective}}"
9796
}
9897

9998
@Inject lateinit var savedSearch: SavedSearch
@@ -264,15 +263,15 @@ class MainActivity : AppCompatActivity(), MainViewController,
264263
override fun onSingleTapUp(x: Float, y: Float): Boolean = false
265264
override fun onSingleTapConfirmed(x: Float, y: Float): Boolean {
266265
confidenceHandler.longPressed = false
267-
val coords = mapzenMap?.coordinatesAtScreenPosition(x.toDouble(), y.toDouble())
266+
val coords = mapzenMap?.screenPositionToLngLat(PointF(x.toFloat(), y.toFloat()))
268267
presenter.reverseGeoLngLat = coords
269268
poiTapPoint = floatArrayOf(x, y)
270269
return true
271270
}
272271
}
273272
mapzenMap?.setDoubleTapResponder({ x, y ->
274273
confidenceHandler.longPressed = false
275-
val tappedPos = mapzenMap?.coordinatesAtScreenPosition(x.toDouble(), y.toDouble())
274+
val tappedPos = mapzenMap?.screenPositionToLngLat(PointF(x.toFloat(), y.toFloat()))
276275
val currentPos = mapzenMap?.position
277276
if (tappedPos != null && currentPos != null) {
278277
mapzenMap?.setZoom((mapzenMap?.zoom as Float) + 1.0f, 500)
@@ -663,9 +662,9 @@ class MainActivity : AppCompatActivity(), MainViewController,
663662

664663
val lngLat: LngLat?
665664
if (poiTapPoint != null) {
666-
val x = poiTapPoint!![0].toDouble()
667-
val y = poiTapPoint!![1].toDouble()
668-
lngLat = mapzenMap?.coordinatesAtScreenPosition(x, y)
665+
val x = poiTapPoint!![0].toFloat()
666+
val y = poiTapPoint!![1].toFloat()
667+
lngLat = mapzenMap?.screenPositionToLngLat(PointF(x, y))
669668

670669
// Fallback for a failed Pelias Place Callback
671670
overridePlaceFeature(features.get(0))
@@ -686,10 +685,10 @@ class MainActivity : AppCompatActivity(), MainViewController,
686685

687686
var lngLat: LngLat? = null
688687

689-
val pointX = poiTapPoint?.get(0)?.toDouble()
690-
val pointY = poiTapPoint?.get(1)?.toDouble()
688+
val pointX = poiTapPoint?.get(0)?.toFloat()
689+
val pointY = poiTapPoint?.get(1)?.toFloat()
691690
if (pointX != null && pointY != null) {
692-
lngLat = mapzenMap?.coordinatesAtScreenPosition(pointX, pointY)
691+
lngLat = mapzenMap?.screenPositionToLngLat(PointF(pointX, pointY))
693692
}
694693

695694
mapzenMap?.clearDroppedPins()
@@ -756,7 +755,7 @@ class MainActivity : AppCompatActivity(), MainViewController,
756755

757756
override fun reverseGeolocate(screenX: Float, screenY: Float) {
758757
pelias.setLocationProvider(presenter.getPeliasLocationProvider())
759-
val coords = mapzenMap?.coordinatesAtScreenPosition(screenX.toDouble(), screenY.toDouble())
758+
val coords = mapzenMap?.screenPositionToLngLat(PointF(screenX.toFloat(), screenY.toFloat()))
760759
presenter.reverseGeoLngLat = coords
761760
presenter.currentFeature = getGenericLocationFeature(coords?.latitude as Double,
762761
coords?.longitude as Double)
@@ -878,8 +877,8 @@ class MainActivity : AppCompatActivity(), MainViewController,
878877
val screen = Point()
879878
windowManager.defaultDisplay.getSize(screen)
880879
// Take half of the y dimension to allow space for other UI elements
881-
val viewMin = mapzenMap?.coordinatesAtScreenPosition(0.0, screen.y.toDouble() * 0.25) ?: LngLat()
882-
val viewMax = mapzenMap?.coordinatesAtScreenPosition(screen.x.toDouble(), screen.y.toDouble() * 0.75) ?: LngLat()
880+
val viewMin = mapzenMap?.screenPositionToLngLat(PointF(0.0f, screen.y.toFloat() * 0.25f)) ?: LngLat()
881+
val viewMax = mapzenMap?.screenPositionToLngLat(PointF(screen.x.toFloat(), screen.y.toFloat() * 0.75f)) ?: LngLat()
883882

884883
// Determine the amount of re-scaling needed to view the route
885884
val scaleX = routeBounds.width / Math.abs(viewMax.longitude - viewMin.longitude)
@@ -1075,14 +1074,12 @@ class MainActivity : AppCompatActivity(), MainViewController,
10751074

10761075
private fun setRoutingCamera() {
10771076
if (routeModeView.isResumeButtonHidden()) {
1078-
mapzenMap?.queueSceneUpdate(SCENE_CAMERA, SCENE_CAMERA_PERSPECTIVE)
1079-
mapzenMap?.applySceneUpdates()
1077+
mapzenMap?.cameraType = CameraType.PERSPECTIVE
10801078
}
10811079
}
10821080

10831081
private fun setDefaultCamera() {
1084-
mapzenMap?.queueSceneUpdate(SCENE_CAMERA, SCENE_CAMERA_ISOMETRIC)
1085-
mapzenMap?.applySceneUpdates()
1082+
mapzenMap?.cameraType = CameraType.ISOMETRIC
10861083
}
10871084

10881085
private fun showRoutingMode(feature: Feature) {
@@ -1115,10 +1112,10 @@ class MainActivity : AppCompatActivity(), MainViewController,
11151112
if (poiTapPoint != null) {
11161113
val geometry = Geometry()
11171114
val coordinates = ArrayList<Double>()
1118-
val pointX = poiTapPoint?.get(0)?.toDouble()
1119-
val pointY = poiTapPoint?.get(1)?.toDouble()
1115+
val pointX = poiTapPoint?.get(0)?.toFloat()
1116+
val pointY = poiTapPoint?.get(1)?.toFloat()
11201117
if (pointX != null && pointY != null) {
1121-
val coords = mapzenMap?.coordinatesAtScreenPosition(pointX, pointY)
1118+
val coords = mapzenMap?.screenPositionToLngLat(PointF(pointX, pointY))
11221119
val lng = coords?.longitude
11231120
val lat = coords?.latitude
11241121
if (lng != null && lat!= null) {

app/src/main/kotlin/com/mapzen/erasermap/model/MapzenLocationImpl.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapzen.erasermap.model
22

33
import android.content.Context
4+
import android.graphics.PointF
45
import android.location.Location
56
import android.util.Log
67
import android.view.WindowManager
@@ -99,8 +100,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
99100
override fun getLat(): Double {
100101
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
101102
val display = windowManager.defaultDisplay
102-
val midLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble()/2,
103-
display.height.toDouble()/2)
103+
val midLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat() / 2,
104+
display.height.toFloat() / 2))
104105
if (midLatLon?.latitude == null) {
105106
return 0.0
106107
}
@@ -110,8 +111,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
110111
override fun getLon(): Double {
111112
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
112113
val display = windowManager.defaultDisplay
113-
val midLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble()/2,
114-
display.height.toDouble()/2)
114+
val midLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat()/2,
115+
display.height.toFloat()/2))
115116
if (midLatLon?.longitude == null) {
116117
return 0.0
117118
}
@@ -121,8 +122,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
121122
override fun getBoundingBox(): BoundingBox? {
122123
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
123124
val display = windowManager.defaultDisplay
124-
val minLatLon = mapzenMap?.coordinatesAtScreenPosition(0.0, display.height.toDouble())
125-
val maxLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble(), 0.0)
125+
val minLatLon = mapzenMap?.screenPositionToLngLat(PointF(0.0f, display.height.toFloat()))
126+
val maxLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat(), 0.0f))
126127
val boundingBox: BoundingBox = BoundingBox(
127128
minLatLon?.latitude as Double,
128129
minLatLon?.longitude as Double,

app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapzen.erasermap.view
22

33
import android.content.Context
44
import android.graphics.Point
5+
import android.graphics.PointF
56
import android.location.Location
67
import android.os.Handler
78
import android.support.v4.view.PagerAdapter
@@ -283,13 +284,13 @@ class RouteModeView : LinearLayout, RouteViewController, ViewPager.OnPageChangeL
283284
val display = windowManager.defaultDisplay
284285
val point = Point()
285286
display.getSize(point)
286-
val screenWidth = point.x.toDouble()
287-
val screenHeight = point.y.toDouble()
287+
val screenWidth = point.x.toFloat()
288+
val screenHeight = point.y.toFloat()
288289

289290
// Find the view that will place the current location marker in the lower quarter
290291
// of the window.
291-
val nextPosition = mapzenMap?.coordinatesAtScreenPosition(screenWidth/2,
292-
screenHeight/3.5) ?: LngLat()
292+
val nextPosition = mapzenMap?.screenPositionToLngLat(PointF(screenWidth / 2,
293+
screenHeight / 3.5f)) ?: LngLat()
293294
val nextRotation = getBearingInRadians(location)
294295

295296
// Return to our initial view to prepare for easing to the next view

0 commit comments

Comments
 (0)