Commit 295ceaf9 authored by Qiu Xiang's avatar Qiu Xiang

android 新增 Marker#anchor 接口

相关: #65
parent 3e818a4a
...@@ -26,6 +26,8 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -26,6 +26,8 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
private var icon: View? = null private var icon: View? = null
private var bitmapDescriptor: BitmapDescriptor? = null private var bitmapDescriptor: BitmapDescriptor? = null
private var anchorU: Float = 0.5f
private var anchorV: Float = 1f
var infoWindow: AMapInfoWindow? = null var infoWindow: AMapInfoWindow? = null
var infoWindowEnabled: Boolean = true var infoWindowEnabled: Boolean = true
...@@ -108,6 +110,7 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -108,6 +110,7 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
.alpha(opacity) .alpha(opacity)
.draggable(draggable) .draggable(draggable)
.position(position) .position(position)
.anchor(anchorU, anchorV)
.title(title) .title(title)
.infoWindowEnable(infoWindowEnabled) .infoWindowEnable(infoWindowEnabled)
.snippet(snippet) .snippet(snippet)
...@@ -148,4 +151,10 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -148,4 +151,10 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
bitmapDescriptor = BitmapDescriptorFactory.fromResource(drawable) bitmapDescriptor = BitmapDescriptorFactory.fromResource(drawable)
marker?.setIcon(bitmapDescriptor) marker?.setIcon(bitmapDescriptor)
} }
fun setAnchor(x: Double, y: Double) {
anchorU = x.toFloat()
anchorV = y.toFloat()
marker?.setAnchor(anchorU, anchorV)
}
} }
...@@ -110,4 +110,11 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() { ...@@ -110,4 +110,11 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
fun setZInex(marker: AMapMarker, zIndex: Float) { fun setZInex(marker: AMapMarker, zIndex: Float) {
marker.zIndex = zIndex marker.zIndex = zIndex
} }
@ReactProp(name = "anchor")
fun setAnchor(view: AMapMarker, coordinate: ReadableMap) {
view.setAnchor(
coordinate.getDouble("x"),
coordinate.getDouble("y"))
}
} }
...@@ -12,5 +12,10 @@ const Region = PropTypes.shape({ ...@@ -12,5 +12,10 @@ const Region = PropTypes.shape({
longitudeDelta: PropTypes.number.isRequired, longitudeDelta: PropTypes.number.isRequired,
}) })
export {LatLng, Region} const Point = PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
})
export {LatLng, Region, Point}
import React, {PropTypes} from 'react' import React, {PropTypes} from 'react'
import {Platform, requireNativeComponent, StyleSheet, View, ViewPropTypes} from 'react-native' import {Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View} from 'react-native'
import InfoWindow from './InfoWindow' import InfoWindow from './InfoWindow'
import {LatLng} from '../PropTypes' import {LatLng, Point} from '../PropTypes'
import BaseComponent from '../BaseComponent' import BaseComponent from '../BaseComponent'
export default class Marker extends BaseComponent { export default class Marker extends BaseComponent {
...@@ -81,6 +81,14 @@ export default class Marker extends BaseComponent { ...@@ -81,6 +81,14 @@ export default class Marker extends BaseComponent {
*/ */
zIndex: PropTypes.number, zIndex: PropTypes.number,
/**
* 设置覆盖物的锚点比例
*
* @link http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/Marker.html#setAnchor-float-float-
* @platform android
*/
anchor: Point,
/** /**
* 是否选中,选中时将显示信息窗体,一个地图只能有一个正在选中的 marker * 是否选中,选中时将显示信息窗体,一个地图只能有一个正在选中的 marker
*/ */
......
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