package expo.modules.gaodemap.map import expo.modules.kotlin.modules.Module import expo.modules.kotlin.modules.ModuleDefinition /** * 高德地图视图 Module */ class ExpoGaodeMapViewModule : Module() { override fun definition() = ModuleDefinition { Name("ExpoGaodeMapView") View(ExpoGaodeMapView::class) { Events("onMapPress", "onPressPoi", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle") // 延迟销毁地图,避免页面退出动画未完成时地图就变成白屏 OnViewDestroys { view: ExpoGaodeMapView -> // 延迟 500ms 销毁地图,让页面退出动画先完成 android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({ view.onDestroy() }, 500) } Prop("mapType") { view, type -> view.mapType = type view.setMapType(type) } Prop?>("initialCameraPosition") { view, position -> view.initialCameraPosition = position position?.let { view.setInitialCameraPosition(it) } } Prop("zoomControlsEnabled") { view, show -> view.setShowsZoomControls(show) } Prop("compassEnabled") { view, show -> view.setShowsCompass(show) } Prop("scaleControlsEnabled") { view, show -> view.setShowsScale(show) } Prop("zoomGesturesEnabled") { view, enabled -> view.setZoomEnabled(enabled) } Prop("scrollGesturesEnabled") { view, enabled -> view.setScrollEnabled(enabled) } Prop("rotateGesturesEnabled") { view, enabled -> view.setRotateEnabled(enabled) } Prop("tiltGesturesEnabled") { view, enabled -> view.setTiltEnabled(enabled) } Prop("maxZoom") { view, maxZoom -> view.setMaxZoom(maxZoom) } Prop("minZoom") { view, minZoom -> view.setMinZoom(minZoom) } Prop("followUserLocation") { view, follow -> view.setFollowUserLocation(follow) } Prop("myLocationEnabled") { view, show -> view.setShowsUserLocation(show) } Prop?>("userLocationRepresentation") { view, representation -> representation?.let { view.setUserLocationRepresentation(it) } } Prop("trafficEnabled") { view, show -> view.setShowsTraffic(show) } Prop("buildingsEnabled") { view, show -> view.setShowsBuildings(show) } Prop("indoorViewEnabled") { view, show -> view.setShowsIndoorMap(show) } Prop("labelsEnabled") { view, enabled -> view.setLabelsEnabled(enabled) } Prop("myLocationButtonEnabled") { view, enabled -> view.setMyLocationButtonEnabled(enabled) } Prop("cameraEventThrottleMs") { view, throttleMs -> view.setCameraEventThrottleMs(throttleMs) } Prop?>("customMapStyle") { view, styleData -> styleData?.let { view.setCustomMapStyle(it) } } OnViewDidUpdateProps { view: ExpoGaodeMapView -> if (view.mapType != 1) { view.setMapType(view.mapType) } view.initialCameraPosition?.let { position -> view.setInitialCameraPosition(position) } } AsyncFunction("moveCamera") { view: ExpoGaodeMapView, position: Map, duration: Int -> view.moveCamera(position, duration) } AsyncFunction("getLatLng") { view: ExpoGaodeMapView, point: Map -> view.getLatLng(point) } AsyncFunction("takeSnapshot") { view: ExpoGaodeMapView, promise: expo.modules.kotlin.Promise -> view.takeSnapshot(promise) } AsyncFunction("setCenter") { view: ExpoGaodeMapView, center: Map, animated: Boolean -> view.setCenter(center, animated) } AsyncFunction("setZoom") { view: ExpoGaodeMapView, zoom: Double, animated: Boolean -> view.setZoomLevel(zoom.toFloat(), animated) } AsyncFunction("getCameraPosition") { view: ExpoGaodeMapView -> view.getCameraPosition() } } } }