Commit 22538e45 authored by Qiu Xiang's avatar Qiu Xiang

优化代码

parent c181df86
...@@ -81,19 +81,7 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -81,19 +81,7 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
private val eventEmitter: RCTEventEmitter = context.getJSModule(RCTEventEmitter::class.java) private val eventEmitter: RCTEventEmitter = context.getJSModule(RCTEventEmitter::class.java)
fun addToMap(map: AMap) { fun addToMap(map: AMap) {
marker = map.addMarker(markerOptions) marker = map.addMarker(MarkerOptions()
if (active) {
marker?.showInfoWindow()
} else {
marker?.hideInfoWindow()
}
}
val markerId: String?
get() = marker?.id
private val markerOptions: MarkerOptions
get() = MarkerOptions()
.setFlat(flat) .setFlat(flat)
.icon(bitmapDescriptor) .icon(bitmapDescriptor)
.alpha(opacity) .alpha(opacity)
...@@ -101,7 +89,14 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -101,7 +89,14 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
.position(position) .position(position)
.title(title) .title(title)
.infoWindowEnable(infoWindowEnabled) .infoWindowEnable(infoWindowEnabled)
.snippet(snippet) .snippet(snippet))
if (active) {
marker?.showInfoWindow()
} else {
marker?.hideInfoWindow()
}
}
fun setIcon(icon: String) { fun setIcon(icon: String) {
bitmapDescriptor = COLORS[icon.toUpperCase()]?.let { bitmapDescriptor = COLORS[icon.toUpperCase()]?.let {
......
...@@ -84,7 +84,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) { ...@@ -84,7 +84,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
fun addMarker(marker: AMapMarker) { fun addMarker(marker: AMapMarker) {
marker.addToMap(map) marker.addToMap(map)
markers.put(marker.markerId!!, marker) markers.put(marker.marker?.id!!, marker)
} }
fun addPolyline(polyline: AMapPolyline) { fun addPolyline(polyline: AMapPolyline) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment