package com.rtnmapsgl.interop import android.webkit.JavascriptInterface import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.events.RCTEventEmitter import com.facebook.react.uimanager.annotations.ReactProp; import com.rtnmapsgl.MainViewModel /* * Description: Javascript events * Javascript -> Kotlin events interOp */ class WebAppInterface( private val viewModel: MainViewModel, private val jsBuilder: JSBuilder? = null, private val reactContext: ReactApplicationContext, private val reactNativeViewId: Int ) { val TAG = "WebAppInterface" /* * Debugging - Echo(Log) and Error */ @JavascriptInterface fun onError(err: String) { /* All html / javascript error comes here */ android.util.Log.d(TAG, "CONNOR - onError:$err") } @JavascriptInterface fun echo(msg: String) { android.util.Log.d(TAG, "CONNOR - echo:$msg") // use this to debug } /* * Configuration */ @JavascriptInterface fun onWindowReady() { viewModel.setWebViewReady(true) android.util.Log.d(TAG, "CONNOR - onWindowReady") } @JavascriptInterface fun onCtrlLoadStart() { // android.util.Log.d(TAG, "CONNOR - onCtrlLoadStart") } @JavascriptInterface fun onCtrlLoadComplete() { // android.util.Log.d(TAG, "CONNOR - onCtrlLoadComplete") } /* * React Native Callbacks */ /* * Core */ @JavascriptInterface fun getCenter(lat: Float, lon: Float) { /* response */ android.util.Log.d(TAG, "getCenter lat:$lat lon:$lon") } @JavascriptInterface fun getZoom(zoom: Int) { /* response (1,2,3...) */ android.util.Log.d(TAG, "getZoom zoom:$zoom") } @JavascriptInterface fun getBounds(east: Float, west: Float, north: Float, south: Float) { android.util.Log.d(TAG, "getBounds east:$east west:$west north:$north south:$south") } @JavascriptInterface fun getBearing(value: Int) { android.util.Log.d(TAG, "getBearing bearing:$value") } @JavascriptInterface fun getPitch(value: Int) { android.util.Log.d(TAG, "getPitch pitch:$value") } @JavascriptInterface fun getFov(value: Float) { android.util.Log.d(TAG, "getFov fov:$value") } @JavascriptInterface fun onMapClick(x: Int, y: Int, height: Int, width: Int, lat: Float, lon: Float) { /* return x,y points */ android.util.Log.d( TAG, "onMapClick x:$x y:$y height:$height width:$width lat:$lat lon:$lon" ) } @JavascriptInterface fun onCtrlMapClick(feature: String) { android.util.Log.d(TAG, "onCtrlMapClick feature:$feature") } @JavascriptInterface fun onCtrlZoom() { android.util.Log.d(TAG, "onCtrlZoom") } @JavascriptInterface fun onCtrlMove() { // android.util.Log.d(TAG, "onCtrlMove") } @JavascriptInterface fun onMoveEnd(mapView: String) { val event = Arguments.createMap().apply { putString("mapView", mapView) } reactContext.getJSModule(RCTEventEmitter::class.java) .receiveEvent(reactNativeViewId, "onMapsglViewDidMove", event) } @JavascriptInterface fun onSelectWaterbody(waterbody: String) { android.util.Log.d(TAG, "CONNOR - onSelectWaterbody: $waterbody") val event = Arguments.createMap().apply { putString("waterbody", waterbody) } reactContext.getJSModule(RCTEventEmitter::class.java) .receiveEvent(reactNativeViewId, "onSelectWaterbody", event) } @JavascriptInterface fun onCtrlAddSource() { android.util.Log.d(TAG, "onCtrlAddSource") } @JavascriptInterface fun onCtrlAddLayer() { android.util.Log.d(TAG, "onCtrlAddLayer") // jsBuilder?.getLegend() } @JavascriptInterface fun onCtrlRemoveSource() { android.util.Log.d(TAG, "onCtrlRemoveSource") } @JavascriptInterface fun onCtrlRemoveLayer() { android.util.Log.d(TAG, "onCtrlRemoveLayer") // jsBuilder?.getLegend() } @JavascriptInterface fun onCtrlHasLayer(hasLayer: Boolean) { android.util.Log.d(TAG, "onCtrlHasLayer:$hasLayer") } @JavascriptInterface fun onQueryResult(data: String) { android.util.Log.d(TAG, "query:$data") } /* *timeline */ @JavascriptInterface fun getStartDate(time: String) { android.util.Log.d(TAG, "getStartDate:$time") } @JavascriptInterface fun getEndDate(time: String) { android.util.Log.d(TAG, "getEndDate:$time") } @JavascriptInterface fun getCurrentDate(time: String) { android.util.Log.d(TAG, "getCurrentDate:$time") } /* * animation */ @JavascriptInterface fun onAnimationStart() { android.util.Log.d(TAG, "onAnimationStart") } @JavascriptInterface fun onAnimationStop() { android.util.Log.d(TAG, "onAnimationStop") } @JavascriptInterface fun onAnimationPause() { android.util.Log.d(TAG, "onAnimationPause") } @JavascriptInterface fun onAnimationResume() { android.util.Log.d(TAG, "onAnimationResume") } @JavascriptInterface fun onAnimationAdvance(position: String, date: String) { android.util.Log.d(TAG, "onAnimationAdvance position:$position date:$date") } }