Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example for how to create an animated marker with WhirlyGlobe/Maply
//
// TBActiveMarker.h
// TrailTracker
//
// Created by Jesse Crocker on 2/10/14.
//
//
#import "WhirlyGlobeComponent.h"
@interface TBActiveMarker : MaplyActiveObject
@property (nonatomic, assign) BOOL needsUpdate;
@property (nonatomic, strong) MaplyScreenMarker *marker;
@property (nonatomic, strong) MaplyScreenLabel *label;
@property (nonatomic, strong) NSDictionary *markerDisplayOptions;
@property (nonatomic, strong) NSDictionary *labelDisplayOptions;
@property (nonatomic, readonly) MaplyComponentObject *markerComponentObject;
@property (nonatomic, readonly) MaplyComponentObject *labelComponentObject;
+ (TBActiveMarker*)activeMarkerForMarker:(MaplyScreenMarker*)marker
displayOptions:(NSDictionary*)displayOptions
inViewC:(MaplyBaseViewController *)inViewC;
- (void)setLocation:(CLLocationCoordinate2D)coord;
- (void)setRotation:(CGFloat)radians;
- (CGFloat)rotation;
- (void)setLoc:(MaplyCoordinate)loc;
@end
//
// TBActiveMarker.mm
// TrailTracker
//
// Created by Jesse Crocker on 2/10/14.
//
//
#import "TBActiveMarker.h"
#import "SceneRendererES.h"
@implementation TBActiveMarker
+ (TBActiveMarker*)activeMarkerForMarker:(MaplyScreenMarker*)marker
displayOptions:(NSDictionary*)displayOptions
inViewC:(MaplyBaseViewController *)inViewC {
TBActiveMarker *activeObject = [[TBActiveMarker alloc] initWithViewController:inViewC];
activeObject.marker = marker;
activeObject.needsUpdate = YES; //so it gets added to the next frame
marker.layoutImportance = MAXFLOAT; //so it doesn't flash
if(displayOptions) {
activeObject.markerDisplayOptions = displayOptions;
} else { //default display options
activeObject.markerDisplayOptions = @{kMaplyMinVis: @(0.0),
kMaplyMaxVis: @(6.0),
kMaplyFade: @(0.0)};
}
return activeObject;
}
- (void)setLocation:(CLLocationCoordinate2D)coord {
_marker.loc = MaplyCoordinateMakeWithDegrees(coord.longitude, coord.latitude);
_needsUpdate = YES;
}
- (void)setLoc:(MaplyCoordinate)loc {
_marker.loc = loc;
_label.loc = loc;
_needsUpdate = YES;
}
- (void)setRotation:(CGFloat)radians {
_marker.rotation = radians;
_needsUpdate = YES;
}
- (CGFloat)rotation {
return _marker.rotation;
}
- (void)updateForFrame:(WhirlyKitRendererFrameInfo *)frameInfo {
if(_needsUpdate && _marker) {
_needsUpdate = false;
MaplyComponentObject *oldMarkerObject = _markerComponentObject;
MaplyComponentObject *oldLabelObject = _labelComponentObject;
if(_marker) {
_markerComponentObject = [self.viewC addScreenMarkers:@[_marker]
desc:_markerDisplayOptions
mode:MaplyThreadCurrent];
}
if(_label) {
_labelComponentObject = [self.viewC addScreenLabels:@[_label]
desc:_labelDisplayOptions
mode:MaplyThreadCurrent];
}
if(oldMarkerObject) {
[self.viewC removeObjects:@[oldMarkerObject]
mode:MaplyThreadCurrent];
}
if(oldLabelObject) {
[self.viewC removeObjects:@[oldLabelObject]
mode:MaplyThreadCurrent];
}
}
}
- (void)shutdown {
if(self.markerComponentObject) {
[self.viewC removeObjects:@[self.markerComponentObject]
mode:MaplyThreadCurrent];
_markerComponentObject = nil;
}
if(self.labelComponentObject) {
[self.viewC removeObjects:@[self.labelComponentObject]
mode:MaplyThreadCurrent];
_labelComponentObject = nil;
}
}
- (bool)hasUpdate {
return _needsUpdate;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.