Let rect = self.rect(for: overlay.boundingMapRect)ĬanslateBy(x: 0.0, y: ) Then replace its contents with:Ĭlass ParkMapOverlay: NSObject, MKOverlay Your task is to create an object that represents an overlay for the entire park.įirst, select the Overlays group and create a new Swift file named ParkMapOverlay.swift. Now that you’ve covered the theory, it’s time to put these concepts to use! Adding Your Information to the MapĬurrently, the map doesn’t provide enough information about the park. Instead, you tell the map about MKOverlay objects to display and return MKOverlayRenderers when the delegate method requests them. To sum up, you don’t add MKOverlayRenderer objects directly to the map view. MapKit calls this method when it realizes there’s an MKOverlay object in the region the map view is displaying. In ContentView.swift, you’ll see a delegate method that lets you return an overlay view: MapKit expects to present a MKMapView object, and this class defines the drawing infrastructure used by the map view. Subclassing it lets you set up what you want to display in each spot.įor example, in this app, you’ll draw an image of the roller coaster or restaurant. This is where MKOverlayRenderer comes in. But it doesn’t know what to display in each region. Finally, add the overlays to your map view.Īt this point, the map knows where it’s supposed to display the overlays.In this app, for example, you’ll create an instance for a roller coaster overlay and another for a restaurant overlay. Then, create an instance of your class for each area where you want to display an overlay.These properties define where the overlay resides on the map and its size. First, create your custom class that implements the MKOverlay protocol, which has two required properties: coordinate and boundingMapRect.There are three steps for using this class: MKOverlay tells MapKit where you want it to draw the overlays. All About Overlay Viewsīefore you start creating overlay views, you need to understand two key classes: MKOverlay and MKOverlayRenderer. Once you feel ready, dive right into overlay views. Note: If you feel like you need a refresher on how to add a map to your app, or want to dive deeper on the basics of working with MapKit, visit MapKit Tutorial: Getting Started.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |