Commit 6b61e4b1 authored by Qiu Xiang's avatar Qiu Xiang

实现圆形绘制接口

parent 487e1f91
...@@ -22,6 +22,7 @@ class AMap3DPackage : ReactPackage { ...@@ -22,6 +22,7 @@ class AMap3DPackage : ReactPackage {
AMapOverlayManager(), AMapOverlayManager(),
AMapInfoWindowManager(), AMapInfoWindowManager(),
AMapPolylineManager(), AMapPolylineManager(),
AMapPolygonManager()) AMapPolygonManager(),
AMapCircleManager())
} }
} }
package cn.qiuxiang.react.amap3d
import android.graphics.Color
import com.amap.api.maps.AMap
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Circle
import com.amap.api.maps.model.CircleOptions
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.views.view.ReactViewGroup
class AMapCircle(context: ThemedReactContext) : ReactViewGroup(context) {
var circle: Circle? = null
private set
var center: LatLng? = null
set(value) {
field = value
circle?.center = value
}
var radius: Double = 0.0
set(value) {
field = value
circle?.radius = value
}
var strokeWidth: Float = 1f
set(value) {
field = value
circle?.strokeWidth = value
}
var strokeColor: Int = Color.BLACK
set(value) {
field = value
circle?.strokeColor = value
}
var fillColor: Int = Color.BLACK
set(value) {
field = value
circle?.fillColor = value
}
var zIndex: Float = 0f
set(value) {
field = value
circle?.zIndex = value
}
fun addToMap(map: AMap) {
circle = map.addCircle(CircleOptions()
.center(center)
.radius(radius)
.strokeColor(strokeColor)
.strokeWidth(strokeWidth)
.fillColor(fillColor)
.zIndex(zIndex))
}
}
package cn.qiuxiang.react.amap3d
import com.amap.api.maps.model.LatLng
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
@Suppress("unused")
internal class AMapCircleManager : ViewGroupManager<AMapCircle>() {
override fun getName(): String {
return "AMapCircle"
}
override fun createViewInstance(reactContext: ThemedReactContext): AMapCircle {
return AMapCircle(reactContext)
}
@ReactProp(name = "center")
fun setCoordinate(circle: AMapCircle, coordinate: ReadableMap) {
circle.center = LatLng(
coordinate.getDouble("latitude"),
coordinate.getDouble("longitude"))
}
@ReactProp(name = "radius")
fun setRadius(circle: AMapCircle, radius: Double) {
circle.radius = radius
}
@ReactProp(name = "fillColor", customType = "Color")
fun setFillColor(circle: AMapCircle, fillColor: Int) {
circle.fillColor = fillColor
}
@ReactProp(name = "strokeColor", customType = "Color")
fun setStrokeColor(circle: AMapCircle, strokeColor: Int) {
circle.strokeColor = strokeColor
}
@ReactProp(name = "strokeWidth")
fun setStrokeWidth(circle: AMapCircle, strokeWidth: Float) {
circle.strokeWidth = strokeWidth
}
@ReactProp(name = "zIndex")
fun setZIndex_(circle: AMapCircle, zIndex: Float) {
circle.zIndex = zIndex
}
}
...@@ -7,6 +7,7 @@ import com.facebook.react.uimanager.ThemedReactContext ...@@ -7,6 +7,7 @@ import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp import com.facebook.react.uimanager.annotations.ReactProp
@Suppress("unused")
internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() { internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
override fun getName(): String { override fun getName(): String {
return "AMapMarker" return "AMapMarker"
......
...@@ -18,6 +18,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) { ...@@ -18,6 +18,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
private val markers = HashMap<String, AMapMarker>() private val markers = HashMap<String, AMapMarker>()
private val polylines = HashMap<String, AMapPolyline>() private val polylines = HashMap<String, AMapPolyline>()
private val polygons = HashMap<String, AMapPolygon>() private val polygons = HashMap<String, AMapPolygon>()
private val circles = HashMap<String, AMapCircle>()
init { init {
super.onCreate(null) super.onCreate(null)
...@@ -102,6 +103,11 @@ class AMapView(context: ThemedReactContext) : MapView(context) { ...@@ -102,6 +103,11 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
polygons.put(polygon.polygon?.id!!, polygon) polygons.put(polygon.polygon?.id!!, polygon)
} }
fun addCircle(circle: AMapCircle) {
circle.addToMap(map)
circles.put(circle.circle?.id!!, circle)
}
fun emit(id: Int?, name: String, data: WritableMap = Arguments.createMap()) { fun emit(id: Int?, name: String, data: WritableMap = Arguments.createMap()) {
id?.let { eventEmitter.receiveEvent(it, name, data) } id?.let { eventEmitter.receiveEvent(it, name, data) }
} }
...@@ -120,6 +126,10 @@ class AMapView(context: ThemedReactContext) : MapView(context) { ...@@ -120,6 +126,10 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
polygons.remove(child.polygon?.id) polygons.remove(child.polygon?.id)
child.polygon?.remove() child.polygon?.remove()
} }
is AMapCircle -> {
polygons.remove(child.circle?.id)
child.circle?.remove()
}
} }
} }
......
...@@ -44,6 +44,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -44,6 +44,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
is AMapMarker -> mapView.addMarker(child) is AMapMarker -> mapView.addMarker(child)
is AMapPolyline -> mapView.addPolyline(child) is AMapPolyline -> mapView.addPolyline(child)
is AMapPolygon -> mapView.addPolygon(child) is AMapPolygon -> mapView.addPolygon(child)
is AMapCircle -> mapView.addCircle(child)
} }
} }
......
...@@ -10,6 +10,7 @@ import InfoWindow from './InfoWindow' ...@@ -10,6 +10,7 @@ import InfoWindow from './InfoWindow'
import Overlay from './Overlay' import Overlay from './Overlay'
import Polyline from './Polyline' import Polyline from './Polyline'
import Polygon from './Polygon' import Polygon from './Polygon'
import Circle from './Circle'
const CoordinatePropType = PropTypes.shape({ const CoordinatePropType = PropTypes.shape({
latitude: PropTypes.number.isRequired, latitude: PropTypes.number.isRequired,
...@@ -182,9 +183,10 @@ class MapView extends Component { ...@@ -182,9 +183,10 @@ class MapView extends Component {
static InfoWindow = InfoWindow static InfoWindow = InfoWindow
static Polyline = Polyline static Polyline = Polyline
static Polygon = Polygon static Polygon = Polygon
static Circle = Circle
} }
AMapView = requireNativeComponent('AMapView', MapView) AMapView = requireNativeComponent('AMapView', MapView)
export default MapView export default MapView
export {MapView, Marker, InfoWindow, Overlay, Polyline, Polygon} export {MapView, Marker, InfoWindow, Overlay, Polyline, Polygon, Circle}
...@@ -8,6 +8,7 @@ import Gestures from './examples/gestures' ...@@ -8,6 +8,7 @@ import Gestures from './examples/gestures'
import Marker from './examples/marker' import Marker from './examples/marker'
import Polyline from './examples/polyline' import Polyline from './examples/polyline'
import Polygon from './examples/polygon' import Polygon from './examples/polygon'
import Circle from './examples/circle'
export default StackNavigator({ export default StackNavigator({
Examples: {screen: Examples}, Examples: {screen: Examples},
...@@ -19,6 +20,7 @@ export default StackNavigator({ ...@@ -19,6 +20,7 @@ export default StackNavigator({
Marker: {screen: Marker}, Marker: {screen: Marker},
Polyline: {screen: Polyline}, Polyline: {screen: Polyline},
Polygon: {screen: Polygon}, Polygon: {screen: Polygon},
Circle: {screen: Circle},
}, { }, {
navigationOptions: { navigationOptions: {
headerTintColor: '#212121', headerTintColor: '#212121',
......
...@@ -48,6 +48,8 @@ export default class Examples extends Component { ...@@ -48,6 +48,8 @@ export default class Examples extends Component {
{this._renderItem('绘制折线', 'Polyline')} {this._renderItem('绘制折线', 'Polyline')}
<View style={styles.separator}/> <View style={styles.separator}/>
{this._renderItem('绘制多边形', 'Polygon')} {this._renderItem('绘制多边形', 'Polygon')}
<View style={styles.separator}/>
{this._renderItem('绘制圆形', 'Circle')}
</View> </View>
</ScrollView> </ScrollView>
} }
......
import React, {Component} from 'react'
import {StyleSheet} from 'react-native'
import {MapView, Circle} from 'react-native-amap3d'
export default class CircleExample extends Component {
static navigationOptions = {
title: '绘制圆形',
}
render() {
return <MapView style={StyleSheet.absoluteFill}>
<Circle
strokeWidth={5}
strokeColor='blue'
fillColor='red'
radius={10000}
center={{
latitude: 39.906901,
longitude: 116.397972,
}}/>
</MapView>
}
}
...@@ -9,6 +9,7 @@ export default class MapTypes extends Component { ...@@ -9,6 +9,7 @@ export default class MapTypes extends Component {
return { return {
title: '地图模式', title: '地图模式',
headerRight: <Picker headerRight: <Picker
mode='dropdown'
style={{width: 100}} style={{width: 100}}
selectedValue={state.params.mapType} selectedValue={state.params.mapType}
onValueChange={mapType => setParams({mapType})}> onValueChange={mapType => setParams({mapType})}>
......
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