2017-06-01 61 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接口,你需要實現它並繪製你的圖標。