SDK for iOS Developer's Guide

Objects and Interaction

The HERE SDK allows the addition of a variety of objects, each with a specific purpose, to a map view. The types of available object include map markers, routes, polylines, and overlays. These objects are described in more detail below.

The NMAMapObject Class

The NMAMapObject class provides a generic base class from which most types of specialized map object inherit. Functionality that is common to all these object types is encapsulated in NMAMapObject. The following is a list of the important properties and methods in NMAMapObject.

  • zIndex - determines the objects stacking order, which controls how the object is displayed on the map relative to other objects that may overlap it
  • visible - determines whether or not the object is drawn when the map is rendered
  • type - contains the type of the map object, such as marker, polyline, and route. For the full list, see the NMAMapObject API reference.
  • parent - the NMAMapContainer instance holding this object, if any
  • uniqueId - uniquely identifies the object for the duration of the application launch
  • NMAMapObject serves as a base class to other map object types and should not be instantiated directly.
  • Any change in a map object's visual appearance causes the entire map view to be redrawn, since map objects are drawn as part of the map itself. For optimal performance, map objects should not be frequently updated unless it is necessary.

The NMAMapContainer class

Map containers are a special type of map object that can be used to group together other map objects of certain types.  The types of object allowed are NMAMapMarker, NMAMapCircle, NMAMapPolygon, and NMAMapPolyline. Containers provide a convenient way to control the stacking order and visibility of a large group of objects.

To use a map container, create one or more map objects and add them to the container using the addMapObject method. To show the objects on a map, add the map container to the map with the addMapObject method of NMAMapView.

Note: A container may also hold other instances of NMAMapContainer.

The NMAMapCircle class

An NMAMapCircle class is used to draw a circle on the map at a fixed geographical location; custom border and fill colors may be defined.

Figure 1. A MapCircle object

The NMAMapPolyline class

The NMAMapPolyline class is used to draw one or more connected line segments on the map. The segment vertices are specified by a series of NMAGeoCoordinates. The visual appearance of the polyline can be customized.

Figure 2. A MapPolyline object

The NMAMapPolygon interface

The NMAMapPolygon class is similar to NMAMapPolyline, but the first and last points of the line are automatically joined to create a closed shape. Polygon objects can have different border and fill colors.

Figure 3. A MapPolygon object with transparent fill and a border
Note: Polygons that have a path that crosses over itelf are not supported. For example, it is not possible to create a "bowtie" shape using four line segments, where one line segment crosses over another. However, you can create the shape using two triangles.

The NMAMapMarker class

The NMAMapMarker class is used to display a custom icon at a fixed geographical position on the map.

Custom icons can be provided as an UIImage.

Figure 4. A NMAMapMarker object

You can set NMAMapMarker to be draggable by setting the draggable property to YES. To listen for drag events, such as marker position changes, use the respondToEvents:withBlock: method in NMAMapView.

Map Object Selection

All user-defined objects with a visual representation can be selected. Selection occurs when a visible object on the map is tapped. By default, the map does not take any action when objects are selected. To implement selection handling, a custom class must implement the NMAMapViewDelegate protocol and its onMapObjectsSelected method. The onMapObjectsSelected callback returns an array that contains instances of NMAViewObject, which is a superclass of NMAMapObject.

Object selection can also be programmatically invoked by using the objectsAtPoint: or visibleObjectsAtPoint: method. Each of these methods takes a CGPoint screen coordinate and returns an NSArray of NMAMapObject at that location. The visibleObjectsAtPoint method does not return any object that has the visible property set as NO.

For more information, see the NMAMapView API documentation.