I am working with map-box in ios swift, my code is working good enough until I zoom to the destination marker but when I reach to destination marker, I unable to get any count on destination marker. Below is my code
let icon = UIImage(named: "ic_pin")!
let ic_pin_count_bord = UIImage(named: "ic_pin_count_bord")!
var coordinates = [[String:AnyObject]]()
for i in mainModelView.mapData.mapPinsData{
var pinSet = [String: AnyObject]()
pinSet["id"] = i.ID as AnyObject
pinSet["coordinate"] = CLLocationCoordinate2D(latitude: i.cordinates?.coordinates?.last ?? Double(), longitude: i.cordinates?.coordinates?.first ?? Double()) as AnyObject
coordinates.append(pinSet)
}
let features = coordinates.map { coordinate -> MGLPointFeature in
let pointFeature = MGLPointFeature()
pointFeature.coordinate = coordinate["coordinate"] as! CLLocationCoordinate2D
pointFeature.attributes = [
"id": coordinate["id"] as! String
]
return pointFeature
}
// Create an MGLShapeCollectionFeature from the features
// Create an MGLShapeSource using the shapeCollection
let source = MGLShapeSource(identifier: "clusteredPorts", features: features, options: [.clustered: true, .clusterRadius: mainModelView.icon.size.width])
mapView.style?.addSource(source)
// Show unclustered features as icons. The `cluster` attribute is built into clustering-enabled source features.
// This example requires two style layers to work properly: one for clustered points and one for unclustered points
let markerLayer = MGLSymbolStyleLayer(identifier: "ports", source: source)
markerLayer.iconImageName = NSExpression(forConstantValue: "ic_pin")
markerLayer.predicate = NSPredicate(format: "cluster != YES")
markerLayer.iconAllowsOverlap = NSExpression(forConstantValue: true)
style.addLayer(markerLayer)
style.setImage(icon, forName: "ic_pin")
// Create style layer to cluster features as images with labels
let clusterLayer = MGLSymbolStyleLayer(identifier: "clusteredPortsNumbers", source: source)
clusterLayer.textColor = NSExpression(forConstantValue: UIColor.white)
clusterLayer.textFontSize = NSExpression(forConstantValue: NSNumber(value: Double(icon.size.width) / 2))
clusterLayer.iconAllowsOverlap = NSExpression(forConstantValue: true)
// Style image clusters
style.setImage(icon, forName: "ic_pin")
let stops = [
10: NSExpression(forConstantValue: "ic_pin"),
25: NSExpression(forConstantValue: "ic_pin"),
75: NSExpression(forConstantValue: "ic_pin"),
150: NSExpression(forConstantValue: "ic_pin")
]
// Use expressions to set each cluster's image based on defined stops and display the point count over the corresponding image
let defaultShape = NSExpression(forConstantValue: "ic_pin")
clusterLayer.iconImageName = NSExpression(format: "mgl_step:from:stops:(point_count, %@, %@)", defaultShape, stops)
let backgroundLayer = MGLSymbolStyleLayer(identifier: "clusteredPortsNumbersBackground", source: source)
backgroundLayer.iconImageName = NSExpression(forConstantValue: "ic_pin_count_bord") // Use the same image for the background
style.setImage(ic_pin_count_bord, forName: "ic_pin_count_bord")
// Configure background layer
let expression = NSExpression(format: "CAST(point_count, 'NSString')")
backgroundLayer.text = expression
backgroundLayer.iconAllowsOverlap = NSExpression(forConstantValue: true)
backgroundLayer.textAllowsOverlap = NSExpression(forConstantValue: true)
backgroundLayer.textFontSize = NSExpression(forConstantValue: NSNumber(value: Double(icon.size.width) / 2))
backgroundLayer.textAnchor = NSExpression(forConstantValue: "center")
backgroundLayer.textColor = NSExpression(forConstantValue: UIColor.black)
backgroundLayer.iconAnchor = NSExpression(forConstantValue: "bottom")
backgroundLayer.iconOffset = NSExpression(forConstantValue: NSValue(cgVector: CGVector(dx: 0, dy: -10)))
backgroundLayer.textOffset = NSExpression(forConstantValue: NSValue(cgVector: CGVector(dx: 0, dy: -4)))
style.addLayer(backgroundLayer)
style.addLayer(clusterLayer)
I want set the text like if count is more than 1 then I want to manupulate the NSExpression by "Count Images" other wise "1 Image".