Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.yfind"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -26,17 +27,22 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
implementation 'com.esri.arcgisruntime:arcgis-android:100.7.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
// implementation 'androidx.multidex:multidex:2.0.1'
}
10 changes: 9 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
package="com.example.yfind">

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
Expand Down Expand Up @@ -37,6 +38,13 @@
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".SearchRoom" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
</application>

</manifest>
202 changes: 143 additions & 59 deletions app/src/main/java/com/example/yfind/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
package com.example.yfind

import android.app.SearchManager
import android.app.Service
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity

import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.location.Location
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.esri.arcgisruntime.concurrent.ListenableFuture
import com.esri.arcgisruntime.data.FeatureQueryResult
import com.esri.arcgisruntime.data.QueryParameters
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.esri.arcgisruntime.data.ServiceFeatureTable
import com.esri.arcgisruntime.geometry.Geometry
import com.esri.arcgisruntime.geometry.Point
import com.esri.arcgisruntime.geometry.SpatialReferences
import com.esri.arcgisruntime.layers.FeatureLayer
import com.esri.arcgisruntime.loadable.LoadStatus
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.Basemap
import kotlinx.android.synthetic.main.activity_main.mapView
import java.util.*
import com.esri.arcgisruntime.mapping.view.Graphic
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.symbology.PictureMarkerSymbol
import com.esri.arcgisruntime.symbology.SimpleLineSymbol
import com.esri.arcgisruntime.tasks.networkanalysis.Route
import com.esri.arcgisruntime.tasks.networkanalysis.RouteParameters
import com.esri.arcgisruntime.tasks.networkanalysis.RouteTask
import com.esri.arcgisruntime.tasks.networkanalysis.Stop
import kotlinx.android.synthetic.main.activity_main.*
import java.util.concurrent.ExecutionException


class MainActivity : AppCompatActivity() {
companion object {
private val TAG: String = MainActivity::class.java.simpleName
}

private val buildingsFeatureTable: ServiceFeatureTable by lazy {
ServiceFeatureTable(getString(R.string.buildings_url))
}
Expand All @@ -34,11 +49,28 @@ class MainActivity : AppCompatActivity() {
FeatureLayer(roomsFeatureTable)
}

private var MapView: MapView? = null
private var mRoute: Route? = null
private val mRouteTask: RouteTask? = null
private val mRouteParams: RouteParameters? = null
private var mSourcePoint: Point? = null
private var mDestinationPoint: Point? = null
private var mRouteSymbol: SimpleLineSymbol? = null
private var mGraphicsOverlay: GraphicsOverlay? = null
private var roomGeometry : Geometry? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val map = ArcGISMap(Basemap.Type.TOPOGRAPHIC, 40.249727, -111.649265, 16)
mapView.map = map
// MapView = findViewById(R.id.mapView)
val progressBar: ProgressBar = findViewById(R.id.progressBar)
val bundle: Bundle? = intent.extras
this.roomGeometry = Geometry.fromJson(bundle?.getString("geometry"))
val lo = LocationUtil()
var currentLocation: Location? = lo.currentLocation

val map = ArcGISMap(Basemap.Type.LIGHT_GRAY_CANVAS_VECTOR, 40.249727, -111.649265, 16)
// mapView.map = map

// create feature layer with its service feature table
// create the service feature table
Expand All @@ -55,65 +87,113 @@ class MainActivity : AppCompatActivity() {
//
// // add the layer to the map
// map.operationalLayers.add(buildingLayer)
// map.operationalLayers.add(roomsLayer)
map.operationalLayers.add(roomsLayer)

// set the map to be displayed in the mapview
mapView.map = map
}
override fun onNewIntent(intent: Intent) {
this.intent = intent

if (Intent.ACTION_SEARCH == intent.action) {
intent.getStringExtra(SearchManager.QUERY)?.let {
if (it.isNotEmpty()) {
searchBuildings(it)
setupSymbols()

progressBar.isInvisible = true


val routeTaskUrl =
"https://utility.arcgis.com/usrsvcs/servers/a8ee36150d1b4178b33affcb5d7027cb/rest/services/World/Route/NAServer/Route_World"
// create route task from San Diego service
val routeTask = RouteTask(applicationContext, routeTaskUrl)
// var listenableFuture: ListenableFuture<RouteParameters> = routeTask.createDefaultParametersAsync()

// routeTask.loadAsync()
val routeParameters = routeTask.createDefaultParametersAsync().get()

routeTask.addDoneLoadingListener {
if (routeTask.loadError == null && routeTask.loadStatus == LoadStatus.LOADED) { // route task has loaded successfully
try { // get default route parameters
// val ESPG_3857 = SpatialReference.create(102100);
val roomCenter = this.roomGeometry?.extent?.center
if (lo == null){

}
val stop1Loc = Stop(Point(lo.currentLocation!!.latitude, lo.currentLocation!!.longitude))
val stop2Loc = Stop(roomCenter)
// add route stops
routeParameters.setStops(listOf<Stop>(stop1Loc, stop2Loc))

val result = routeTask.solveRouteAsync(routeParameters).get()
val routes = result.routes
mRoute = routes[0]
val routeGraphic: Graphic = Graphic(mRoute?.routeGeometry, mRouteSymbol)
mGraphicsOverlay?.graphics?.add(routeGraphic);


val directions = mRoute?.directionManeuvers
// val directionsArray = List(directions.size!!)

// add mRouteSymbol graphic to the map
val selectedRouteSymbol = SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 5F)
val selectedRouteGraphic = Graphic(
directions?.get(0)?.getGeometry(),
selectedRouteSymbol)
mGraphicsOverlay?.graphics?.add(selectedRouteGraphic)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
progressBar.isVisible = false

}

private fun searchBuildings(searchString: String) {
// clear any previous selections
buildingLayer.clearSelection()
// create a query for the state that was entered
val query = QueryParameters()
// make search case insensitive
query.whereClause =
"(upper(Name) LIKE '% ${searchString.toUpperCase(Locale.US)}%' OR Upper(Acronym) LIKE '%${searchString.toUpperCase(Locale.US)}%') AND Acronym != ''"
// call select features
val future: ListenableFuture<FeatureQueryResult> = buildingsFeatureTable.queryFeaturesAsync(query)
// add done loading listener to fire when the selection returns
future.addDoneListener {
try {
// call get on the future to get the result
val result = future.get()
// check there are some results
val resultIterator = result.iterator()
if (resultIterator.hasNext()) {
resultIterator.next().run {
// get the extent of the first feature in the result to zoom to
// val envelope = geometry.extent
// mapView.setViewpointGeometryAsync(envelope, 10.0)
// // select the feature
// buildingLayer.selectFeature(this)
Log.d(TAG, attributes.toString())
}
} else {
"No buildings found with name: $searchString".also {
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
Log.d(TAG, it)
}
}
} catch (e: Exception) {
"Feature search failed for: $searchString. Error: ${e.message}".also {
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
Log.e(TAG, it)
}

private fun setupSymbols() {
mGraphicsOverlay = GraphicsOverlay()
//add the overlay to the map view
mapView?.graphicsOverlays?.add(mGraphicsOverlay)
//[DocRef: Name=Picture Marker Symbol Drawable-android, Category=Fundamentals, Topic=Symbols and Renderers]
//Create a picture marker symbol from an app resource
val startDrawable =
ContextCompat.getDrawable(this, R.drawable.ic_source) as BitmapDrawable?
val pinSourceSymbol: PictureMarkerSymbol
try {
pinSourceSymbol = PictureMarkerSymbol.createAsync(startDrawable).get()
pinSourceSymbol.loadAsync()
pinSourceSymbol.addDoneLoadingListener {
//add a new graphic as start point
mSourcePoint =
Point(-117.15083257944445, 32.741123367963446, SpatialReferences.getWgs84())
val pinSourceGraphic = Graphic(mSourcePoint, pinSourceSymbol)
mGraphicsOverlay!!.getGraphics().add(pinSourceGraphic)
}
pinSourceSymbol.offsetY = 20f
} catch (e: InterruptedException) {
e.printStackTrace()
} catch (e: ExecutionException) {
e.printStackTrace()
}
//[DocRef: END]
val endDrawable =
ContextCompat.getDrawable(this, R.drawable.ic_destination) as BitmapDrawable?
val pinDestinationSymbol: PictureMarkerSymbol
try {
pinDestinationSymbol = PictureMarkerSymbol.createAsync(endDrawable).get()
pinDestinationSymbol.loadAsync()
pinDestinationSymbol.addDoneLoadingListener {
//add a new graphic as end point
mDestinationPoint =
Point(-117.15557279683529, 32.703360305883045, SpatialReferences.getWgs84())
val destinationGraphic =
Graphic(mDestinationPoint, pinDestinationSymbol)
mGraphicsOverlay!!.getGraphics().add(destinationGraphic)
}
pinDestinationSymbol.offsetY = 20f
} catch (e: InterruptedException) {
e.printStackTrace()
} catch (e: ExecutionException) {
e.printStackTrace()
}
//[DocRef: END]
mRouteSymbol = SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 5F)
}

override fun onPause() {
super.onPause()
mapView.pause()
Expand All @@ -128,4 +208,8 @@ class MainActivity : AppCompatActivity() {
super.onDestroy()
mapView.dispose()
}



}

32 changes: 13 additions & 19 deletions app/src/main/java/com/example/yfind/SearchBuilding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ import com.esri.arcgisruntime.data.FeatureQueryResult
import com.esri.arcgisruntime.data.QueryParameters
import com.esri.arcgisruntime.data.ServiceFeatureTable
import java.util.*
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.widget.*
import com.esri.arcgisruntime.data.Feature
import com.esri.arcgisruntime.data.QueryParameters.*





class SearchBuilding : AppCompatActivity() {
companion object {
private val TAG: String = SearchBuilding::class.java.simpleName
Expand All @@ -32,10 +27,6 @@ class SearchBuilding : AppCompatActivity() {
ServiceFeatureTable(getString(R.string.buildings_url))
}

private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<*>
private lateinit var viewManager: RecyclerView.LayoutManager

private lateinit var results: MutableList<Feature>

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -74,7 +65,7 @@ class SearchBuilding : AppCompatActivity() {
future.addDoneListener {
try {
// call get on the future to get the result
val result = future.get()
val result = future.get().toList()
// check there are some results
val resultIterator = result.iterator()
print(result.toString())
Expand All @@ -87,16 +78,16 @@ class SearchBuilding : AppCompatActivity() {
val lv = findViewById<ListView>(R.id.list)
var arrayAdapter = ArrayAdapter<String>(this, R.layout.list_row, R.id.label, results)
lv.adapter = arrayAdapter

lv.setOnItemClickListener{ parent, view, position, id ->
val building = result[position].attributes["Acronym"].toString()
Log.d("building clicked : ", building + "position: " + position + "id: " + id)
// val building = arrayAdapter.getPosition(position.toString()) as String // The item that was clicked
val intent = Intent(this, SearchRoom::class.java)
intent.putExtra("acronym", building)
startActivity(intent)
}
}
// if (resultIterator.hasNext()) {
// resultIterator.next().run {
// // get the extent of the first feature in the result to zoom to
//// val envelope = geometry.extent
//// mapView.setViewpointGeometryAsync(envelope, 10.0)
//// // select the feature
// Log.d(TAG, attributes.toString())
// }
// }
else {
"No buildings found with name: $searchString".also {
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
Expand Down Expand Up @@ -144,3 +135,6 @@ class SearchBuilding : AppCompatActivity() {
}
}




Loading