Orb*_*bit 11 android mapbox mapbox-android
使用以下代码将各种行添加到表示路径的地图中:
private LineLayer makeLineLayer(List<GeoPoint> routePoints, String title) {
String sourceTitle = "line-layer-" + lineCount;
List<Position> points = new ArrayList<>(routePoints.size());
List<Feature> routes = new ArrayList<>(routePoints.size());
for (GeoPoint point : routePoints) {
points.add(Position.fromCoordinates(point.getLongitude(), point.getLatitude()));
}
LineString route = LineString.fromCoordinates(points);
Feature routeFeature = Feature.fromGeometry(route);
routeFeature.addStringProperty("custom-line", "0");
routes.add(routeFeature);
GeoJsonSource linesSource = new GeoJsonSource(
sourceTitle,
FeatureCollection.fromFeatures(routes));
mapboxMap.addSource(linesSource);
LineLayer lineLayer = new LineLayer(title, sourceTitle);
lineLayer.setProperties(
//Sets properties...
);
return lineLayer;
}
LineLayer lineLayer = makeLineLayer(getRoutePoints());
mapboxMap.addLayer(lineLayer);
Run Code Online (Sandbox Code Playgroud)
我希望能够确定何时单击其中一行.目前,MapBox调用OnMapClick并传入一个LatLng对象.然后,我可以custom-line使用以下内容查询属性的渲染功能:
PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> selectedKeys = mapboxMap.queryRenderedFeatures(pixel, Filter.has("custom-line"));
Run Code Online (Sandbox Code Playgroud)
如果selectedKeys然后包含任何返回的Feature对象,我可以查询它们的坐标.getGeometry().将这些值与LatLng传入的对象的值进行比较,可以确定单击哪一行的粗略估计.但是,当订单项紧密分组时,这是非常不准确和麻烦的.
如何监听这些订单项上的点击事件?
| 归档时间: |
|
| 查看次数: |
339 次 |
| 最近记录: |