2017-06-01 64 views
1

我想将集群添加到mapbox地图。我跟着可用的文档和一段时间后,我堆放着的是:Android上的Mapbox集群

List<Feature> markerCoordinates = new ArrayList<>(); 
      Log.v(LOG_TAG, "all advertiesrs retrieved"); 

      for(Elem e: result) { 
       markerCoordinates.add(Feature.fromGeometry(
         Point.fromCoordinates(Position.fromCoordinates(e.getLatitude(), e.getLongitude()))) 
       ); 
      } 

      FeatureCollection featureCollection = FeatureCollection.fromFeatures(markerCoordinates); 

      Log.v(LOG_TAG, "list has: " + markerCoordinates.size() + " elements"); 

      FeatureCollection collection1 = FeatureCollection.fromFeatures(markerCoordinates); 

      map.addSource(
        new GeoJsonSource(CUSTOM_DATA_SOURCE, 
          collection1, 
          new GeoJsonOptions() 
            .withCluster(true) 
            .withClusterMaxZoom(14) 
            .withClusterRadius(50) 
        ) 
      ); 

      // Each point range gets a different fill color. 
      int[][] layers = new int[][] { 
        new int[] {10, ContextCompat.getColor(MainActivity.this, R.color.marker_red)}, 
        new int[] {4, ContextCompat.getColor(MainActivity.this, R.color.marker_green)}, 
        new int[] {0, ContextCompat.getColor(MainActivity.this, R.color.marker_blue)} 
      }; 

      //Creating a marker layer for single data points 
      //How to create different markers for different points categories 
      Bitmap icon = BitmapFactory.decodeResource(MainActivity.this.getResources(), R.drawable.marker_1); 
      map.addImage("marker_1", icon); 

      SymbolLayer unclustered = new SymbolLayer("unclustered-points", CUSTOM_DATA_SOURCE); 
      unclustered.setProperties(iconImage("marker_1")); 
      map.addLayer(unclustered); 

      for (int i = 0; i < layers.length; i++) { 
       //Add clusters' circles 
       CircleLayer circles = new CircleLayer("cluster-" + i, CUSTOM_DATA_SOURCE); 
       circles.setProperties(
         circleColor(layers[i][1]), 
         circleRadius(18f) 
       ); 
       circles.setFilter(
         i == 0 
           ? gte("point_count", layers[i][0]) : 
           all(gte("point_count", layers[i][0]), lt("point_count", layers[i - 1][0])) 
       ); 
       map.addLayer(circles); 
      } 

      //Add the count labels 
      SymbolLayer count = new SymbolLayer("count", CUSTOM_DATA_SOURCE); 
      count.setProperties(
        textField("{point_count}"), 
        textSize(12f), 
        textColor(Color.WHITE) 
      ); 
      map.addLayer(count); 

问题是,我需要为不同的非集群点添加不同的图标标记。目前我只能添加一个常见图标marker_1。我无法弄清楚如何创建一些非群集数据的“群组”(每个不同点类别的不同图标)。

回答

0

试试这个Mapbox plugin。这个库有ClusterRenderer.java接口,你需要实现它并绘制你的图标。