Untitled
unknown
kotlin
3 years ago
2.2 kB
2
Indexable
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // authentication with an API key or named user is required to access basemaps and other // location services ArcGISRuntimeEnvironment.setApiKey(BuildConfig.API_KEY) // create a map with a topographic basemap val map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC) // set the map to be displayed in the layout's map view mapView.map = map // set an initial viewpoint on the map view mapView.setViewpoint(Viewpoint(34.056295, -117.195800, 100000.0)) mapView.onTouchListener = object : DefaultMapViewOnTouchListener(this, mapView) { override fun onSingleTapConfirmed(motionEvent: MotionEvent): Boolean { // get the point that was tapped on the screen val screenPoint = android.graphics.Point(motionEvent.x.roundToInt(), motionEvent.y.roundToInt()) // create a map point from that screen point val mapPoint = mapView.screenToLocation(screenPoint) // convert the point to WGS84 for obtaining lat/lon format val wgs84Point = GeometryEngine.project(mapPoint, SpatialReferences.getWgs84()) as Point // create a textview for the callout val calloutContent = TextView(applicationContext).apply { setTextColor(Color.BLACK) setSingleLine() // format coordinates to 4 decimal places and display lat long read out text = getString(R.string.callout_text, wgs84Point.y, wgs84Point.x) } // get the callout, set its content and show it and the tapped location mapView.callout.apply { location = mapPoint content = calloutContent show() } // center the map on the tapped location mapView.setViewpointCenterAsync(mapPoint) return true } } } override fun onResume() { super.onResume() mapView.resume() } override fun onPause() { mapView.pause() super.onPause() } override fun onDestroy() { mapView.dispose() super.onDestroy() } }
Editor is loading...