Coder Social home page Coder Social logo

mapbox / ios-sdk-examples Goto Github PK

View Code? Open in Web Editor NEW
95.0 103.0 35.0 1.88 MB

Live example code for the Mapbox iOS SDK

Home Page: https://www.mapbox.com/ios-sdk/examples/

License: Other

Objective-C 55.93% Ruby 12.73% Swift 30.82% C 0.53%
ios mapbox mobile mapbox-ios-sdk maps

ios-sdk-examples's Introduction

Mapbox iOS SDK Examples

bitrisecodecov

A live Xcode project/app that provides public examples for the Mapbox Maps SDK for iOS.

How to receive help

We are not able to answer support questions in this repository — it is intended to show examples of what is possible with the Mapbox Maps SDK for iOS. If you have questions about how to use the Mapbox Maps SDK for iOS, please see our excellent documentation or ask the community at Stack Overflow.

Other helpful links

Getting started

  1. Run bundle install to install build/packaging dependencies.
  2. Follow the instructions for installing the Maps SDK via CocoaPods in the installation guide.
  3. Run bundle exec pod install to download and integrate dependencies using CocoaPods.
  4. Create the mapbox_access_token file in the base directory and insert your Mapbox access token.
  5. Open Examples.xcworkspace.

Adding a new example

See the instructions in Examples.h for how to add new examples.

ios-sdk-examples's People

Contributors

1ec5 avatar captainbarbosa avatar ericrwolfe avatar fabian-guerra avatar friedbunny avatar heystenson avatar incanus avatar jmkiley avatar julianrex avatar lloydsheng avatar nishant-karajgikar avatar riastrad avatar vincethecoder avatar zizasaurus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-sdk-examples's Issues

Add view annotation z-ordering example

An example of mapbox/mapbox-gl-native#5287:

For example, if you want a particular view-backed annotation other than the selected annotation to appear in front of any other view-backed annotations, your MGLMapViewDelegate can hold a strong reference to the view it provides for that annotation and implement this method:

- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered {
    // Make way for Its Preeminence!
    [self.preeminentAnnotationView.superview bringSubviewToFront:self.preeminentAnnotationView];
}

This example would also need to note our support for other types of annotations, whatever that is when this is finished/published.

/cc @1ec5

How to add different type of icon in the Geo map Cluster ?

Hi All, I have implemented Map box cluster in my GeoMap. The clustering part is working charm but pointed location icon like static according my requirement that pointed location should be different type of icons see below image ( red colour and yellow colour icons ) seems like i will add different type of icons

- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ports" ofType:@"geojson"]]; self.source = [[MGLShapeSource alloc] initWithIdentifier:@"clusteredPorts" URL:url options:@{ MGLShapeSourceOptionClustered: @(YES), MGLShapeSourceOptionClusterRadius: @(self.icon.size.width+50) }]; [style addSource:self.source]; // Use a template image so that we can tint it with the iconColorruntime styling property. **[style setImage:[self.icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forName:@"icon"];** // Show unclustered features as icons. Thecluster` attribute is built into clustering-enabled source features.
self.ports = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"ports" source:self.source];
self.ports .iconImageName = [MGLStyleValue valueWithRawValue:@"icon"];
self.ports .iconColor = [MGLStyleValue valueWithRawValue:[[UIColor redColor] colorWithAlphaComponent:0.9]];
self.ports.predicate = [NSPredicate predicateWithFormat:@"%K != YES", @"cluster"];

self.ports.predicate = [NSPredicate predicateWithFormat:@"%K != created", @"icon"];
NSLog(@"Predicate : %@",self.ports.predicate);
[style addLayer:self.ports ];
// Color clustered features based on clustered point counts.
NSDictionary *stops = @{ @20: [MGLStyleValue valueWithRawValue:[UIColor lightGrayColor]],
@50: [MGLStyleValue valueWithRawValue:[UIColor orangeColor]],
@100: [MGLStyleValue valueWithRawValue:[UIColor redColor]],
@200: [MGLStyleValue valueWithRawValue:[UIColor purpleColor]] };
// Show clustered features as circles. The point_count attribute is built into clustering-enabled source features.
MGLCircleStyleLayer *circlesLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"clusteredPorts" source:self.source];
circlesLayer.circleRadius = [MGLStyleValue valueWithRawValue:@(self.icon.size.width+2 / 2)];
circlesLayer.circleOpacity = [MGLStyleValue valueWithRawValue:@0.75];
circlesLayer.circleStrokeColor = [MGLStyleValue valueWithRawValue:[[UIColor whiteColor] colorWithAlphaComponent:0.75]];
circlesLayer.circleStrokeWidth = [MGLStyleValue valueWithRawValue:@2];
circlesLayer.circleColor = [MGLSourceStyleFunction
functionWithInterpolationMode:MGLInterpolationModeInterval
stops:stops
attributeName:@"point_count"
options:nil];
circlesLayer.predicate = [NSPredicate predicateWithFormat:@"%K == YES", @"cluster"];
[style addLayer:circlesLayer];
// Label cluster circles with a layer of text indicating feature count. Per text token convention, wrap the attribute in {}.
MGLSymbolStyleLayer *numbersLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"clusteredPortsNumbers" source:self.source];
numbersLayer.textColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]];
numbersLayer.textFontSize = [MGLStyleValue valueWithRawValue:@(self.icon.size.width+3 / 2)];
numbersLayer.iconAllowsOverlap = [MGLStyleValue valueWithRawValue:@(YES)];
numbersLayer.text = [MGLStyleValue valueWithRawValue:@"{point_count}"];
numbersLayer.predicate = [NSPredicate predicateWithFormat:@"%K == YES", @"cluster"];
[style addLayer:numbersLayer];
// Add a tap gesture for zooming in to clusters or showing popups on individual features.
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]];
}
`
cluster

Geocoding example

There should be an example in which the user can long-press the map to drop a pin and see its address, geocoded using the Geocoding API via MapboxGeocoder.swift.

/ref #6
/cc @friedbunny @tmcw

Custom user dot

Let’s add an example of customizing the user location annotation view, somewhere along the lines of the existing annotation view example, since it may not be entirely obvious from the MGLMapView API how to do that.

/cc @friedbunny @frederoni

SceneKit annotation view

Let’s add an example of using SceneKit content in an annotation view. For example, we could use an SCNView as the user location annotation view to turn the user puck into a 3D car. We could also do the same in the iOS navigation SDK’s example application as well.

This blog post shows how to sync an SCNView with an MGLMapView, although it doesn’t associate the view with an annotation. This Apple sample project provides some inspiration for using a car model to represent the user. Freely licensed 3D car models in COLLADA format aren’t easy to find, but apparently the Unity Asset Store has models in FBX format that can be converted to COLLADA using Maya or another 3D application.

/ref mapbox/mapbox-navigation-ios#402 (comment)
/cc @mapbox/ios @mapbox/navigation-ios @david-rhodes @kronick

Discussion: 3D Objects above earth

Hi, We're investigating whether it's possible to place upright view's that are part of the map over the earth as if it was an overlay that was positioned to the earth's normal.

The goal would be to have our own views that can be placed on the map, having the map tilted to a pitch of 90 degrees, buildings turned on so that you can see the height of the buildings and terrain, and a view that sizes with it's size and distance from the latitude and longitude that it's fixed at.

This is very similar to an overlay implementation except, that the view could be adjusted to sitting
upright on the map.

Is this accomplishable?

Animated polyline annotation

We should have an example of appending or otherwise mutating a polyline annotation on the fly, using -[MGLPolyline appendCoordinates:count:]. This would accomplish the same visual effect as “Animated line” but demonstrate an easier and more performant approach than what the runtime styling API is currently capable of.

/cc @jmkiley @incanus

Symbol layer (GeoJSON) point clustering

Per mapbox/mapbox-gl-native#320 (comment), we should have a good example of symbol layer clustering.

What I'd like to see:

  • Ability to toggle all clusters on & off
  • Ability to tap on a cluster to have it zoom in to the extent of the clustered points (revealing more points)
  • Ability to show a callout when tapping a cluster point
    • This might require some sort of interaction between a GL-backed symbol layer and an annotation view layer

Basically, let's:

  • Show what you can do now with our clustering capabilities
  • Get an idea of how important mapbox/mapbox-gl-native#6181 is as a way to make this better.

Lint examples

We should use SwiftLint to enforce coding conventions automatically, since we tend to care more about code style in our examples than in other code we write.

/cc @friedbunny

Simple offline pack example

The site should have a simple offline pack example that downloads a single pack and shepherds it to completion, based on the examples in this help document. It would likely use an MGLOfflinePackAdditionCompletionHandler and KVO on a specific MGLOfflinePack object’s progress property, but it wouldn’t need to register for notifications about packs in general.

/cc @friedbunny

Update for v9 styles

Besides refreshing the screenshots, we should:

  • Deal with versioning
    • MGLStyleCurrentVersion or hard-code the latest version?
  • Tielt — make sure it smoothes out with the new caching
  • Move ‘simple map view’ away from NYC
  • Replace Emerald with Outdoors in Custom style example
  • Add appropriate tint for each style

Refs mapbox/mapbox-gl-native#4759

/cc @1ec5

Examples' page formatting on mobile

You can only see Swift examples when viewing the iOS Examples page on Mobile in Safari. The examples list is not present in portrait mode.

screenshot 2016-12-08 15 58 28

Add traffic to existing style

It’s straightforward enough to create a new style based on the Traffic Day or Traffic Night style in Studio, but if a developer wants to offer a toggleable traffic overlay, they need to write a nontrivial (but not excessive) amount of code using the runtime styling API.

The proposed example would show how to add traffic lines based on the Mapbox Traffic v1 source to an existing style using the runtime styling API. It would hard-code colors and line widths, but the developer would be free to adjust them as desired – we could even throw in some #colorLiterals in the Swift version to make the color scheme easier to tweak.

To ensure that the lines sit beneath any labels and shields in the style, we could hard-code a style layer name, put in a <#placeholder#> for that layer name, or have the developer dynamically search for the topmost layer that isn’t a symbol style layer:

for layer in style.layers.reversed() {
    if !(layer is MGLSymbolStyleLayer) {
        style.insertLayer(line, above: layer)
        // …
        break
    }
}

Along these lines, we might want to make it easy for the developer to toggle traffic lines on and off. We could similarly hard-code a list of layer identifiers, or the developer could search for relevant layers dynamically, demonstrating another aspect of the runtime styling API:

var trafficSource = style.sources
    .flatMap { $0 as? MGLVectorSource }
    .filter { $0.URL == URL(string: "mapbox://mapbox.mapbox-traffic-v1") }
    .first

for layer in style.layers {
    if let layer = layer as? MGLForegroundStyleLayer,
        layer.sourceIdentifier == trafficSource.identifier {
        layer.isVisible = showsTraffic
    }
}

/cc @friedbunny @bsudekum @mtirwin

Geofencing example

It would be great to have an example that shows how to visualize geofencing with Mapbox iOS SDK. For example, how to detect and change a map based on whether a user is in a region.

cc @captainbarbosa

Tiptoe around border disputes

We should have an example of restyling certain sets of disputed borders. We can go a step further, using NSLocale.countryCode or CTCarrier.isoCountryCode to erase borders based on the country we detect the user is located in.

This will require iOS SDK v3.4.0 for the runtime styling API.

/cc @friedbunny @pveugen @frederoni

View syncing example

Even after we implement mapbox/mapbox-gl-native#1784, developers may still need to synchronize native views with the map, for example in cases where the view doesn’t quite behave like a point feature. We should add an example that exercises the geometric conversion methods in MGLMapView.

/cc @friedbunny

Provide Swift 3 examples

Now that Xcode 8 is in beta, we should provide Swift 3 examples or tailor the existing Swift examples to accommodate Swift 3 syntax using #if swift(3). Here are the most obvious changes that’ll affect our examples:

// Note “Center” instead of “CenterCoordinate”
mapView.setCenter(, animated: )
MGLMapCamera(lookingAtCenter: , fromDistance: , pitch: , heading: )

// Note the _ before mapView and “imageFor” instead of “imageForAnnotation”
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage?

// Note the lowercase f
mapView.userTrackingMode = .followWithHeading

/cc @friedbunny @tmcw

More fill pattern example follow-up

@captainbarbosa Follow-up for #94:

  1. Rename the Swift view controller to FillPatternExample_Swift so that the Jekyll plugin can regex it to ViewController.
  2. Set a matching tint color.
  3. Delete the Xcode 9 AppIcon entry that got added.

Add managing memory resources example (with multiple active full screen maps)

It is common for iOS applications to have many view controllers on the nav stack (think about surfing through user profiles in a social networking app where you may keep adding views like cards on a deck as you walk through a social graph).

We should consider adding an example that illustrates some approaches for keeping memory usage (RAM) streamlined in this situation.

Datasets API

We should have examples for working with data sets authored in Mapbox Studio, specifically for using the Datasets API to populate a shape source. The example in #69 dealt with a relatively small amount of immutable data that was more appropriate for a bundled GeoJSON file, but a data set–focused example would use a larger data set containing the kind of data that would naturally vary over time.

We don’t have a client library for the Datasets API yet like we do for the Geocoding, Directions, and classic Static APIs. From the code originally pushed to #69, it looks like the developer wouldn’t have to do much with the API to display the data set. So let’s focus on display; something more advanced like modifying or deleting data can wait until we have a proper client library.

/cc @jmkiley @captainbarbosa @friedbunny

Runtime styling annotation substitute examples

If anyone needs to draw something that's geographic-based versus pixel-based, runtime styling is the way to go instead of annotation views.

A good example might be circles of a fixed distance radius around a point. This changes the circle size on zoom in a way that would be inefficient in a view on zoom/viewport change callback.

At a technical level, this would happen with these steps:

  1. Determine geographic coordinates of features.
  2. Encode them in GeoJSON.
  3. Add an MGLGeoJSONSource to the style.
  4. Add appropriate MGLStyleLayer object(s) to render the source.

We should probably do multiple examples in increasing complexity, such as with label text or animations.

/cc @boundsj @ericrwolfe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.