0

How can I create a cluster title based on point fields ?

For example. I have points with a value in the properties - “count”

And when creating a cluster from these points, I want to see the cluster circle text with the sum of the "count" fields, as below :

enter image description here

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "count": 16

            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    30.5419921875,
                    50.55532498251967
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "count": 2
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    36.25488281249999,
                    50.05008477838256
                ]
            }
        }
    ]
}

https://docs.mapbox.com/ios/maps/examples/clustering/ This example make text title from "point_count" But i need use sum of values from all points in cluster

Artyom
  • 39
  • 2
  • Your question is a little unclear but have you seen this? https://docs.mapbox.com/ios/maps/examples/clustering/ – Magnas Mar 21 '20 at 09:35
  • 2
    Yes. They use "point_count" value for cluster title. numbersLayer.text = NSExpression(format: "CAST(point_count, 'NSString')") But i need use sum of values from all points in cluster – Artyom Mar 21 '20 at 10:06

1 Answers1

2

There is solution:

https://github.com/mapbox/mapbox-gl-native/pull/15515

let firstExpression = NSExpression(format: "sum:({$featureAccumulated, sumValue})")
let secondExpression = NSExpression(forKeyPath: "magnitude")
let clusterPropertiesDictionary = ["sumValue" : [firstExpression, secondExpression]]

let options : [MGLShapeSourceOption : Any] = [.clustered : true,
                                           .clusterProperties: clusterPropertiesDictionary]
Artyom
  • 39
  • 2