Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

[ios] Add example for variable label placement. - #286

Merged
fabian-guerra merged 2 commits into
ios-v4.10.0from
fabian-label-placement-example
Apr 9, 2019
Merged

fabian-guerra merged 2 commits into
ios-v4.10.0from
fabian-label-placement-example

Conversation

@fabian-guerra

@fabian-guerra fabian-guerra commented Apr 2, 2019 •

Copy link
Copy Markdown
Contributor

Example that shows how to use variable label placement: mapbox/mapbox-gl-native#14184

@captainbarbosa captainbarbosa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 My comments on the Objective-C file also apply to the corresponding Swift file as well.

Comment thread Examples/Examples.h Outdated
extern NSString *const MBXExampleUserLocationAnnotation;
extern NSString *const MBXExampleUserTrackingModes;
extern NSString *const MBXExampleWebAPIData;
extern NSString *const MBXExampleLabelPlacement;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this under line 40 to keep this in alphabetical order.

// Created by Fabian Guerra Soto on 4/2/19.
// Copyright © 2019 Mapbox. All rights reserved.
//

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is customary for this project to remove the above information.

poiLabelLayers.textOffset = nil;
poiLabelLayers.symbolPlacement = nil;
poiLabelLayers.textOffset = nil;
// poiLabelLayers.textVariableAnchor = [NSExpression expressionForConstantValue:@[@(MGLTextAnchorTop), @(MGLTextAnchorRight)]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you intend to keep these comments in, can you explain what uncommenting them will do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the code that does the label placement. But I don't have a beta release that contains such code, that's why I commented this code while waiting for beta.2. Once that is released will uncomment.

}

- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
MGLSymbolStyleLayer *poiLabelLayers = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"poi-label"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its important to mention here that the poi-label layer is specific to Mapbox styles that include the mapbox-streets-v8 source, which you may want to link to here: https://docs.mapbox.com/vector-tiles/reference/mapbox-streets-v8/#poi_label

poiLabelLayers.textAnchor = nil;
poiLabelLayers.textOffset = nil;
poiLabelLayers.symbolPlacement = nil;
poiLabelLayers.textOffset = nil;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain what the default styling for the poi-label looks like? For example, by default it shows a symbol (or "icon") with the text below it, and the modification you are making above will undo that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refers to label collision, when you turn on the label placement anchors the collision detection re-positions the labels.

Here is how it looks:
mapbox/mapbox-gl-js#7596 (comment)

@chloekraw
chloekraw self-requested a review April 5, 2019 19:55

@chloekraw chloekraw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed feedback @captainbarbosa! @fabian-guerra will address these comments next week when they are added as official parts of our example documentation. For now I'll approve so we can test with the beta release.

@fabian-guerra
fabian-guerra force-pushed the fabian-label-placement-example branch from acd788f to b9eb168 Compare April 9, 2019 18:08
@fabian-guerra
fabian-guerra merged commit 5b25d00 into ios-v4.10.0 Apr 9, 2019
@fabian-guerra
fabian-guerra deleted the fabian-label-placement-example branch April 9, 2019 18:38
friedbunny pushed a commit that referenced this pull request Apr 9, 2019
Added test case for text label placement feature.
friedbunny pushed a commit that referenced this pull request Apr 24, 2019
Added test case for text label placement feature.
@chloekraw chloekraw changed the title [ios] Add example for label placement. [ios] Add example for variable label placement. May 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants