你好我正在使用谷歌地图android api,我正在使用谷歌地图android geojson实用程序。我在地图中添加了3层geojson,只有 road_layer (LineString)具有功能点击事件。点击事件正常工作,直到我添加 samsad_boundary_layer (多边形)。问题是如果点击了 samsad_boundary_layer 功能,它会触发 road_layer 功能点击事件,尽管图层(samsad_boundary_layer)没有功能点击事件。
private void showBoundery(){
try {
samsad_boundary_layer=new GeoJsonLayer(mMap,R.raw.samsad_boundary,MapActivity.this); //1st Layer
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
samsad_boundary_layer.getDefaultPolygonStyle().setZIndex(-12f);
GeoJsonPolygonStyle polygonStyle=samsad_boundary_layer.getDefaultPolygonStyle();
polygonStyle.setStrokeWidth(5f);
polygonStyle.setStrokeColor(getResources().getColor(R.color.purple));
samsad_boundary_layer.addLayerToMap();
}
private void retrieveFileFromResource() {
try {
temp_layer=new GeoJsonLayer(mMap,R.raw.area_survey,this); //2nd Layer
temp_layer.addLayerToMap();
road_layer=new GeoJsonLayer(mMap,R.raw.road_survey,this); //3rd Layer
road_layer.setOnFeatureClickListener(new Layer.OnFeatureClickListener() {
@Override
public void onFeatureClick(Feature feature) {
if (feature!=null){
Iterator<HashMap> flavoursIter = feature.getProperties().iterator();
while (flavoursIter.hasNext()){
Map.Entry entry = (Map.Entry)flavoursIter.next();
//Log.v("SURVEYOR_FEATURE",entry.getKey().toString()+":"+entry.getValue());
}
}
}
});
GeoJsonLineStringStyle lineStyle=road_layer.getDefaultLineStringStyle();
lineStyle.setZIndex(10f);
lineStyle.setWidth(2f);
lineStyle.setColor(getResources().getColor(R.color.light_green));
road_layer.addLayerToMap();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
与其在地图上分别添加3层,而是遍历所有层并创建单层。 然后添加图层以映射并设置功能单击侦听器。相应地处理onFeatureClick。