Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Navmii SDK provides an easy way to present custom images on the map and to draw polylines. Children classes of NMGeoObject abstract class represent these custom images (NMGeoMarker) and polylines (NMGeoPolyline) in the SDK. NMMapView instance is responsible for creating and handling this type of objects.

CREATING MARKERS ON THE MAP

To present a marker on the map at specified coordinates with default image, instantiate it first with either initWithCoordinates: instance method or geoMarkerWithCoordinates: class method and, then, add it to the map using NMMapView instance's addGeoObject: method: 

Code Block
languagecpp
themeEclipse
NMGeoMarker *marker = [[NMGeoMarker alloc] initWithCoordinates:coords];

/* or, alternatively*/

NMGeoMarker *marker = [NMGeoMarker geoMakerWithCoordinates:coords];
*/
[mapView addGeoObject:marker];

To present a marker with specified image, use one of initWithCoordinates:andImagePath: and geoMarkerWithCoordinates:andImagePath: pair of methods. Make sure you add them to the map as in previous case:

Code Block
languagecpp
themeEclipse
NMGeoMarker *marker = [[NMGeoMarker alloc] initWithCoordinates:coords
                                                  andImagePath:pathToImage];

/* or, alternatively*/

NMGeoMarker *marker = [NMGeoMarker geoMakerWithCoordinates:coords
                                              andImagePath:pathToImage];
[mapView addGeoObject:marker];

Please note to use PNG images in Xcode, Compress PNG Files - Packaging parameters should be set to NO:

Code Block
languagecpp
themeEclipse
Compress PNG Files: No
Remove Text Metadata From PNG Files: No

CREATING IMAGES ON THE MAP

To present an image on the map at specified coordinates, instantiate a dedicated object, NMGeoImage, with either initWithRect:imagePath:imageScale: instance method or geoImageWithRect:imagePath:imageScale: class method with a rectangle NMMapRectangle object and then add it to the map using NMMapView instance's addGeoObject: method:

Code Block
languagecpp
themeEclipse
NMGeoImage *geoImage = [[NMGeoImage alloc] initWithRect:rect imagePath:imagePath imageScale:imageScale];

/* or, alternatively*/

NMGeoImage *geoImage = [NMGeoImage geoImageWithRect:rect imagePath:imagePath imageScale:imageScale];

[mapView addGeoObject:geoImage];

Alternatively an NMGeoImage can be instantiated with independent corner coordinates initWithCoordinatesTopLeft:topRight:bottomLeft:bottomRight:imagePath:imageScale: instance method or geoImageWithCoordinatesTopLeft:topRight:bottomLeft:bottomRight:imagePath:imageScale: class method. After object is being instantiated it can be added to the map using NMMapView instance's addGeoObject: method: 

Code Block
languagecpp
themeEclipse
NMGeoImage *geoImage = [[NMGeoImage alloc] initWithTopLeft:topLeft
												  topRight:topRight
												bottomLeft:bottomLeft
											   bottomRight:bottomRight
												 imagePath:imagePath
												imageScale:imageScale];

/* or, alternatively*/

NMGeoImage *geoImage = [NMGeoImage geoImageWithCoordinatesTopLeft:topLeft
														 topRight:topRight
													   bottomLeft:bottomLeft
													  bottomRight:bottomRight
													    imagePath:imagePath
													   imageScale:imageScale];

[mapView addGeoObject:marker];geoImage];

Please note to use PNG images in Xcode, Compress PNG Files - Packaging parameters should be set to NO:

Code Block
languagecpp
themeEclipse
Compress PNG Files: No
Remove Text Metadata From PNG Files: No


DRAWING POLYLINES

To draw a polyline on the map use either initWithVertices: instance method or geoPolylineWithVertices: class  class method. Pass an array of NMMapCoordinates representing polyline vertices geo position as the argument.  Add the polyline instantiated with one of methods to the NMMapView instance:

Code Block
languagecpp
themeEclipse
NMGeoPolyline *polyline = [[NMGeoPolyline alloc] initWithVertices:vertices];
/* or, alternatively
NMGeoPolyline *polyline = [NMGeoPolyline geoPolylineWithVertices:vertices];
*/
[mapView addGeoObject:polyline];

DRAWING CIRCLES

To draw a circle on the map use either initWithCenter:radius:strokeWidth:fillColor:strokeColor: instance method or geoCircleWithCenter:radius:strokeWidth:fillColor:strokeColor: class method. Pass an center of NMMapCoordinates representing circle's center geo position as the argument, a radius, a stroke width and color and a fill color. Add the circle instantiated with one of methods to the NMMapView instance:

Code Block
languagecpp
themeEclipse
NMGeoCirce *circle = [[NMGeoCircle alloc] initWithCenter:center
												  radius:radius
										     strokeWidth:strokeWidth
											   fillColor:fillColor
											 strokeColor:strokeColor];
/* or, alternatively
NMGeoCirce *circle = [NMGeoCirce geoCircleWithCenter:center
										      radius:radius
										 strokeWidth:strokeWidth
										   fillColor:fillColor
									     strokeColor:strokeColor];
*/
[mapView addGeoObject:circle];


WORKING WITH POLYLINES

You can insert and remove a point or multiple points into and from a polyline, using NMGeoPolyline's appendVertex:, insertVertex:AtIndex:, removeLastVertex:removeVertexAtIndex: and removeAllVertices methods. To retrieve overall vertices count use vertices property is an NSArray instance.

Code Block
languagecpp
themeEclipse
//adds a vertex to the polyline's end
[polyline appendVertex:coordinates]; 
//inserts a vertex into the polyline at index 3
if ([polyline.vertices count] >= 3) {


	[polyline insertVertex:coordinates atIndex:3];
}
//removes last vertex from the polyline
[polyline removeLastVertex];
//removes the vertex at index 3 from the polyline 
if ([polyline.vertices count] >= 3) {
	
	[polyline removeVertexAtIndex:3];
}
//removes all vertices from the polyline
[polyline removeAllVertices];	

The way the polyline is rendered on the map is also customizable. You can change the polyline's color and width using NMGeoPolyline's color and width properties. The width property is CGFloat value representing polyline's width in Device-Independent Pixels (DIPs).

Code Block
languagecpp
themeEclipse
//sets polyline width to 3 DPI
polyline.width = 3;
//sets polyline color to red
polyline.color = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f];


INTERACTING WITH GEO OBJECTS

Editing geo objects

Circles and polygons can be made editable using editable method. An editable object will be displayed with handles, which can be dragged in order to edit the object:


Image Added Image Added

Listening to geo object events

There three types of user events related to NMGeoObjects recognized by the SDK:

  • single tap on a geo object
  • double tap on a geo object
  • long press on a geo object
  • modifying an editable geo object by dragging the handles displayed on it by the SDK

The first three events will only be called for clickable geo objects (markers, circles and polygons, for which setClickable(true) method has been called).

The last event will only be called for editable geo objects (circles and polygon, for which editable property was set to true). This event is called once when a user stops interacting with the object.

To be able to handle these events make one of your classes conforming to NMGeoObjectListener protocol and add an instance of this class to the map view's geo object listeners. Methods onGeoObjectClick:, onGeoObjectDoubleClick:

and

onGeoObjectLongPress: and onGeoObjectChanged: will be called on these events:

Code Block
languagecpp
themeEclipse
- (void)onGeoObjectClick:(NSUInteger)geoObjectID {
	//handle single tap on geo object here
}
- (void)onGeoObjectLongPress:(NSUInteger)geoObjectID {
	//handle long press on geo object here
}
- (void)onGeoObjectPress:(NSUInteger)geoObjectID {
	//handle press on geo object here
}

- (void)onGeoObjectRelease:(NSUInteger)geoObjectID {
	//handle release geo object here
}
- (void)onGeoObjectChanged:(NSUInteger)geoObjectID {
	//handle geo object changed event here
}