Я пробовал образец из https://www.mapbox.com/ios-sdk/maps/examples/clustering/, и в настоящее время все изображения значков похожи.Могу ли я узнать, как установить разные изображения для разных категорий (используя ports1.text) на карте?
Как показано ниже, мой пример кода: -
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"clusteredPorts" URL:url options:@{ MGLShapeSourceOptionClustered: @(YES),MGLShapeSourceOptionClusterRadius: @(100)
}];
[style addSource:source];
[style setImage:[UIImage imageNamed:@"Map_Food"] forName:@"icon1"];
[style setImage:[UIImage imageNamed:@"Map_IT"] forName:@"icon2"];
MGLSymbolStyleLayer *ports1 = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"ports1" source:source];
ports1.iconImageName = [NSExpression expressionForConstantValue:@"icon1"];
ports1.text = [NSExpression expressionForKeyPath:@"category_id"];
ports1.textFontSize = [NSExpression expressionForConstantValue:@(10)];
ports1.iconAnchor = [NSExpression expressionForConstantValue:@"bottom"];
ports1.textAnchor = [NSExpression expressionForConstantValue:@"top"];
ports1.iconColor = [NSExpression expressionForConstantValue:[ThemeDarkBlueColor colorWithAlphaComponent:0.9]];
ports1.predicate = [NSPredicate predicateWithFormat:@"cluster != YES"];
[style addLayer:ports1];
MGLSymbolStyleLayer *ports2 = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"ports2" source:source];
ports2.iconImageName = [NSExpression expressionForConstantValue:@"icon2"];
ports2.text = [NSExpression expressionForKeyPath:@"category_id"];
ports2.textFontSize = [NSExpression expressionForConstantValue:@(10)];
ports2.iconAnchor = [NSExpression expressionForConstantValue:@"bottom"];
ports2.textAnchor = [NSExpression expressionForConstantValue:@"top"];
ports2.iconColor = [NSExpression expressionForConstantValue:[ThemeDarkBlueColor colorWithAlphaComponent:0.9]];
ports2.predicate = [NSPredicate predicateWithFormat:@"cluster != YES"];
[style addLayer:ports2];
NSDictionary *stops = @{ @20: [UIColor greenColor],
@50: [UIColor yellowColor],
@100: [UIColor orangeColor],
@200: ThemeRedColor };
MGLCircleStyleLayer *circlesLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"clusteredPorts" source:source];
circlesLayer.circleRadius = [NSExpression expressionForConstantValue:@(30)];
circlesLayer.circleOpacity = [NSExpression expressionForConstantValue:@0.75];
circlesLayer.circleStrokeColor = [NSExpression expressionForConstantValue:[ThemeWhiteColor colorWithAlphaComponent:0.75]];
circlesLayer.circleStrokeWidth = [NSExpression expressionForConstantValue:@1];
circlesLayer.circleColor = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(point_count, %@, %@)",
ThemeGrayColor, stops];
circlesLayer.predicate = [NSPredicate predicateWithFormat:@"cluster == YES"];
[style addLayer:circlesLayer];
MGLSymbolStyleLayer *numbersLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"clusteredPortsNumbers" source:source];
numbersLayer.textColor = [NSExpression expressionForConstantValue:ThemeWhiteColor];
numbersLayer.textFontSize = [NSExpression expressionForConstantValue:@(20)];
numbersLayer.iconAllowsOverlap = [NSExpression expressionForConstantValue:@(YES)];
numbersLayer.text = [NSExpression expressionWithFormat:@"CAST(point_count, 'NSString')"];
numbersLayer.predicate = [NSPredicate predicateWithFormat:@"cluster == YES"];
[style addLayer:numbersLayer];
Любое решение для изменения изображения с помощью [NSPredicate predicateWithFormat:
?