Skip to content

Commit

Permalink
Migrate to mapzen-android-sdk 1.0.6 (#702)
Browse files Browse the repository at this point in the history
* Migrate to mapzen-android-sdk 1.0.6

* Use camera api
  • Loading branch information
sarahsnow1 authored Jul 23, 2016
1 parent ee833df commit 0f6c39f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ gradle.startParameter.getTaskNames().each { task ->
dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.mapzen:mapzen-android-sdk:1.0.5'
compile 'com.mapzen:mapzen-android-sdk:1.0.6'
compile('com.mapzen.android:pelias-android-sdk:0.7.1') {
exclude group: 'javax.annotation:javax', module: 'javax.annotation-api'
}
Expand Down
39 changes: 18 additions & 21 deletions app/src/main/kotlin/com/mapzen/erasermap/controller/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.graphics.Point
import android.graphics.PointF
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
Expand All @@ -29,6 +30,7 @@ import android.widget.Toast
import com.mapzen.android.MapView
import com.mapzen.android.MapzenMap
import com.mapzen.android.lost.api.LocationServices
import com.mapzen.android.model.CameraType
import com.mapzen.erasermap.CrashReportService
import com.mapzen.erasermap.EraserMapApplication
import com.mapzen.erasermap.R
Expand Down Expand Up @@ -91,9 +93,6 @@ class MainActivity : AppCompatActivity(), MainViewController,
@JvmStatic val MAP_DATA_PROP_NAME = "name"
@JvmStatic val DIRECTION_LIST_ANIMATION_DURATION = 300L
@JvmStatic val PERMISSIONS_REQUEST: Int = 1
@JvmStatic val SCENE_CAMERA = "cameras"
@JvmStatic val SCENE_CAMERA_ISOMETRIC = "{isometric: {type: isometric}}"
@JvmStatic val SCENE_CAMERA_PERSPECTIVE = "{perspective: {type: perspective}}"
}

@Inject lateinit var savedSearch: SavedSearch
Expand Down Expand Up @@ -264,15 +263,15 @@ class MainActivity : AppCompatActivity(), MainViewController,
override fun onSingleTapUp(x: Float, y: Float): Boolean = false
override fun onSingleTapConfirmed(x: Float, y: Float): Boolean {
confidenceHandler.longPressed = false
val coords = mapzenMap?.coordinatesAtScreenPosition(x.toDouble(), y.toDouble())
val coords = mapzenMap?.screenPositionToLngLat(PointF(x.toFloat(), y.toFloat()))
presenter.reverseGeoLngLat = coords
poiTapPoint = floatArrayOf(x, y)
return true
}
}
mapzenMap?.setDoubleTapResponder({ x, y ->
confidenceHandler.longPressed = false
val tappedPos = mapzenMap?.coordinatesAtScreenPosition(x.toDouble(), y.toDouble())
val tappedPos = mapzenMap?.screenPositionToLngLat(PointF(x.toFloat(), y.toFloat()))
val currentPos = mapzenMap?.position
if (tappedPos != null && currentPos != null) {
mapzenMap?.setZoom((mapzenMap?.zoom as Float) + 1.0f, 500)
Expand Down Expand Up @@ -663,9 +662,9 @@ class MainActivity : AppCompatActivity(), MainViewController,

val lngLat: LngLat?
if (poiTapPoint != null) {
val x = poiTapPoint!![0].toDouble()
val y = poiTapPoint!![1].toDouble()
lngLat = mapzenMap?.coordinatesAtScreenPosition(x, y)
val x = poiTapPoint!![0].toFloat()
val y = poiTapPoint!![1].toFloat()
lngLat = mapzenMap?.screenPositionToLngLat(PointF(x, y))

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

var lngLat: LngLat? = null

val pointX = poiTapPoint?.get(0)?.toDouble()
val pointY = poiTapPoint?.get(1)?.toDouble()
val pointX = poiTapPoint?.get(0)?.toFloat()
val pointY = poiTapPoint?.get(1)?.toFloat()
if (pointX != null && pointY != null) {
lngLat = mapzenMap?.coordinatesAtScreenPosition(pointX, pointY)
lngLat = mapzenMap?.screenPositionToLngLat(PointF(pointX, pointY))
}

mapzenMap?.clearDroppedPins()
Expand Down Expand Up @@ -756,7 +755,7 @@ class MainActivity : AppCompatActivity(), MainViewController,

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

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

private fun setRoutingCamera() {
if (routeModeView.isResumeButtonHidden()) {
mapzenMap?.queueSceneUpdate(SCENE_CAMERA, SCENE_CAMERA_PERSPECTIVE)
mapzenMap?.applySceneUpdates()
mapzenMap?.cameraType = CameraType.PERSPECTIVE
}
}

private fun setDefaultCamera() {
mapzenMap?.queueSceneUpdate(SCENE_CAMERA, SCENE_CAMERA_ISOMETRIC)
mapzenMap?.applySceneUpdates()
mapzenMap?.cameraType = CameraType.ISOMETRIC
}

private fun showRoutingMode(feature: Feature) {
Expand Down Expand Up @@ -1115,10 +1112,10 @@ class MainActivity : AppCompatActivity(), MainViewController,
if (poiTapPoint != null) {
val geometry = Geometry()
val coordinates = ArrayList<Double>()
val pointX = poiTapPoint?.get(0)?.toDouble()
val pointY = poiTapPoint?.get(1)?.toDouble()
val pointX = poiTapPoint?.get(0)?.toFloat()
val pointY = poiTapPoint?.get(1)?.toFloat()
if (pointX != null && pointY != null) {
val coords = mapzenMap?.coordinatesAtScreenPosition(pointX, pointY)
val coords = mapzenMap?.screenPositionToLngLat(PointF(pointX, pointY))
val lng = coords?.longitude
val lat = coords?.latitude
if (lng != null && lat!= null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapzen.erasermap.model

import android.content.Context
import android.graphics.PointF
import android.location.Location
import android.util.Log
import android.view.WindowManager
Expand Down Expand Up @@ -99,8 +100,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
override fun getLat(): Double {
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = windowManager.defaultDisplay
val midLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble()/2,
display.height.toDouble()/2)
val midLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat() / 2,
display.height.toFloat() / 2))
if (midLatLon?.latitude == null) {
return 0.0
}
Expand All @@ -110,8 +111,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
override fun getLon(): Double {
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = windowManager.defaultDisplay
val midLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble()/2,
display.height.toDouble()/2)
val midLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat()/2,
display.height.toFloat()/2))
if (midLatLon?.longitude == null) {
return 0.0
}
Expand All @@ -121,8 +122,8 @@ public class MapzenLocationImpl(val locationClient: LostApiClient,
override fun getBoundingBox(): BoundingBox? {
val windowManager = application.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = windowManager.defaultDisplay
val minLatLon = mapzenMap?.coordinatesAtScreenPosition(0.0, display.height.toDouble())
val maxLatLon = mapzenMap?.coordinatesAtScreenPosition(display.width.toDouble(), 0.0)
val minLatLon = mapzenMap?.screenPositionToLngLat(PointF(0.0f, display.height.toFloat()))
val maxLatLon = mapzenMap?.screenPositionToLngLat(PointF(display.width.toFloat(), 0.0f))
val boundingBox: BoundingBox = BoundingBox(
minLatLon?.latitude as Double,
minLatLon?.longitude as Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mapzen.erasermap.view

import android.content.Context
import android.graphics.Point
import android.graphics.PointF
import android.location.Location
import android.os.Handler
import android.support.v4.view.PagerAdapter
Expand Down Expand Up @@ -283,13 +284,13 @@ class RouteModeView : LinearLayout, RouteViewController, ViewPager.OnPageChangeL
val display = windowManager.defaultDisplay
val point = Point()
display.getSize(point)
val screenWidth = point.x.toDouble()
val screenHeight = point.y.toDouble()
val screenWidth = point.x.toFloat()
val screenHeight = point.y.toFloat()

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

// Return to our initial view to prepare for easing to the next view
Expand Down

0 comments on commit 0f6c39f

Please sign in to comment.