Artyom
Artyom

Reputation: 39

IOS MapBox clustering point with label from sum by custom points field

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

Upvotes: 0

Views: 647

Answers (1)

Artyom
Artyom

Reputation: 39

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]

Upvotes: 2

Related Questions