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

Add missing icons example. - #289

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

fabian-guerra merged 2 commits into
ios-v4.10.0from
fabian-missing-icons-example

Conversation

@fabian-guerra

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

Copy link
Copy Markdown
Contributor

Adds a new example for missing icons event.

@fabian-guerra

Copy link
Copy Markdown
Contributor Author

This is how it should look
missing-icons

@riastrad

riastrad commented Apr 4, 2019

Copy link
Copy Markdown
Contributor

Thanks for putting in the legwork to add the new example, @fabian-guerra!

Would you mind sharing a quick blurb about what types of situations this usage addresses? I ask because if we add it to the docs.mapbox.com/ios/maps/examples in the future, it will be helpful to know what keywords users will be ⌘+F'ing the page for.

@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.

All examples should eventually live on https://docs.mapbox.com/ios/maps/examples/. While the code here is sound, in my opinion there is some more opportunity to make the above design more user friendly so that users can understand what is happening.

One suggestion would be to load a single map style JSON with basic styling. I have made a sample for you here:

Details
{
    "version": 8,
    "name": "test-label-replacement",
    "metadata": {
        "mapbox:autocomposite": true,
        "mapbox:type": "default",
        "mapbox:origin": "streets-v10",
        "mapbox:groups": {},
        "mapbox:sdk-support": {
            "js": "0.49.0",
            "android": "6.5.0",
            "ios": "4.4.0"
        }
    },
    "center": [-64.9876295426152, 26.58735062445217],
    "zoom": 2.78070912459614,
    "bearing": 0,
    "pitch": 0,
    "sources": {
        "composite": {
            "url": "mapbox://mapbox.mapbox-streets-v7",
            "type": "vector"
        }
    },
    "sprite": "mapbox://sprites/nbb12805/cjpvjdpvn11z42rms5wy5wigt/3x9nlnh6jy6xbyf73mnwnjvwe",
    "glyphs": "mapbox://fonts/nbb12805/{fontstack}/{range}.pbf",
    "layers": [
        {
            "id": "background",
            "type": "background",
            "layout": {},
            "paint": {"background-color": "hsl(35, 0%, 100%)"}
        },
        {
            "id": "water",
            "type": "fill",
            "source": "composite",
            "source-layer": "water",
            "layout": {},
            "paint": {
                "fill-color": "hsla(196, 0%, 0%, 0)",
                "fill-outline-color": "hsla(0, 0%, 0%, 0.35)"
            }
        },
        {
            "id": "admin-2-boundaries",
            "type": "line",
            "metadata": {},
            "source": "composite",
            "source-layer": "admin",
            "minzoom": 1,
            "filter": [
                "all",
                ["==", "admin_level", 2],
                ["==", "disputed", 0],
                ["==", "maritime", 0]
            ],
            "layout": {"line-join": "round", "line-cap": "round"},
            "paint": {
                "line-color": "hsl(230, 8%, 51%)",
                "line-width": {"base": 1, "stops": [[3, 0.5], [10, 2]]}
            }
        },
        {
            "id": "country-label-lg",
            "type": "symbol",
            "metadata": {},
            "source": "composite",
            "source-layer": "country_label",
            "minzoom": 1,
            "maxzoom": 7,
            "filter": ["in", "scalerank", 1, 2],
            "layout": {
                "text-field": "Missing icon loaded above",
                "text-max-width": {"base": 1, "stops": [[0, 5], [3, 6]]},
                "text-font": [
                    "DIN Offc Pro Medium",
                    "Arial Unicode MS Regular"
                ],
                "text-size": 14,
                "icon-image": "za-provincial-2",
                "icon-offset": [0, 0],
                "text-offset": [0, 0],
                "text-anchor": "top"
            },
            "paint": {
                "text-color": "hsl(0, 0%, 0%)",
                "text-halo-color": {
                    "base": 1,
                    "stops": [
                        [2, "rgba(255,255,255,0.75)"],
                        [3, "hsl(0, 0%, 100%)"]
                    ]
                },
                "text-halo-width": 1.25,
                "text-translate": [0, 10]
            }
        }
    ],
    "created": "2018-12-19T18:54:40.995Z",
    "id": "cjpvjdpvn11z42rms5wy5wigt",
    "modified": "2019-04-04T20:27:15.173Z",
    "owner": "nbb12805",
    "visibility": "public",
    "draft": false
}

This style uses a single symbol layer that uses one icon, with text underneath that says "Missing icon loaded above" - it looks like this:

Screenshot 2019-04-04 13 23 40

By modifying my above sample style, you can instead load your own backup icon at runtime with the delegate method you are illustrating in this example. This approach clearly illustrates just by looking at the image above that there was a backup icon loaded on to the map.

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

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 move this under line 43 please so that this list stays in alphabetical order?

self.mapView.delegate = self;
[self.view addSubview:self.mapView];

// Create a button to load the faulty style.

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.

In case people don't look at the style itself (which may probably happen when it goes live on the examples website), its probably a good idea to explain why the style we're loading is faulty.

Create a button to load the faulty style, which in this case references a missing icon image.

Comment thread Examples.xcodeproj/project.pbxproj Outdated
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh",
"${SRCROOT}/Pods/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh",

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.

I'm not sure why this changed here (also in line 1273, 1282, and 1309), but I think it should remain {PODS_ROOT}.

[self.mapView setStyleURL:customStyleJSON];
}

- (UIImage *)mapView:(MGLMapView *)mapView didFailToLoadImage:(NSString *)imageName {

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 leave a short description as to what this is doing, since it is the highlight of the example.

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

@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.

@captainbarbosa

Copy link
Copy Markdown
Contributor

@fabian-guerra do you think you can just address #289 (comment) before merging? I'm ok with the design/comment changes coming in a later PR but just a little concerned about the Pod changes as those aren't typically changed in other new example PRs.

@friedbunny friedbunny 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.

This PR conflates Xcode 10.2 project changes, the 4.10.0-beta.2 bump, and new example code — let’s separate those out into different commits and/or pull requests.

@fabian-guerra
fabian-guerra force-pushed the fabian-missing-icons-example branch from 7d48921 to 0555534 Compare April 8, 2019 23:13
@fabian-guerra
fabian-guerra force-pushed the fabian-missing-icons-example branch from 0555534 to 11a5f85 Compare April 8, 2019 23:29
@fabian-guerra

Copy link
Copy Markdown
Contributor Author

Hi, @riastrad. This "example" is more of a test case than a formal example. Clarifying the goal for this, and the other pr's I have #286 & #285. The goal for this feature is give developers a chance to load a style icon when is missing from the style —for many reasons, either it was not downloaded or the style was corrupted—

This as is will not be part of ios-sdk docs.

@fabian-guerra
fabian-guerra merged commit a7a573a into ios-v4.10.0 Apr 9, 2019
@fabian-guerra
fabian-guerra deleted the fabian-missing-icons-example branch April 9, 2019 17:58
friedbunny pushed a commit that referenced this pull request Apr 9, 2019
Added a test case for missing icons feature.
friedbunny pushed a commit that referenced this pull request Apr 24, 2019
Added a test case for missing icons feature.
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.

5 participants