Repository navigation
Add missing icons example. - #289
Conversation
|
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. |
There was a problem hiding this comment.
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:
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.
| extern NSString *const MBXExampleUserLocationAnnotation; | ||
| extern NSString *const MBXExampleUserTrackingModes; | ||
| extern NSString *const MBXExampleWebAPIData; | ||
| extern NSString *const MBXExampleMissingIcons; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
| ); | ||
| inputPaths = ( | ||
| "${PODS_ROOT}/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh", | ||
| "${SRCROOT}/Pods/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh", |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Please leave a short description as to what this is doing, since it is the highlight of the example.
chloekraw
left a comment
There was a problem hiding this comment.
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 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
left a comment
There was a problem hiding this comment.
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.
7d48921 to
0555534
Compare
0555534 to
11a5f85
Compare
|
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 |
Added a test case for missing icons feature.
Added a test case for missing icons feature.


Adds a new example for missing icons event.