DingiShape
@interface DingiShape : NSObject <DingiAnnotation, NSSecureCoding>
DingiShape
is an abstract class that represents a shape or annotation. Shapes
constitute the content of a map – not only the overlays atop the map, but also
the content that forms the base map.
Create instances of DingiPointAnnotation
, DingiPointCollection
, DingiPolyline
,
DingiMultiPolyline
, DingiPolygon
, DingiMultiPolygon
, or DingiShapeCollection
in
order to use DingiShape
‘s methods. Do not create instances of DingiShape
directly, and do not create your own subclasses of this class. The shape
classes correspond to the
Geometry object
types in the GeoJSON standard, but some have nonstandard names for backwards
compatibility.
Although you do not create instances of this class directly, you can use its
+[DingiShape shapeWithData:encoding:error:]
factory method to create one of the
concrete subclasses of DingiShape
noted above from GeoJSON data. To access a
shape’s attributes, use the corresponding DingiFeature
class instead.
You can add shapes to the map by adding them to an DingiShapeSource
object.
Configure the appearance of an DingiShapeSource
’s or DingiVectorTileSource
’s
shapes collectively using a concrete instance of DingiVectorStyleLayer
.
Alternatively, you can add some kinds of shapes directly to a map view as
annotations or overlays.
-
Returns an
DingiShape
object initialized with the given data interpreted as a string containing a GeoJSON object.If the GeoJSON object is a geometry, the returned value is a kind of
DingiShape
. If it is a feature object, the returned value is a kind ofDingiShape
that conforms to theDingiFeature
protocol. If it is a feature collection object, the returned value is an instance ofDingiShapeCollectionFeature
.Example
let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")! let data = try! Data(contentsOf: url) let feature = try! DingiShape(data: data, encoding: String.Encoding.utf8.rawValue) as! DingiShapeCollectionFeature
Declaration
Objective-C
+ (nullable DingiShape *)shapeWithData:(nonnull NSData *)data encoding:(NSStringEncoding)encoding error:(NSError *_Nullable *_Nullable)outError;
Swift
/*not inherited*/ init(data: Data, encoding: UInt) throws
Parameters
data
String data containing GeoJSON source code.
encoding
The encoding used by
data
.outError
Upon return, if an error has occurred, a pointer to an
NSError
object describing the error. Pass inNULL
to ignore any error.Return Value
An
DingiShape
object representation ofdata
, ornil
ifdata
could not be parsed as valid GeoJSON source code. Ifnil
,outError
contains anNSError
object describing the problem.
-
The title of the shape annotation.
The default value of this property is
nil
.This property is ignored when the shape is used in an
DingiShapeSource
. To name a shape used in a shape source, create anDingiFeature
and add an attribute to theDingiFeature.attributes
property.Declaration
Objective-C
@property (readwrite, copy, nonatomic, nullable) NSString *title;
Swift
var title: String? { get set }
-
The subtitle of the shape annotation. The default value of this property is
nil
.This property is ignored when the shape is used in an
DingiShapeSource
. To provide additional information about a shape used in a shape source, create anDingiFeature
and add an attribute to theDingiFeature.attributes
property.Declaration
Objective-C
@property (readwrite, copy, nonatomic, nullable) NSString *subtitle;
Swift
var subtitle: String? { get set }
-
Returns the GeoJSON string representation of the shape encapsulated in a data object.
Declaration
Objective-C
- (nonnull NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding;
Swift
func geoJSONData(usingEncoding encoding: UInt) -> Data
Parameters
encoding
The string encoding to use.
Return Value
A data object containing the shape’s GeoJSON string representation.