Commit 949816bb authored by Qiu Xiang's avatar Qiu Xiang

优化 Overlay 的实现方式

parent 3c5fe80e
...@@ -113,18 +113,18 @@ import MapView from 'react-native-amap3d' ...@@ -113,18 +113,18 @@ import MapView from 'react-native-amap3d'
```jsx ```jsx
<Marker <Marker
icon={() => icon={() =>
<Overlay style={styles.customMarker}> <View style={styles.customMarker}>
<Image style={styles.customIcon} source={require('marker.png')}/> <Image style={styles.customIcon} source={require('marker.png')}/>
</Overlay> </View>
} }
coordinate={{ coordinate={{
latitude: 39.706901, latitude: 39.706901,
longitude: 116.397972, longitude: 116.397972,
}} }}
> >
<InfoWindow style={styles.customInfoWindow}> <View style={styles.customInfoWindow}>
<Text>自定义信息窗体</Text> <Text>自定义信息窗体</Text>
</InfoWindow> </View>
</Marker> </Marker>
``` ```
...@@ -157,7 +157,7 @@ import MapView from 'react-native-amap3d' ...@@ -157,7 +157,7 @@ import MapView from 'react-native-amap3d'
- [x] 手势交互(平移、缩放、旋转、倾斜) - [x] 手势交互(平移、缩放、旋转、倾斜)
- [x] 中心坐标、缩放级别、倾斜度 - [x] 中心坐标、缩放级别、倾斜度
- [x] 地图事件(onPress、onLongPress、onLocation) - [x] 地图事件(onPress、onLongPress、onLocation)
- [ ] 地图标记(Marker) - [x] 地图标记(Marker)
- [x] 基本属性及事件 - [x] 基本属性及事件
- [x] 自定义信息窗体 - [x] 自定义信息窗体
- [x] 自定义图标 - [x] 自定义图标
......
...@@ -20,7 +20,6 @@ class AMap3DPackage : ReactPackage { ...@@ -20,7 +20,6 @@ class AMap3DPackage : ReactPackage {
AMapViewManager(), AMapViewManager(),
AMapMarkerManager(), AMapMarkerManager(),
AMapOverlayManager(), AMapOverlayManager(),
AMapInfoWindowManager(),
AMapPolylineManager(), AMapPolylineManager(),
AMapPolygonManager(), AMapPolygonManager(),
AMapCircleManager()) AMapCircleManager())
......
package cn.qiuxiang.react.amap3d
import android.content.Context
import com.facebook.react.views.view.ReactViewGroup
class AMapInfoWindow(context: Context) : ReactViewGroup(context)
package cn.qiuxiang.react.amap3d
import android.view.ViewGroup.LayoutParams
import com.facebook.react.uimanager.LayoutShadowNode
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
class AMapInfoWindowManager : ViewGroupManager<AMapInfoWindow>() {
override fun getName(): String {
return "AMapInfoWindow"
}
override fun createViewInstance(reactContext: ThemedReactContext): AMapInfoWindow {
return AMapInfoWindow(reactContext)
}
override fun createShadowNodeInstance(): LayoutShadowNode {
return LayoutNode()
}
override fun updateExtraData(infoWindow: AMapInfoWindow, extraData: Any) {
val data = extraData as LayoutNode.Layout
infoWindow.layoutParams = LayoutParams(data.width, data.height)
}
}
...@@ -23,7 +23,7 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -23,7 +23,7 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
) )
} }
var infoWindow: ReactViewGroup? = null var infoWindow: AMapOverlay? = null
var infoWindowEnabled: Boolean = true var infoWindowEnabled: Boolean = true
var marker: Marker? = null var marker: Marker? = null
......
...@@ -18,9 +18,11 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() { ...@@ -18,9 +18,11 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
} }
override fun addView(marker: AMapMarker, view: View, index: Int) { override fun addView(marker: AMapMarker, view: View, index: Int) {
when (view) { if (view is AMapOverlay) {
is AMapInfoWindow -> marker.infoWindow = view when(index) {
is AMapOverlay -> marker.setIconView(view) 0 -> marker.setIconView(view)
1 -> marker.infoWindow = view
}
} }
} }
......
...@@ -85,7 +85,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) { ...@@ -85,7 +85,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
emit(polylines[polyline.id]?.id, "onPolylineClick") emit(polylines[polyline.id]?.id, "onPolylineClick")
} }
map.setInfoWindowAdapter(AMapInfoWindowAdapter(context, markers)) map.setInfoWindowAdapter(InfoWindowAdapter(context, markers))
} }
fun addMarker(marker: AMapMarker) { fun addMarker(marker: AMapMarker) {
......
...@@ -8,7 +8,7 @@ import android.widget.TextView ...@@ -8,7 +8,7 @@ import android.widget.TextView
import com.amap.api.maps.AMap import com.amap.api.maps.AMap
import com.amap.api.maps.model.Marker import com.amap.api.maps.model.Marker
class AMapInfoWindowAdapter( class InfoWindowAdapter(
val context: Context, val context: Context,
val markers: HashMap<String, AMapMarker> val markers: HashMap<String, AMapMarker>
) : AMap.InfoWindowAdapter { ) : AMap.InfoWindowAdapter {
......
import React, {PropTypes, Component} from 'react'
import {requireNativeComponent, View} from 'react-native'
class InfoWindow extends Component {
static propTypes = {
...View.propTypes,
}
render() {
return <AMapInfoWindow {...this.props}/>
}
}
AMapInfoWindow = requireNativeComponent('AMapInfoWindow', InfoWindow)
export default InfoWindow
...@@ -34,7 +34,7 @@ export default class Examples extends Component { ...@@ -34,7 +34,7 @@ export default class Examples extends Component {
<View style={styles.group}> <View style={styles.group}>
{this._renderItem('地图模式', 'MapTypes')} {this._renderItem('地图模式', 'MapTypes')}
<View style={styles.separator}/> <View style={styles.separator}/>
{this._renderItem('图层功能', 'Layers')} {this._renderItem('基本图层', 'Layers')}
<View style={styles.separator}/> <View style={styles.separator}/>
{this._renderItem('室内地图', 'Indoor')} {this._renderItem('室内地图', 'Indoor')}
<View style={styles.separator}/> <View style={styles.separator}/>
......
import React, {Component} from 'react' import React, {Component} from 'react'
import {StyleSheet, Alert, Text, Image} from 'react-native' import {StyleSheet, Alert, Text, Image, View} from 'react-native'
import {MapView, Marker, InfoWindow, Overlay} from 'react-native-amap3d' import {MapView, Marker} from 'react-native-amap3d'
export default class MarkerExample extends Component { export default class MarkerExample extends Component {
static navigationOptions = { static navigationOptions = {
...@@ -45,15 +45,15 @@ export default class MarkerExample extends Component { ...@@ -45,15 +45,15 @@ export default class MarkerExample extends Component {
latitude: 39.806901, latitude: 39.806901,
longitude: 116.297972, longitude: 116.297972,
}}> }}>
<InfoWindow style={styles.customInfoWindow}> <View style={styles.customInfoWindow}>
<Text>Custom View InfoWindow</Text> <Text>Custom View InfoWindow</Text>
</InfoWindow> </View>
</Marker> </Marker>
<Marker <Marker
icon={() => icon={() =>
<Overlay style={styles.customIcon}> <View style={styles.customIcon}>
<Image style={styles.customIcon} source={require('../../images/marker.png')}/> <Image style={styles.customIcon} source={require('../../images/marker.png')}/>
</Overlay> </View>
} }
title='自定义图片' title='自定义图片'
description="Note the use of nativeOnly above. Sometimes you'll have some special properties that you need to expose for the native component, but don't actually want them as part of the API for the associated React component." description="Note the use of nativeOnly above. Sometimes you'll have some special properties that you need to expose for the native component, but don't actually want them as part of the API for the associated React component."
...@@ -65,9 +65,9 @@ export default class MarkerExample extends Component { ...@@ -65,9 +65,9 @@ export default class MarkerExample extends Component {
<Marker <Marker
title='Custom View Marker' title='Custom View Marker'
icon={() => icon={() =>
<Overlay style={styles.customMarker}> <View style={styles.customMarker}>
<Text style={styles.markerText}>{this.state.time.toLocaleTimeString()}</Text> <Text style={styles.markerText}>{this.state.time.toLocaleTimeString()}</Text>
</Overlay> </View>
} }
coordinate={{ coordinate={{
latitude: 39.706901, latitude: 39.706901,
...@@ -85,7 +85,6 @@ const styles = StyleSheet.create({ ...@@ -85,7 +85,6 @@ const styles = StyleSheet.create({
}, },
customInfoWindow: { customInfoWindow: {
backgroundColor: '#8bc34a', backgroundColor: '#8bc34a',
position: 'absolute',
padding: 10, padding: 10,
borderRadius: 10, borderRadius: 10,
elevation: 4, elevation: 4,
...@@ -93,7 +92,6 @@ const styles = StyleSheet.create({ ...@@ -93,7 +92,6 @@ const styles = StyleSheet.create({
borderColor: '#689F38', borderColor: '#689F38',
}, },
customMarker: { customMarker: {
position: 'absolute',
backgroundColor: '#009688', backgroundColor: '#009688',
alignItems: 'center', alignItems: 'center',
borderRadius: 5, borderRadius: 5,
......
...@@ -85,12 +85,16 @@ ...@@ -85,12 +85,16 @@
- (void)insertReactSubview:(id <RCTComponent>)subview atIndex:(NSInteger)atIndex { - (void)insertReactSubview:(id <RCTComponent>)subview atIndex:(NSInteger)atIndex {
if ([subview isKindOfClass:[AMapOverlay class]]) { if ([subview isKindOfClass:[AMapOverlay class]]) {
if (atIndex == 0) {
_overlay = (AMapOverlay *) subview; _overlay = (AMapOverlay *) subview;
_overlay.delegate = self; _overlay.delegate = self;
_annotationView.image = nil; _annotationView.image = nil;
} else { }
if (atIndex == 1) {
// TODO: customCalloutView 的位置不太对
_annotationView.customCalloutView = [[MACustomCalloutView alloc] initWithCustomView:(id) subview]; _annotationView.customCalloutView = [[MACustomCalloutView alloc] initWithCustomView:(id) subview];
} }
}
} }
#pragma mark AMapOverlayDelegate #pragma mark AMapOverlayDelegate
......
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