use of com.mapbox.rctmgl.components.styles.sources.RCTSource in project maps by rnmapbox.
the class RCTMGLMapView method getTouchableSourceWithHighestZIndex.
private RCTSource getTouchableSourceWithHighestZIndex(List<RCTSource> sources) {
if (sources == null || sources.size() == 0) {
return null;
}
if (sources.size() == 1) {
return sources.get(0);
}
Map<String, RCTSource> layerToSourceMap = new HashMap<>();
for (RCTSource source : sources) {
String[] layerIDs = source.getLayerIDs();
for (String layerID : layerIDs) {
layerToSourceMap.put(layerID, source);
}
}
List<Layer> mapboxLayers = mMap.getStyle().getLayers();
for (int i = mapboxLayers.size() - 1; i >= 0; i--) {
Layer mapboxLayer = mapboxLayers.get(i);
String layerID = mapboxLayer.getId();
if (layerToSourceMap.containsKey(layerID)) {
return layerToSourceMap.get(layerID);
}
}
return null;
}
use of com.mapbox.rctmgl.components.styles.sources.RCTSource in project maps by rnmapbox.
the class RCTMGLMapView method addFeature.
public void addFeature(View childView, int childPosition) {
AbstractMapFeature feature = null;
if (childView instanceof RCTSource) {
RCTSource source = (RCTSource) childView;
mSources.put(source.getID(), source);
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLImages) {
RCTMGLImages images = (RCTMGLImages) childView;
mImages.add(images);
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLLight) {
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLNativeUserLocation) {
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLPointAnnotation) {
RCTMGLPointAnnotation annotation = (RCTMGLPointAnnotation) childView;
mPointAnnotations.put(annotation.getID(), annotation);
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLMarkerView) {
RCTMGLMarkerView marker = (RCTMGLMarkerView) childView;
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTMGLCamera) {
mCamera = (RCTMGLCamera) childView;
feature = (AbstractMapFeature) childView;
} else if (childView instanceof RCTLayer) {
feature = (RCTLayer) childView;
} else if (childView instanceof ViewGroup) {
ViewGroup children = (ViewGroup) childView;
for (int i = 0; i < children.getChildCount(); i++) {
addFeature(children.getChildAt(i), childPosition);
}
}
if (feature != null) {
if (mQueuedFeatures == null) {
feature.addToMap(this);
mFeatures.add(childPosition, feature);
} else {
mQueuedFeatures.add(childPosition, feature);
}
}
}
use of com.mapbox.rctmgl.components.styles.sources.RCTSource in project maps by rnmapbox.
the class RCTMGLMapView method onMapClick.
@Override
public boolean onMapClick(@NonNull LatLng point) {
if (mAnnotationClicked) {
mAnnotationClicked = false;
return true;
}
PointF screenPoint = mMap.getProjection().toScreenLocation(point);
List<RCTSource> touchableSources = getAllTouchableSources();
Map<String, List<Feature>> hits = new HashMap<>();
List<RCTSource> hitTouchableSources = new ArrayList<>();
for (RCTSource touchableSource : touchableSources) {
Map<String, Double> hitbox = touchableSource.getTouchHitbox();
if (hitbox == null) {
continue;
}
float halfWidth = hitbox.get("width").floatValue() / 2.0f;
float halfHeight = hitbox.get("height").floatValue() / 2.0f;
RectF hitboxF = new RectF();
hitboxF.set(screenPoint.x - halfWidth, screenPoint.y - halfHeight, screenPoint.x + halfWidth, screenPoint.y + halfHeight);
List<Feature> features = mMap.queryRenderedFeatures(hitboxF, touchableSource.getLayerIDs());
if (features.size() > 0) {
hits.put(touchableSource.getID(), features);
hitTouchableSources.add(touchableSource);
}
}
if (hits.size() > 0) {
RCTSource source = getTouchableSourceWithHighestZIndex(hitTouchableSources);
if (source != null && source.hasPressListener()) {
source.onPress(new RCTSource.OnPressEvent(hits.get(source.getID()), point, screenPoint));
return true;
}
}
MapClickEvent event = new MapClickEvent(this, point, screenPoint);
mManager.handleEvent(event);
return false;
}
use of com.mapbox.rctmgl.components.styles.sources.RCTSource in project maps by rnmapbox.
the class RCTMGLMapView method onMapClick.
@Override
public boolean onMapClick(@NonNull Point point) {
RCTMGLMapView _this = this;
/*if (mPointAnnotationManager != nil) {
getAnnotations()
}*/
if (mAnnotationClicked) {
mAnnotationClicked = false;
return true;
}
ScreenCoordinate screenPoint = mMap.pixelForCoordinate(point);
List<RCTSource> touchableSources = getAllTouchableSources();
HashMap<String, List<Feature>> hits = new HashMap<>();
handleTapInSources(new LinkedList<>(touchableSources), screenPoint, hits, new ArrayList<>(), new HandleTap() {
@Override
public void run(List<RCTSource> hitTouchableSources, Map<String, List<Feature>> hits) {
if (hits.size() > 0) {
RCTSource source = getTouchableSourceWithHighestZIndex(hitTouchableSources);
if (source != null && source.hasPressListener()) {
source.onPress(new RCTSource.OnPressEvent(hits.get(source.getID()), GeoJSONUtils.toLatLng(point), new PointF((float) screenPoint.getX(), (float) screenPoint.getY())));
return;
}
}
MapClickEvent event = new MapClickEvent(_this, new LatLng(point), screenPoint);
mManager.handleEvent(event);
}
});
return false;
}
use of com.mapbox.rctmgl.components.styles.sources.RCTSource in project maps by rnmapbox.
the class RCTMGLMapView method handleTapInSources.
void handleTapInSources(LinkedList<RCTSource> sources, ScreenCoordinate screenPoint, HashMap<String, List<Feature>> hits, ArrayList<RCTSource> hitTouchableSources, HandleTap handleTap) {
if (sources.isEmpty()) {
handleTap.run(hitTouchableSources, hits);
return;
}
RCTSource source = sources.removeFirst();
Map<String, Double> hitbox = source.getTouchHitbox();
if (hitbox != null) {
double halfWidth = hitbox.get("width").floatValue() / 2.0f;
double halfHeight = hitbox.get("height").floatValue() / 2.0f;
ScreenBox screenBox = new ScreenBox(new ScreenCoordinate(screenPoint.getX() - halfWidth, screenPoint.getY() - halfHeight), new ScreenCoordinate(screenPoint.getX() + halfWidth, screenPoint.getY() + halfHeight));
getMapboxMap().queryRenderedFeatures(screenBox, new RenderedQueryOptions(source.getLayerIDs(), null), new QueryFeaturesCallback() {
@Override
public void run(@NonNull Expected<String, List<QueriedFeature>> features) {
HashMap<String, List<Feature>> newHits = hits;
if (features.isValue()) {
if (features.getValue().size() > 0) {
ArrayList<Feature> featuresList = new ArrayList<>();
for (QueriedFeature i : features.getValue()) {
featuresList.add(i.getFeature());
}
newHits.put(source.getID(), featuresList);
hitTouchableSources.add(source);
}
} else {
Logger.e("handleTapInSources", features.getError());
}
handleTapInSources(sources, screenPoint, newHits, hitTouchableSources, handleTap);
}
});
}
}
Aggregations