You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
I am drawing custom text labels using a MGLSymbolStyleLayer which was populated with features from GeoJSON. The features contain a property called displayName which I can render just fine using layer.text = NSExpression(forKeyPath: "displayName").
The displayName property also contains a special character to indicate a line break, for example the value could be "Hello|World".
How can I create an NSExpression that replaces | with \n?
I already tried with an NSString category and NSExpression(format: "FUNCTION(..)"), but I always get an exception saying that the function is unknown.
Configuration
Mapbox SDK versions:
Mapbox-iOS-SDK 5.7.0
iOS/macOS versions:
iOS 13.2
The text was updated successfully, but these errors were encountered:
How can I create an NSExpression that replaces | with \n?
String replacement inside expressions is currently unsupported: mapbox/mapbox-gl-js#4100. For now, the best workaround is to modify the GeoJSON so that each feature’s displayName property contains newlines instead of the | character. (Or you could use a different feature property for that value.)
If you’re currently loading the GeoJSON into a shape source using MGLShape(data:encoding:error:), you could use JSONSerialization to first convert the structure to a Dictionary that you can manipulate. Or, if you have full control over the contents of the GeoJSON, you could edit the GeoJSON ahead of time so no manipulation is needed at runtime.
I already tried with an NSString category and NSExpression(format: "FUNCTION(..)"), but I always get an exception saying that the function is unknown.
Under the hood, the SDK converts NSExpressions and NSPredicates to a Mapbox-specific data structure based on the Mapbox Style Specification, so it isn’t generally possible for application code to extend this system with additional functions.
I am drawing custom text labels using a
MGLSymbolStyleLayer
which was populated with features from GeoJSON. The features contain a property calleddisplayName
which I can render just fine usinglayer.text = NSExpression(forKeyPath: "displayName")
.The
displayName
property also contains a special character to indicate a line break, for example the value could be "Hello|World".How can I create an NSExpression that replaces
|
with\n
?I already tried with an NSString category and
NSExpression(format: "FUNCTION(..)")
, but I always get an exception saying that the function is unknown.Configuration
Mapbox SDK versions:
Mapbox-iOS-SDK 5.7.0
iOS/macOS versions:
iOS 13.2
The text was updated successfully, but these errors were encountered: