TGMapData


@interface TGMapData : NSObject

A TGMapData enables you to dynamically create map features to be rendered in the current map scene.

To render features from a TGMapData in your map scene, add a layer in your scene file with a data source set to a new source name. This source name will correspond to the name of your TGMapData instance.

Example:

layers:
    route_line_transit:
       data: { source: route_line_transit_data }
       draw:
           lines:
               color: function() { return feature.color || '#06a6d4'; }
               order: 500
               width: 10px

In your application, create a TGMapData instance with the same name using -[TGMapView addDataLayer:generateCentroid:] and assign map features to it.

Example (Objective-C):

CLLocationCoordinate2D polylinePoints[] = { ... };
TGGeoPolyline *polyline = [[TGGeoPolyline alloc] initWithCoordinates:polylinePoints count:polylinePointCount];
TGFeatureProperties *properties = @{ @"type" : @"line", @"color" : @"#D2655F" };
TGMapFeature *feature = [TGMapFeature mapFeatureWithPolyline:polyline properties:properties];
TGMapData *mapData = [mapView addDataLayer:@"route_line_transit_data", generateCentroid:NO];
[mapData setFeatures:@[feature]];

Example (Swift):

var polyline = TGGeoPolyline(coordinates: polylinePoints, count: polylinePointCount);
var properties = ["type": "line", "color": "#D2655F"];
var feature = TGMapFeature(polyline: polyline, properties: properties);
var mapData = mapView.addDataLayer(name: "mz_route_line_transit_data");
mapData.setFeatures([feature]);
  • Sets the contents of this map data to the specified array of features.

    This replaces any previously assigned contents.

    Declaration

    Objective-C

    - (void)setFeatures:(nonnull NSArray<TGMapFeature *> *)features;

    Swift

    func setFeatures(_ features: [TGMapFeature])

    Parameters

    features

    The array of features to assign.

  • Sets the contents of this map data to the features defined in a GeoJSON string.

    This replaces any previously assigned contents.

    Declaration

    Objective-C

    - (void)setGeoJson:(nonnull NSString *)data;

    Swift

    func setGeoJson(_ data: String)

    Parameters

    data

    A GeoJSON-formatted string.

  • Permanently removes this map data from the map view.

    Any future use of this object will do nothing.

    Declaration

    Objective-C

    - (BOOL)remove;

    Swift

    func remove() -> Bool

    Return Value

    YES if removal was successful.

  • The name of the data source.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull name;

    Swift

    var name: String { get }
  • The map view that created this map data.

    Declaration

    Objective-C

    @property (readonly, nonatomic) TGMapView *_Nullable mapView;

    Swift

    weak var mapView: TGMapView? { get }