use of com.mapbox.maps.QueriedFeature in project maps by rnmapbox.
the class RCTMGLRasterDemSource method querySourceFeatures.
public void querySourceFeatures(String callbackID, @Size(min = 1) List<String> layerIDs, @Nullable Expression filter) {
if (mSource == null) {
WritableMap payload = new WritableNativeMap();
payload.putString("error", "source is not yet loaded");
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
mManager.handleEvent(event);
return;
}
WritableMap payload = new WritableNativeMap();
mMap.querySourceFeatures(mID, new SourceQueryOptions(layerIDs, filter), new QueryFeaturesCallback() {
@Override
public void run(@NonNull Expected<String, List<QueriedFeature>> queriedFeatures) {
if (queriedFeatures.isError()) {
// V10todo
payload.putString("error", queriedFeatures.getError());
} else {
List<Feature> features = new LinkedList<>();
for (QueriedFeature feature : queriedFeatures.getValue()) {
features.add(feature.getFeature());
}
payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
}
}
});
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
mManager.handleEvent(event);
}
use of com.mapbox.maps.QueriedFeature in project maps by rnmapbox.
the class RCTMGLShapeSource method getClusterExpansionZoom.
public void getClusterExpansionZoom(String callbackID, int clusterId) {
if (mSource == null) {
WritableMap payload = new WritableNativeMap();
payload.putString("error", "source is not yet loaded");
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
mManager.handleEvent(event);
return;
}
SourceQueryOptions options = new SourceQueryOptions(null, Expression.eq(Expression.get("cluster_id"), Expression.literal(clusterId)));
RCTMGLShapeSource _this = this;
mMap.querySourceFeatures(getID(), options, new QueryFeaturesCallback() {
@Override
public void run(@NonNull Expected<String, List<QueriedFeature>> features) {
if (features.isValue()) {
QueriedFeature cluster = features.getValue().get(0);
mMap.queryFeatureExtensions(getID(), cluster.getFeature(), "supercluster", "expansion-zoom", null, new QueryFeatureExtensionCallback() {
@Override
public void run(@NonNull Expected<String, FeatureExtensionValue> extension) {
if (extension.isValue()) {
Object contents = extension.getValue().getValue().getContents();
if (contents instanceof Long) {
WritableMap payload = new WritableNativeMap();
payload.putInt("data", ((Long) contents).intValue());
AndroidCallbackEvent event = new AndroidCallbackEvent(_this, callbackID, payload);
mManager.handleEvent(event);
return;
} else {
callbackError(callbackID, "Not a number", "getClusterExpansionZoom/queryFeatureExtensions2");
return;
}
} else {
callbackError(callbackID, extension.getError(), "getClusterExpansionZoom/queryFeatureExtensions");
return;
}
}
});
} else {
callbackError(callbackID, features.getError(), "getClusterExpansionZoom/querySourceFeatures");
return;
}
}
});
}
use of com.mapbox.maps.QueriedFeature 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