use of com.mapbox.rctmgl.events.MapClickEvent 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.events.MapClickEvent 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.events.MapClickEvent in project maps by rnmapbox.
the class RCTMGLMapView method onMapLongClick.
@Override
public boolean onMapLongClick(@NonNull LatLng point) {
if (mAnnotationClicked) {
mAnnotationClicked = false;
return true;
}
PointF screenPoint = mMap.getProjection().toScreenLocation(point);
MapClickEvent event = new MapClickEvent(this, point, screenPoint, EventTypes.MAP_LONG_CLICK);
mManager.handleEvent(event);
return false;
}
Aggregations