2017-02-22 17:15:28 -08:00
|
|
|
package com.mapbox.reactnativemapboxgl;
|
|
|
|
|
|
|
|
|
|
import com.facebook.react.bridge.ReadableMap;
|
|
|
|
|
import com.facebook.react.uimanager.LayoutShadowNode;
|
|
|
|
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
|
|
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
|
|
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
|
|
|
import com.mapbox.mapboxsdk.geometry.LatLng;
|
|
|
|
|
|
2017-04-07 15:43:25 -07:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
2017-02-22 17:15:28 -08:00
|
|
|
public class RNMGLAnnotationViewManager extends ViewGroupManager<RNMGLAnnotationView> {
|
|
|
|
|
|
|
|
|
|
private static final String NAME = "RCTMapboxAnnotation";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected RNMGLAnnotationView createViewInstance(ThemedReactContext reactContext) {
|
2017-04-07 15:43:25 -07:00
|
|
|
return new RNMGLAnnotationView(reactContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Class<? extends LayoutShadowNode> getShadowNodeClass() {
|
|
|
|
|
return SizeReportingShadowNode.class;
|
2017-02-22 17:15:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public LayoutShadowNode createShadowNodeInstance() {
|
2017-04-07 15:43:25 -07:00
|
|
|
return new SizeReportingShadowNode();
|
2017-02-22 17:15:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Props
|
|
|
|
|
|
|
|
|
|
@ReactProp(name = "id")
|
|
|
|
|
public void setAnnotationId(RNMGLAnnotationView view, String value) {
|
|
|
|
|
view.setAnnotationId(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactProp(name = "coordinate")
|
|
|
|
|
public void setCoordinate(RNMGLAnnotationView view, ReadableMap map) {
|
|
|
|
|
LatLng coordinate = new LatLng();
|
|
|
|
|
coordinate.setLatitude(map.getDouble("latitude"));
|
|
|
|
|
coordinate.setLongitude(map.getDouble("longitude"));
|
|
|
|
|
view.setCoordinate(coordinate);
|
|
|
|
|
}
|
2017-04-07 15:43:25 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateExtraData(RNMGLAnnotationView view, Object extraData) {
|
|
|
|
|
// This is called from the {@link SizeReportingShadowNode}. We cache
|
|
|
|
|
// the width and height so that we can set the correct size on the marker
|
|
|
|
|
// view annotations in ReactNativeMapboxGLView RNMGLCustomMarkerViewAdapter.
|
|
|
|
|
HashMap<String, Float> data = (HashMap<String, Float>) extraData;
|
|
|
|
|
float width = data.get("width");
|
|
|
|
|
float height = data.get("height");
|
|
|
|
|
view.setLayoutDimensions(width, height);
|
|
|
|
|
}
|
2017-02-22 17:15:28 -08:00
|
|
|
}
|