DingiShapeSource
@interface DingiShapeSource : DingiSource
DingiShapeSource
is a map content source that supplies vector shapes to be
shown on the map. The shapes may be instances of MGLShape
or DingiFeature
,
or they may be defined by local or external
GeoJSON code. A shape source is added to an
DingiStyle
object along with an DingiVectorStyleLayer
object. The vector style
layer defines the appearance of any content supplied by the shape source. You
can update a shape source by setting its shape
or URL
property.
DingiShapeSource
is optimized for data sets that change dynamically and fit
completely in memory. For large data sets that do not fit completely in memory,
use the DingiComputedShapeSource
or DingiVectorTileSource
class.
Each
geojson source defined by the style JSON file is represented at runtime by an
DingiShapeSource
object that you can use to refine the map’s content and
initialize new style layers. You can also add and remove sources dynamically
using methods such as -[DingiStyle addSource:]
and
-[DingiStyle sourceWithIdentifier:]
.
Any vector style layer initialized with a shape source should have a nil
value in its sourceLayerIdentifier
property.
Example
var coordinates: [CLLocationCoordinate2D] = [
CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42),
CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04),
]
let polyline = DingiPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
let source = DingiShapeSource(identifier: "lines", features: [polyline], options: nil)
mapView.style?.addSource(source)
-
Returns a shape source with an identifier, URL, and dictionary of options for the source.
This class supports the following options:
DingiShapeSourceOptionClustered
,DingiShapeSourceOptionClusterRadius
,DingiShapeSourceOptionMaximumZoomLevelForClustering
,DingiShapeSourceOptionMinimumZoomLevel
,DingiShapeSourceOptionMaximumZoomLevel
,DingiShapeSourceOptionBuffer
, andDingiShapeSourceOptionSimplificationTolerance
. Shapes provided by a shape source are not clipped or wrapped automatically.Declaration
Objective-C
- (nonnull instancetype) initWithIdentifier:(nonnull NSString *)identifier URL:(nonnull NSURL *)url options:(nullable NSDictionary<DingiShapeSourceOption, id> *)options;
Swift
init(identifier: String, url: URL, options: [DingiShapeSourceOption : Any]? = nil)
Parameters
identifier
A string that uniquely identifies the source.
url
An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.
options
An
NSDictionary
of options for this source.Return Value
An initialized shape source.
-
Returns a shape source with an identifier, a shape, and dictionary of options for the source.
This class supports the following options:
DingiShapeSourceOptionClustered
,DingiShapeSourceOptionClusterRadius
,DingiShapeSourceOptionMaximumZoomLevelForClustering
,DingiShapeSourceOptionMinimumZoomLevel
,DingiShapeSourceOptionMaximumZoomLevel
,DingiShapeSourceOptionBuffer
, andDingiShapeSourceOptionSimplificationTolerance
. Shapes provided by a shape source are not clipped or wrapped automatically.To specify attributes about the shape, use an instance of an
DingiShape
subclass that conforms to theDingiFeature
protocol, such asDingiPointFeature
. To include multiple shapes in the source, use anDingiShapeCollection
orDingiShapeCollectionFeature
object, or use the-initWithIdentifier:features:options:
or-initWithIdentifier:shapes:options:
methods.To create a shape from GeoJSON source code, use the
+[DingiShape shapeWithData:encoding:error:]
method.Declaration
Objective-C
- (nonnull instancetype) initWithIdentifier:(nonnull NSString *)identifier shape:(nullable DingiShape *)shape options:(nullable NSDictionary<DingiShapeSourceOption, id> *)options;
Swift
init(identifier: String, shape: DingiShape?, options: [DingiShapeSourceOption : Any]? = nil)
Parameters
identifier
A string that uniquely identifies the source.
shape
A concrete subclass of
DingiShape
options
An
NSDictionary
of options for this source.Return Value
An initialized shape source.
-
Returns a shape source with an identifier, an array of features, and a dictionary of options for the source.
This class supports the following options:
DingiShapeSourceOptionClustered
,DingiShapeSourceOptionClusterRadius
,DingiShapeSourceOptionMaximumZoomLevelForClustering
,DingiShapeSourceOptionMinimumZoomLevel
,DingiShapeSourceOptionMaximumZoomLevel
,DingiShapeSourceOptionBuffer
, andDingiShapeSourceOptionSimplificationTolerance
. Shapes provided by a shape source are not clipped or wrapped automatically.Unlike
-initWithIdentifier:shapes:options:
, this method acceptsDingiFeature
instances, such asDingiPointFeature
objects, whose attributes you can use when applying a predicate toDingiVectorStyleLayer
or configuring a style layer’s appearance.To create a shape from GeoJSON source code, use the
+[DingiShape shapeWithData:encoding:error:]
method.Declaration
Objective-C
- (nonnull instancetype) initWithIdentifier:(nonnull NSString *)identifier features:(nonnull NSArray<DingiShape<DingiFeature> *> *)features options:(nullable NSDictionary<DingiShapeSourceOption, id> *)options;
Parameters
identifier
A string that uniquely identifies the source.
features
An array of objects that conform to the DingiFeature protocol.
options
An
NSDictionary
of options for this source.Return Value
An initialized shape source.
-
Returns a shape source with an identifier, an array of shapes, and a dictionary of options for the source.
This class supports the following options:
DingiShapeSourceOptionClustered
,DingiShapeSourceOptionClusterRadius
,DingiShapeSourceOptionMaximumZoomLevelForClustering
,DingiShapeSourceOptionMinimumZoomLevel
,DingiShapeSourceOptionMaximumZoomLevel
,DingiShapeSourceOptionBuffer
, andDingiShapeSourceOptionSimplificationTolerance
. Shapes provided by a shape source are not clipped or wrapped automatically.Any
DingiFeature
instance passed into this initializer is treated as an ordinary shape, causing any attributes to be inaccessible to anDingiVectorStyleLayer
when evaluating a predicate or configuring certain layout or paint attributes. To preserve the attributes associated with each feature, use the-initWithIdentifier:features:options:
method instead.To create a shape from GeoJSON source code, use the
+[DingiShape shapeWithData:encoding:error:]
method.Declaration
Objective-C
- (nonnull instancetype) initWithIdentifier:(nonnull NSString *)identifier shapes:(nonnull NSArray<DingiShape *> *)shapes options:(nullable NSDictionary<DingiShapeSourceOption, id> *)options;
Swift
convenience init(identifier: String, shapes: [DingiShape], options: [DingiShapeSourceOption : Any]? = nil)
Parameters
identifier
A string that uniquely identifies the source.
shapes
An array of shapes; each shape is a member of a concrete subclass of DingiShape.
options
An
NSDictionary
of options for this source.Return Value
An initialized shape source.
-
The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a collection of features.
If the receiver was initialized using
-initWithIdentifier:URL:options:
, this property is set tonil
. This property is unavailable until the receiver is passed into-[DingiStyle addSource:]
.You can get/set the shapes within a collection via this property. Actions must be performed on the application’s main thread.
Declaration
Objective-C
@property (readwrite, copy, nonatomic, nullable) DingiShape *shape;
Swift
@NSCopying var shape: DingiShape? { get set }
-
The URL to the GeoJSON document that specifies the contents of the source.
If the receiver was initialized using
-initWithIdentifier:shape:options:
, this property is set tonil
.Declaration
Objective-C
@property (readwrite, copy, nonatomic, nullable) NSURL *URL;
Swift
var url: URL? { get set }
-
Returns an array of map features for this source, filtered by the given predicate.
Each object in the returned array represents a feature for the current style and provides access to attributes specified via the
shape
property.Features come from tiled GeoJSON data that is converted to tiles internally, so feature geometries are clipped at tile boundaries and features may appear duplicated across tiles. For example, suppose this source contains a long polyline representing a road. The resulting array includes those parts of the road that lie within the map tiles that the source has loaded, even if the road extends into other tiles. The portion of the road within each map tile is included individually.
Returned features may not necessarily be visible to the user at the time they are loaded: the style may lack a layer that draws the features in question. To obtain only visible features, use the
-[DingiMapView visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate:]
or-[DingiMapView visibleFeaturesInRect:inStyleLayersWithIdentifiers:predicate:]
method.Declaration
Objective-C
- (nonnull NSArray<id<DingiFeature>> *)featuresMatchingPredicate: (nullable NSPredicate *)predicate;
Parameters
predicate
A predicate to filter the returned features. Use
nil
to include all features in the source.Return Value
An array of objects conforming to the
DingiFeature
protocol that represent features in the source that match the predicate.