Android Google Maps GeoJsonLayer OnFeatureClickListener,多层 [英] Android Google Maps GeoJsonLayer OnFeatureClickListener, multiple layers
问题描述
请查看我的代码,以从geojson字符串创建图层,然后将图层添加到地图:
Please look at my code to create layer from geojson string and add layer to map:
private GeoJsonLayer createLayerFromGeojson(String json)
{
JSONObject ob = null;
try
{
ob = new JSONObject(json);
}
catch (JSONException e)
{
e.printStackTrace();
}
GeoJsonLayer layer = new GeoJsonLayer(googleMap, ob);
layer.addLayerToMap();
layer.setOnFeatureClickListener(feature -> Utils.showMessage(getActivity(), "Clicked", feature.getProperty("description").toString()));
return layer;
}
接下来将2层添加到地图:
Next add 2 layers to map:
String json = /*first geojson string here*/
String json2 = /*another geojson string here*/
createLayerFromGeojson(json);
createLayerFromGeojson(json2);
问题:当我单击标记或pologon时,即使单击第一层从第一个json创建的对象,也始终显示从第二个json(json2)中获取的描述.
Problem: When I click on marker or pologon, always description taken from second json (json2) is displayed, even if I click on object created from first json, on first layer.
怎么了?有什么想法吗?
What's wrong? Any ideas?
推荐答案
如果您查看方法setOnFeatureClickListener
的文档,则说明:
If you check the documentation for the method setOnFeatureClickListener
it says:
为整个GoogleMap对象设置单次点击侦听器,当单击地图上的某个对象(多边形,标记,折线)时,它将与相应的Feature对象一起调用.
Sets a single click listener for the entire GoogleMap object, that will be called with the corresponding Feature object when an object on the map (Polygon, Marker, Polyline) is clicked.
对我来说,我们不能具有来自不同GeoJson的信息的多层结构似乎很愚蠢.它必须是MultiPolygon,MultiLineString或MultiPoint.
To me, it seems silly that we cannot have multiple layers with information from different GeoJson. It needs to be a MultiPolygon, MultiLineString or MultiPoint.
这篇关于Android Google Maps GeoJsonLayer OnFeatureClickListener,多层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!