Google map geoJson layer feature info on click

1.5k Views Asked by At

smart people :)!

Story: I have many layers what I have added to google maps in android. I am adding them by iterating - creating new GeoJsonLayer and calling method addLayerToMap(). I have created setOnFeatureClickListener on last GeoJsonLayer (Maybe here is the problem).

Problem: When I click on feature (LineString, Polygon) I receive information only about last Layer - polygon. Then I added mMap.setOnPolylineClickListener(), then click listener is going into correct methods - for LineString in PolyLineClick... etc, but here again is problem - how can I get information from Polyline about LineString properties, what I added to geoJson?

Question: What is the best approach to add layers to map , so I can manage click events and show LineString or Polygon properties for user?

Code example:

geoJsonLayer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {
 @Override
 public void onFeatureClick(Feature feature) {

  mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
   @Override
   public void onPolylineClick(Polyline polyline) {
    //TODO show LineString properties
    //Comes here when LineString clicked
   }
  });

  mMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {

   @Override
   public void onPolygonClick(Polygon polygon) {
    //TODO show Polygon properties
    //Comes here when Polygon clicked
   }
  });
 }

1

There are 1 best solutions below

1
TomTom On BEST ANSWER

Found solution - added all layers into 1 layer and everything works fine.