Skip to content
Browse files

United base for Maply and WhirlyGlobe Component view controllers and …

…interaction layers. Also fleshed out the subclassing possibilities a bit more.
  • Loading branch information...
1 parent e8acf11 commit f009680eba4040d41e8a78ef1fdb770b1e3c4726 @mousebird mousebird committed
Showing with 1,701 additions and 2,110 deletions.
  1. +33 −1 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/WhirlyGlobe-MaplyComponent.xcodeproj/project.pbxproj
  2. +128 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/MaplyBaseViewController.h
  3. +2 −66 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/MaplyViewController.h
  4. +3 −100 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/WhirlyGlobeViewController.h
  5. +5 −5 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/ImageTexture_private.h
  6. +110 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyBaseInteractionLayer_private.h
  7. +94 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyBaseViewController_private.h
  8. +4 −43 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyInteractionLayer_private.h
  9. +44 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyViewController_private.h
  10. +4 −61 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/WGInteractionLayer_private.h
  11. +6 −51 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/WhirlyGlobeViewController_private.h
  12. +628 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyBaseInteractionLayer.mm
  13. +516 −0 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyBaseViewController.mm
  14. +16 −331 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyInteractionLayer.mm
  15. +29 −404 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyViewController.mm
  16. +4 −578 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/WGInteractionLayer.mm
  17. +35 −460 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/WhirlyGlobeViewController.mm
  18. +40 −10 WhirlyGlobeSrc/WhirlyGlobeComponentTester/WhirlyGlobeComponentTester.xcodeproj/project.pbxproj
View
34 ...yGlobeSrc/WhirlyGlobe-MaplyComponent/WhirlyGlobe-MaplyComponent.xcodeproj/project.pbxproj
@@ -7,6 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
+ 2B0A4DB0167BD795000D5786 /* MaplyBaseViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B0A4DAE167BD795000D5786 /* MaplyBaseViewController.h */; };
+ 2B0A4DB1167BD795000D5786 /* MaplyBaseViewController_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B0A4DAF167BD795000D5786 /* MaplyBaseViewController_private.h */; };
+ 2B0A4DB5167BDAC6000D5786 /* MaplyBaseInteractionLayer_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B0A4DB4167BDAC6000D5786 /* MaplyBaseInteractionLayer_private.h */; };
+ 2B0A4DB8167BDAD3000D5786 /* MaplyBaseInteractionLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B0A4DB6167BDAD3000D5786 /* MaplyBaseInteractionLayer.mm */; };
+ 2B0A4DB9167BDAD3000D5786 /* MaplyBaseViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B0A4DB7167BDAD3000D5786 /* MaplyBaseViewController.mm */; };
+ 2B0A4DC0167BFA7A000D5786 /* MaplyViewController_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B0A4DBF167BFA7A000D5786 /* MaplyViewController_private.h */; };
2B0B0D1315C1D88600CCB3B2 /* MaplyViewTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B0B0D1115C1D88600CCB3B2 /* MaplyViewTracker.h */; };
2B0B0D1415C1D88600CCB3B2 /* MaplyViewTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B0B0D1215C1D88600CCB3B2 /* MaplyViewTracker.m */; };
2B0E934515BF441200B3F95F /* MaplyQuadEarthWithMBTiles.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B0E934315BF441200B3F95F /* MaplyQuadEarthWithMBTiles.mm */; };
@@ -77,6 +83,12 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 2B0A4DAE167BD795000D5786 /* MaplyBaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MaplyBaseViewController.h; path = include/MaplyBaseViewController.h; sourceTree = "<group>"; };
+ 2B0A4DAF167BD795000D5786 /* MaplyBaseViewController_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MaplyBaseViewController_private.h; path = include/private/MaplyBaseViewController_private.h; sourceTree = "<group>"; };
+ 2B0A4DB4167BDAC6000D5786 /* MaplyBaseInteractionLayer_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MaplyBaseInteractionLayer_private.h; path = include/private/MaplyBaseInteractionLayer_private.h; sourceTree = "<group>"; };
+ 2B0A4DB6167BDAD3000D5786 /* MaplyBaseInteractionLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MaplyBaseInteractionLayer.mm; path = src/MaplyBaseInteractionLayer.mm; sourceTree = "<group>"; };
+ 2B0A4DB7167BDAD3000D5786 /* MaplyBaseViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MaplyBaseViewController.mm; path = src/MaplyBaseViewController.mm; sourceTree = "<group>"; };
+ 2B0A4DBF167BFA7A000D5786 /* MaplyViewController_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MaplyViewController_private.h; path = include/private/MaplyViewController_private.h; sourceTree = "<group>"; };
2B0B0D1115C1D88600CCB3B2 /* MaplyViewTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MaplyViewTracker.h; path = include/MaplyViewTracker.h; sourceTree = SOURCE_ROOT; };
2B0B0D1215C1D88600CCB3B2 /* MaplyViewTracker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MaplyViewTracker.m; path = src/MaplyViewTracker.m; sourceTree = SOURCE_ROOT; };
2B0E934315BF441200B3F95F /* MaplyQuadEarthWithMBTiles.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MaplyQuadEarthWithMBTiles.mm; path = src/MaplyQuadEarthWithMBTiles.mm; sourceTree = SOURCE_ROOT; };
@@ -150,6 +162,19 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 2B0A4DBA167BDC42000D5786 /* view controller */ = {
+ isa = PBXGroup;
+ children = (
+ 2BB0718F1676B8EA00DE387D /* MaplyViewControllerLayer.h */,
+ 2B0A4DAE167BD795000D5786 /* MaplyBaseViewController.h */,
+ 2B0A4DAF167BD795000D5786 /* MaplyBaseViewController_private.h */,
+ 2B0A4DB7167BDAD3000D5786 /* MaplyBaseViewController.mm */,
+ 2B0A4DB4167BDAC6000D5786 /* MaplyBaseInteractionLayer_private.h */,
+ 2B0A4DB6167BDAD3000D5786 /* MaplyBaseInteractionLayer.mm */,
+ );
+ name = "view controller";
+ sourceTree = "<group>";
+ };
2B11E0D015B4C030007AAE3F = {
isa = PBXGroup;
children = (
@@ -280,8 +305,8 @@
children = (
2B61D7AC16078A3B007888CF /* MaplyComponent.h */,
2B61D7AD16078A3B007888CF /* MaplyViewController.h */,
+ 2B0A4DBF167BFA7A000D5786 /* MaplyViewController_private.h */,
2B61D7B016078A50007888CF /* MaplyViewController.mm */,
- 2BB0718F1676B8EA00DE387D /* MaplyViewControllerLayer.h */,
2BE88489160A46BA00E92A0A /* MaplyInteractionLayer_private.h */,
2BE8848B160A46C700E92A0A /* MaplyInteractionLayer.mm */,
2B61D7C0160793C1007888CF /* gestures */,
@@ -293,6 +318,7 @@
isa = PBXGroup;
children = (
2BE88485160A437D00E92A0A /* MaplySharedAttributes.h */,
+ 2B0A4DBA167BDC42000D5786 /* view controller */,
2BE88490160A59DE00E92A0A /* utility */,
2B1D05FF15B5CBB300B844C4 /* coordinates */,
2B1D061215B5CE0300B844C4 /* object wrappers */,
@@ -378,6 +404,10 @@
2BB0717B1676B5A800DE387D /* MaplySticker.h in Headers */,
2BB071901676B8EA00DE387D /* MaplyViewControllerLayer.h in Headers */,
2BB071921676B93E00DE387D /* MaplyQuadEarthWithRemoteTiles.h in Headers */,
+ 2B0A4DB0167BD795000D5786 /* MaplyBaseViewController.h in Headers */,
+ 2B0A4DB1167BD795000D5786 /* MaplyBaseViewController_private.h in Headers */,
+ 2B0A4DB5167BDAC6000D5786 /* MaplyBaseInteractionLayer_private.h in Headers */,
+ 2B0A4DC0167BFA7A000D5786 /* MaplyViewController_private.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -469,6 +499,8 @@
2BE8848C160A46C700E92A0A /* MaplyInteractionLayer.mm in Sources */,
2BD115961615E16900A4BF5D /* MaplyShape.mm in Sources */,
2BB0717D1676B5BD00DE387D /* MaplySticker.mm in Sources */,
+ 2B0A4DB8167BDAD3000D5786 /* MaplyBaseInteractionLayer.mm in Sources */,
+ 2B0A4DB9167BDAD3000D5786 /* MaplyBaseViewController.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
128 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/MaplyBaseViewController.h
@@ -0,0 +1,128 @@
+/*
+ * MaplyBaseViewController.h
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import <UIKit/UIKit.h>
+#import "MaplyCoordinate.h"
+#import "MaplyScreenMarker.h"
+#import "MaplyVectorObject.h"
+#import "MaplyViewTracker.h"
+#import "MaplyComponentObject.h"
+#import "MaplySharedAttributes.h"
+#import "MaplyViewControllerLayer.h"
+
+/** The MaplyBaseViewController is the base class for the Maply and WhirlyGlobe
+ view controllers. Most of its functionality is private, but you can use
+ those view controllers instead.
+ */
+@interface MaplyBaseViewController : UIViewController
+
+/// Set selection support on or off here
+@property(nonatomic,assign) bool selection;
+
+/// Set the globe view's background color.
+/// Black, by default.
+@property (nonatomic,strong) UIColor *clearColor;
+
+/// Add rendering and other general hints for the globe view controller.
+- (void)setHints:(NSDictionary *)hintsDict;
+
+/// Add a quad tree paged earth layer with MapBox Tiles on top
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name;
+
+/// Add a quad tree paged earth layer with
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithRemoteSource:(NSString *)baseURL imageExt:(NSString *)ext cache:(NSString *)cachdDir minZoom:(int)minZoom maxZoom:(int)maxZoom;
+
+/// Add visual defaults for the screen markers
+- (void)setScreenMarkerDesc:(NSDictionary *)desc;
+
+/// Add a group of screen (2D) markers
+- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers;
+
+/// Add visual defaults for the markers
+- (void)setMarkerDesc:(NSDictionary *)desc;
+
+/// Add a group of 3D markers
+- (MaplyComponentObject *)addMarkers:(NSArray *)markers;
+
+/// Add visual defaults for the screen labels
+- (void)setScreenLabelDesc:(NSDictionary *)desc;
+
+/// Add a group of screen (2D) labels
+- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels;
+
+/// Add visual defaults for the labels
+- (void)setLabelDesc:(NSDictionary *)desc;
+
+/// Add a group of 3D labels
+- (MaplyComponentObject *)addLabels:(NSArray *)labels;
+
+/// Add visual defaults for the vectors
+- (void)setVectorDesc:(NSDictionary *)desc;
+
+/// Add one or more vectors
+- (MaplyComponentObject *)addVectors:(NSArray *)vectors;
+
+/// Add one or more vectors, but only for selection
+- (MaplyComponentObject *)addSelectionVectors:(NSArray *)vectors;
+
+/// Change the representation for the given vector object(s).
+/// Only a few things are changeable, such as color
+- (void)changeVector:(MaplyComponentObject *)compObj desc:(NSDictionary *)desc;
+
+/// Add visual defaults for the shapes
+- (void)setShapeDesc:(NSDictionary *)desc;
+
+/// Add one or more shapes
+- (MaplyComponentObject *)addShapes:(NSArray *)shapes;
+
+/// Add visual defaults for the stickers
+- (void)setStickerDesc:(NSDictionary *)desc;
+
+/// Add one or more stickers
+- (MaplyComponentObject *)addStickers:(NSArray *)stickers;
+
+/// Add a view to track to a particular location
+- (void)addViewTracker:(MaplyViewTracker *)viewTrack;
+
+/// Remove the view tracker associated with the given UIView
+- (void)removeViewTrackForView:(UIView *)view;
+
+/// Remove the data associated with an object the user added earlier
+- (void)removeObject:(MaplyComponentObject *)theObj;
+
+/// Remove an array of data objects
+- (void)removeObjects:(NSArray *)theObjs;
+
+/// Remove a single layer
+- (void)removeLayer:(MaplyViewControllerLayer *)layer;
+
+/// Remove all the base layers (e.g map layers)
+- (void)removeAllLayers;
+
+/// This utility routine will convert a lat/lon (in radians) to display coordinates
+- (MaplyCoordinate3d)displayPointFromGeo:(MaplyCoordinate)geoCoord;
+
+/// Start animation (only if it's been paused)
+- (void)startAnimation;
+
+/// Pause animation (probably because we're going into the background)
+- (void)stopAnimation;
+
+@end
View
68 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/MaplyViewController.h
@@ -25,6 +25,7 @@
#import "MaplyViewTracker.h"
#import "MaplyComponentObject.h"
#import "MaplySharedAttributes.h"
+#import "MaplyBaseViewController.h"
@class MaplyViewControllerLayer;
@class MaplyViewController;
@@ -49,7 +50,7 @@
your view hirarchy and start tossing in data. You'll want a base layer at the
very least and then you can add markers, labels, and vectors on top.
*/
-@interface MaplyViewController : UIViewController
+@interface MaplyViewController : MaplyBaseViewController
{
NSObject<MaplyViewControllerDelegate> * __weak delegate;
}
@@ -65,20 +66,10 @@
/// Set this to get callbacks for various events.
@property(nonatomic,weak) NSObject<MaplyViewControllerDelegate> *delegate;
-/// Set selection support on or off here
-@property(nonatomic,assign) bool selection;
-
-/// Set the globe view's background color.
-/// Black, by default.
-@property (nonatomic,strong) UIColor *clearColor;
-
/// Get/set the current height above terrain.
/// The radius of the earth is 1.0. Height above terrain is relative to that.
@property (nonatomic,assign) float height;
-/// Add rendering and other general hints for the globe view controller.
-- (void)setHints:(NSDictionary *)hintsDict;
-
/// Animate to the given position over the given amount of time
- (void)animateToPosition:(WGCoordinate)newPos time:(NSTimeInterval)howLong;
@@ -88,59 +79,4 @@
/// Set position and height at the same time
- (void)setPosition:(WGCoordinate)newPos height:(float)height;
-
-/// Add a quad tree paged earth layer with MapBox Tiles on top
-- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name;
-
-/// Add a quad tree paged earth layer with
-- (MaplyViewControllerLayer *)addQuadEarthLayerWithRemoteSource:(NSString *)baseURL imageExt:(NSString *)ext cache:(NSString *)cachdDir minZoom:(int)minZoom maxZoom:(int)maxZoom;
-
-/// Add visual defaults for the screen markers
-- (void)setScreenMarkerDesc:(NSDictionary *)desc;
-
-/// Add a group of screen (2D) markers
-- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers;
-
-/// Add visual defaults for the markers
-- (void)setMarkerDesc:(NSDictionary *)desc;
-
-/// Add a group of 3D markers
-- (WGComponentObject *)addMarkers:(NSArray *)markers;
-
-/// Add visual defaults for the screen labels
-- (void)setScreenLabelDesc:(NSDictionary *)desc;
-
-/// Add a group of screen (2D) labels
-- (WGComponentObject *)addScreenLabels:(NSArray *)labels;
-
-/// Add visual defaults for the labels
-- (void)setLabelDesc:(NSDictionary *)desc;
-
-/// Add a group of 3D labels
-- (WGComponentObject *)addLabels:(NSArray *)labels;
-
-/// Add visual defaults for the vectors
-- (void)setVectorDesc:(NSDictionary *)desc;
-
-/// Add one or more vectors
-- (WGComponentObject *)addVectors:(NSArray *)vectors;
-
-/// Add visual defaults for the shapes
-- (void)setShapeDesc:(NSDictionary *)desc;
-
-/// Add one or more shapes
-- (WGComponentObject *)addShapes:(NSArray *)shapes;
-
-/// Add a view to track to a particular location
-- (void)addViewTracker:(WGViewTracker *)viewTrack;
-
-/// Remove the view tracker associated with the given UIView
-- (void)removeViewTrackForView:(UIView *)view;
-
-/// Remove the data associated with an object the user added earlier
-- (void)removeObject:(WGComponentObject *)theObj;
-
-/// Remove an array of data objects
-- (void)removeObjects:(NSArray *)theObjs;
-
@end
View
103 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/WhirlyGlobeViewController.h
@@ -19,12 +19,7 @@
*/
#import <UIKit/UIKit.h>
-#import <WGCoordinate.h>
-#import "MaplyScreenMarker.h"
-#import "MaplyVectorObject.h"
-#import "MaplyViewTracker.h"
-#import "MaplyComponentObject.h"
-#import "MaplySharedAttributes.h"
+#import "MaplyBaseViewController.h"
@class WGViewControllerLayer;
@class WhirlyGlobeViewController;
@@ -59,7 +54,7 @@
At the very least you'll want a base image layer and then you can put
markers, labels, and vectors on top of that.
*/
-@interface WhirlyGlobeViewController : UIViewController
+@interface WhirlyGlobeViewController : MaplyBaseViewController
{
NSObject<WhirlyGlobeViewControllerDelegate> * __weak delegate;
}
@@ -79,13 +74,6 @@
/// Set this to get callbacks for various events.
@property(nonatomic,weak) NSObject<WhirlyGlobeViewControllerDelegate> *delegate;
-/// Set selection support on or off here
-@property(nonatomic,assign) bool selection;
-
-/// Set the globe view's background color.
-/// Black, by default.
-@property (nonatomic,strong) UIColor *clearColor;
-
/// Get/set the current height above terrain.
/// The radius of the earth is 1.0. Height above terrain is relative to that.
@property (nonatomic,assign) float height;
@@ -100,11 +88,8 @@
/// after that interval the given number of degrees per second
- (void)setAutoRotateInterval:(float)autoRotateInterval degrees:(float)autoRotateDegrees;
-/// Add rendering and other general hints for the globe view controller.
-- (void)setHints:(NSDictionary *)hintsDict;
-
/// Animate to the given position over the given amount of time
-- (void)animateToPosition:(WGCoordinate)newPos time:(NSTimeInterval)howLong;
+- (void)animateToPosition:(MaplyCoordinate)newPos time:(NSTimeInterval)howLong;
/// Animate the given position to the given screen location over time.
/// If this isn't physically possible, it will just do nothing
@@ -122,89 +107,7 @@
/// Add a spherical earth layer with the given set of base images
- (WGViewControllerLayer *)addSphericalEarthLayerWithImageSet:(NSString *)name;
-/// Add a quad tree paged earth layer with MapBox Tiles on top
-- (WGViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name;
-
-/// Add a quad tree paged earth layer with
-- (WGViewControllerLayer *)addQuadEarthLayerWithRemoteSource:(NSString *)baseURL imageExt:(NSString *)ext cache:(NSString *)cachdDir minZoom:(int)minZoom maxZoom:(int)maxZoom;
-
-/// Add visual defaults for the screen markers
-- (void)setScreenMarkerDesc:(NSDictionary *)desc;
-
-/// Add a group of screen (2D) markers
-- (WGComponentObject *)addScreenMarkers:(NSArray *)markers;
-
-/// Add visual defaults for the markers
-- (void)setMarkerDesc:(NSDictionary *)desc;
-
-/// Add a group of 3D markers
-- (WGComponentObject *)addMarkers:(NSArray *)markers;
-
-/// Add visual defaults for the screen labels
-- (void)setScreenLabelDesc:(NSDictionary *)desc;
-
-/// Add a group of screen (2D) labels
-- (WGComponentObject *)addScreenLabels:(NSArray *)labels;
-
-/// Add visual defaults for the labels
-- (void)setLabelDesc:(NSDictionary *)desc;
-
-/// Add a group of 3D labels
-- (WGComponentObject *)addLabels:(NSArray *)labels;
-
-/// Add visual defaults for the vectors
-- (void)setVectorDesc:(NSDictionary *)desc;
-
-/// Add one or more vectors
-- (WGComponentObject *)addVectors:(NSArray *)vectors;
-
-/// Add one or more vectors, but only for selection
-- (WGComponentObject *)addSelectionVectors:(NSArray *)vectors;
-
-/// Change the representation for the given vector object(s).
-/// Only a few things are changeable, such as color
-- (void)changeVector:(WGComponentObject *)compObj desc:(NSDictionary *)desc;
-
-/// Add visual defaults for the shapes
-- (void)setShapeDesc:(NSDictionary *)desc;
-
-/// Add one or more shapes
-- (WGComponentObject *)addShapes:(NSArray *)shapes;
-
-/// Add visual defaults for the stickers
-- (void)setStickerDesc:(NSDictionary *)desc;
-
-/// Add one or more stickers
-- (WGComponentObject *)addStickers:(NSArray *)stickers;
-
-/// Add a view to track to a particular location
-- (void)addViewTracker:(WGViewTracker *)viewTrack;
-
-/// Remove the view tracker associated with the given UIView
-- (void)removeViewTrackForView:(UIView *)view;
-
-/// Remove the data associated with an object the user added earlier
-- (void)removeObject:(WGComponentObject *)theObj;
-
-/// Remove an array of data objects
-- (void)removeObjects:(NSArray *)theObjs;
-
-/// Remove a single layer
-- (void)removeLayer:(WGViewControllerLayer *)layer;
-
-/// Remove all the base layers (e.g map layers)
-- (void)removeAllLayers;
-
-/// This utility routine will convert a lat/lon (in radians) to display coordinates
-- (MaplyCoordinate3d)displayPointFromGeo:(MaplyCoordinate)geoCoord;
-
/// This utility routine returns the on screen location for a coordinate in lat/lon
- (CGPoint)screenPointFromGeo:(MaplyCoordinate)geoCoord;
-/// Start animation (only if it's been paused)
-- (void)startAnimation;
-
-/// Pause animation (probably because we're going into the background)
-- (void)stopAnimation;
-
@end
View
10 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/ImageTexture_private.h
@@ -21,14 +21,14 @@
#import <WhirlyGlobe.h>
// Used to map UIImages to Texture IDs
-class ImageTexture
+class MaplyImageTexture
{
public:
- ImageTexture(UIImage *image) : image(image), texID(WhirlyKit::EmptyIdentity) { }
- ImageTexture(UIImage *image,WhirlyKit::SimpleIdentity texID) : image(image), texID(texID) { }
- bool operator < (const ImageTexture &that) const { return image < that.image; }
+ MaplyImageTexture(UIImage *image) : image(image), texID(WhirlyKit::EmptyIdentity) { }
+ MaplyImageTexture(UIImage *image,WhirlyKit::SimpleIdentity texID) : image(image), texID(texID) { }
+ bool operator < (const MaplyImageTexture &that) const { return image < that.image; }
UIImage *image;
WhirlyKit::SimpleIdentity texID;
};
-typedef std::set<ImageTexture> ImageTextureSet;
+typedef std::set<MaplyImageTexture> MaplyImageTextureSet;
View
110 ...lyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyBaseInteractionLayer_private.h
@@ -0,0 +1,110 @@
+/*
+ * MaplyBaseInteractionLayer_private.h
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import <Foundation/Foundation.h>
+#import <set>
+#import <WhirlyGlobe.h>
+#import "MaplyComponentObject_private.h"
+#import "SelectObject_private.h"
+#import "ImageTexture_private.h"
+
+@interface MaplyBaseInteractionLayer : NSObject<WhirlyKitLayer>
+{
+@public
+ WhirlyKitMarkerLayer * __weak markerLayer;
+ WhirlyKitLabelLayer * __weak labelLayer;
+ WhirlyKitVectorLayer * __weak vectorLayer;
+ WhirlyKitShapeLayer * __weak shapeLayer;
+ WhirlyKitSphericalChunkLayer * __weak chunkLayer;
+ WhirlyKitSelectionLayer * __weak selectLayer;
+ // Note: Not a great idea to be passing this in
+ UIView * __weak glView;
+
+ WhirlyKitView * __weak visualView;
+
+ // Use to map IDs in the selection layer to objects the user passed in
+ SelectObjectSet selectObjectSet;
+
+ // Layer thread we're part of
+ WhirlyKitLayerThread * __weak layerThread;
+
+ // Scene we're using
+ WhirlyKit::Scene *scene;
+
+ // Used to track textures
+ MaplyImageTextureSet imageTextures;
+
+ // Component objects created for the user
+ NSMutableArray *userObjects;
+}
+
+@property (nonatomic,weak) WhirlyKitMarkerLayer * markerLayer;
+@property (nonatomic,weak) WhirlyKitLabelLayer * labelLayer;
+@property (nonatomic,weak) WhirlyKitVectorLayer * vectorLayer;
+@property (nonatomic,weak) WhirlyKitShapeLayer * shapeLayer;
+@property (nonatomic,weak) WhirlyKitSphericalChunkLayer *chunkLayer;
+@property (nonatomic,weak) WhirlyKitSelectionLayer * selectLayer;
+@property (nonatomic,weak) UIView * glView;
+
+// Initialize with the view we'll be using
+- (id)initWithView:(WhirlyKitView *)visualView;
+
+// Add screen space (2D) markers
+- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
+
+// Add 3D markers
+- (MaplyComponentObject *)addMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
+
+// Add screen space (2D) labels
+- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels desc:(NSDictionary *)desc;
+
+// Add 3D labels
+- (MaplyComponentObject *)addLabels:(NSArray *)labels desc:(NSDictionary *)desc;
+
+// Add vectors
+- (MaplyComponentObject *)addVectors:(NSArray *)vectors desc:(NSDictionary *)desc;
+
+// Add vectors that we'll only use for selection
+- (MaplyComponentObject *)addSelectionVectors:(NSArray *)vectors desc:(NSDictionary *)desc;
+
+// Change vector representation
+- (void)changeVectors:(MaplyComponentObject *)vecObj desc:(NSDictionary *)desc;
+
+// Add shapes
+- (MaplyComponentObject *)addShapes:(NSArray *)shapes desc:(NSDictionary *)desc;
+
+// Add stickers
+- (MaplyComponentObject *)addStickers:(NSArray *)stickers desc:(NSDictionary *)desc;
+
+// Remove objects associated with the user object
+- (void)removeObject:(MaplyComponentObject *)userObj;
+
+// Remove objects associated with the user objects
+- (void)removeObjects:(NSArray *)userObjs;
+
+///// Internal routines. Don't ever call these outside of the layer thread.
+
+// An internal routine to add an image to our local UIImage/ID cache
+- (WhirlyKit::SimpleIdentity)addImage:(UIImage *)image;
+
+// Do a point in poly check for vectors we're representing
+- (NSObject *)findVectorInPoint:(WhirlyKit::Point2f)pt;
+
+@end
View
94 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyBaseViewController_private.h
@@ -0,0 +1,94 @@
+/*
+ * MaplyBaseViewController_private.h
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import <UIKit/UIKit.h>
+
+#import "MaplyBaseViewController.h"
+#import "MaplyViewControllerLayer_private.h"
+#import "MaplyComponentObject_private.h"
+#import "WGInteractionLayer_private.h"
+#import "PanDelegateFixed.h"
+#import "PinchDelegateFixed.h"
+#import "MaplyQuadEarthWithMBTiles_private.h"
+#import "MaplyQuadEarthWithRemoteTiles_private.h"
+#import "MaplyBaseInteractionLayer_private.h"
+
+@interface MaplyBaseViewController()
+{
+@public
+ WhirlyKitEAGLView *glView;
+ WhirlyKitSceneRendererES1 *sceneRenderer;
+
+ WhirlyKitLayerThread *layerThread;
+
+ // The standard set of layers we create
+ WhirlyKitMarkerLayer *markerLayer;
+ WhirlyKitLabelLayer *labelLayer;
+ WhirlyKitVectorLayer *vectorLayer;
+ WhirlyKitShapeLayer *shapeLayer;
+ WhirlyKitSphericalChunkLayer *chunkLayer;
+ WhirlyKitLayoutLayer *layoutLayer;
+ WhirlyKitSelectionLayer *selectLayer;
+
+ // Our own interaction layer does most of the work
+ MaplyBaseInteractionLayer *interactLayer;
+
+ // Layers (and associated data) created for the user
+ NSMutableArray *userLayers;
+
+ // List of views we're tracking for location
+ NSMutableArray *viewTrackers;
+
+ // If set we'll look for selectables
+ bool selection;
+
+ // General rendering and other display hints
+ NSDictionary *hints;
+
+ // Default description dictionaries for the various data types
+ NSDictionary *screenMarkerDesc,*markerDesc,*screenLabelDesc,*labelDesc,*vectorDesc,*shapeDesc,*stickerDesc;
+
+ // Clear color we're using
+ UIColor *theClearColor;
+
+ /// Pointer to the scene. The subclasses are keeping pointers with their specific subclass.
+ WhirlyKit::Scene *scene;
+
+ /// A pointer to the 3D view. The subclasses are keeping points with the right subclass.
+ WhirlyKitView *visualView;
+}
+
+/// This is called by the subclasses. Don't call it yourself.
+- (void) clear;
+
+/// LoadSetup is where the Component does all the WhirlyGlobe/Maply specific setup. If you override this,
+/// be sure to call [super loadSetup] first and then do your thing.
+- (void) loadSetup;
+
+/// If you have your own WhirlyGlobeView or MaplyView subclass, set it up here
+- (WhirlyKitView *) loadSetup_view;
+
+/// For loading the Maply or Globe view. The subclasses call this, but you shouldn't
+- (WhirlyKit::Scene *) loadSetup_scene;
+
+/// The base classes fill this in to return their own interaction layer subclass
+- (MaplyBaseInteractionLayer *) loadSetup_interactionLayer;
+
+@end
View
47 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyInteractionLayer_private.h
@@ -19,10 +19,7 @@
*/
#import <Foundation/Foundation.h>
-#import <set>
-#import <WhirlyGlobe.h>
-#import "MaplyComponentObject_private.h"
-#import "SelectObject_private.h"
+#import "MaplyBaseInteractionLayer_private.h"
// The view controller fills this in
@protocol MaplyInteractionLayerDelegate <NSObject>
@@ -33,52 +30,16 @@
/** The Interaction Layer runs in the layer thread (mostly) and manages
data added to the scene and various other layers.
*/
-@interface MaplyInteractionLayer : NSObject<WhirlyKitLayer>
+@interface MaplyInteractionLayer : MaplyBaseInteractionLayer
{
- WhirlyKitMarkerLayer * __weak markerLayer;
- WhirlyKitLabelLayer * __weak labelLayer;
- WhirlyKitVectorLayer * __weak vectorLayer;
- WhirlyKitSelectionLayer * __weak selectLayer;
- // Note: This is not a good idea
- UIView * __weak glView;
-
- // Component objects created for the user
- NSMutableArray *userObjects;
-
// The view controller, for various callbacks
NSObject<MaplyInteractionLayerDelegate> * __weak viewController;
-
- // Use to map IDs in the selection layer to objects the user passed in
- SelectObjectSet selectObjectSet;
}
-@property (nonatomic,weak) WhirlyKitMarkerLayer * markerLayer;
-@property (nonatomic,weak) WhirlyKitLabelLayer * labelLayer;
-@property (nonatomic,weak) WhirlyKitVectorLayer * vectorLayer;
-@property (nonatomic,weak) WhirlyKitSelectionLayer * selectLayer;
-@property (nonatomic,weak) UIView * glView;
@property (nonatomic,weak) NSObject<MaplyInteractionLayerDelegate> * viewController;
-// Add screen space (2D) markers
-- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
-
-// Add 3D markers
-- (MaplyComponentObject *)addMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
-
-// Add screen space (2D) labels
-- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels desc:(NSDictionary *)desc;
-
-// Add 3D labels
-- (MaplyComponentObject *)addLabels:(NSArray *)labels desc:(NSDictionary *)desc;
-
-// Add vectors
-- (MaplyComponentObject *)addVectors:(NSArray *)vectors desc:(NSDictionary *)desc;
-
-// Remove objects associated with the user object
-- (void)removeObject:(MaplyComponentObject *)userObj;
-
-// Remove objects associated with the user objects
-- (void)removeObjects:(NSArray *)userObjs;
+// Create with the map view
+- (id)initWithMapView:(MaplyView *)inMapView;
// Call this to process a tap with the selection layer
// It will call the given selector if there was no selection
View
44 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyViewController_private.h
@@ -0,0 +1,44 @@
+/*
+ * MaplyViewController_private.h
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import "MaplyViewController.h"
+#import "MaplyBaseViewController_private.h"
+#import "MaplyInteractionLayer_private.h"
+
+@interface MaplyViewController()
+{
+ // Custom map scene
+ Maply::MapScene *mapScene;
+ // Maply view
+ MaplyView *mapView;
+
+ // Coordinate system and display adapter
+ WhirlyKit::SphericalMercatorDisplayAdapter *coordAdapter;
+
+ // Our own interaction layer for adding and removing things
+ MaplyInteractionLayer *mapInteractLayer;
+
+ // Gesture recognizers
+ MaplyTapDelegate *tapDelegate;
+ MaplyPanDelegate *panDelegate;
+ MaplyPinchDelegate *pinchDelegate;
+}
+
+@end
View
65 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/WGInteractionLayer_private.h
@@ -19,10 +19,7 @@
*/
#import <Foundation/Foundation.h>
-#import <set>
-#import <WhirlyGlobe.h>
-#import "MaplyComponentObject_private.h"
-#import "SelectObject_private.h"
+#import "MaplyBaseInteractionLayer_private.h"
// The view controller fills this in
@protocol WGInteractionLayerDelegate <NSObject>
@@ -33,27 +30,13 @@
/** The Interaction Layer runs in the layer thread (mostly) and manages
data added to the scene and various other layers.
*/
-@interface WGInteractionLayer : NSObject<WhirlyKitLayer>
+@interface WGInteractionLayer : MaplyBaseInteractionLayer
{
- WhirlyKitMarkerLayer * __weak markerLayer;
- WhirlyKitLabelLayer * __weak labelLayer;
- WhirlyKitVectorLayer * __weak vectorLayer;
- WhirlyKitShapeLayer * __weak shapeLayer;
- WhirlyKitSphericalChunkLayer * __weak chunkLayer;
- WhirlyKitSelectionLayer * __weak selectLayer;
WhirlyGlobeView * __weak globeView;
- // Note: This is not a good idea
- UIView * __weak glView;
-
- // Component objects created for the user
- NSMutableArray *userObjects;
-
+
// The view controller, for various callbacks
NSObject<WGInteractionLayerDelegate> * __weak viewController;
-
- // Use to map IDs in the selection layer to objects the user passed in
- SelectObjectSet selectObjectSet;
-
+
// If set, we'll autorotate after a certain amount of time
float autoRotateInterval,autoRotateDegrees;
@@ -61,13 +44,6 @@
NSTimeInterval lastTouched;
}
-@property (nonatomic,weak) WhirlyKitMarkerLayer * markerLayer;
-@property (nonatomic,weak) WhirlyKitLabelLayer * labelLayer;
-@property (nonatomic,weak) WhirlyKitVectorLayer * vectorLayer;
-@property (nonatomic,weak) WhirlyKitShapeLayer * shapeLayer;
-@property (nonatomic,weak) WhirlyKitSphericalChunkLayer *chunkLayer;
-@property (nonatomic,weak) WhirlyKitSelectionLayer * selectLayer;
-@property (nonatomic,weak) UIView * glView;
@property (nonatomic,weak) NSObject<WGInteractionLayerDelegate> * viewController;
// Initialize with the globeView
@@ -76,39 +52,6 @@
// Set the autorotate values
- (void)setAutoRotateInterval:(float)autoRotateInterval degrees:(float)autoRotateDegrees;
-// Add screen space (2D) markers
-- (WGComponentObject *)addScreenMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
-
-// Add 3D markers
-- (WGComponentObject *)addMarkers:(NSArray *)markers desc:(NSDictionary *)desc;
-
-// Add screen space (2D) labels
-- (WGComponentObject *)addScreenLabels:(NSArray *)labels desc:(NSDictionary *)desc;
-
-// Add 3D labels
-- (WGComponentObject *)addLabels:(NSArray *)labels desc:(NSDictionary *)desc;
-
-// Add vectors
-- (WGComponentObject *)addVectors:(NSArray *)vectors desc:(NSDictionary *)desc;
-
-// Add vectors that we'll only use for selection
-- (WGComponentObject *)addSelectionVectors:(NSArray *)vectors desc:(NSDictionary *)desc;
-
-// Change vector representation
-- (void)changeVectors:(WGComponentObject *)vecObj desc:(NSDictionary *)desc;
-
-// Add shapes
-- (WGComponentObject *)addShapes:(NSArray *)shapes desc:(NSDictionary *)desc;
-
-// Add stickers
-- (WGComponentObject *)addStickers:(NSArray *)stickers desc:(NSDictionary *)desc;
-
-// Remove objects associated with the user object
-- (void)removeObject:(WGComponentObject *)userObj;
-
-// Remove objects associated with the user objects
-- (void)removeObjects:(NSArray *)userObjs;
-
// Call this to process a tap with the selection layer
// It will call the given selector if there was no selection
- (void) userDidTap:(WhirlyGlobeTapMessage *)msg;
View
57 ...lyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/WhirlyGlobeViewController_private.h
@@ -21,71 +21,26 @@
#import <UIKit/UIKit.h>
#import <WhirlyGlobe.h>
#import "WhirlyGlobeViewController.h"
-#import "MaplyViewControllerLayer_private.h"
-#import "MaplyComponentObject_private.h"
-#import "WGInteractionLayer_private.h"
-#import "PanDelegateFixed.h"
-#import "PinchDelegateFixed.h"
+#import "MaplyBaseViewController_private.h"
#import "WGSphericalEarthWithTexGroup_private.h"
-#import "MaplyQuadEarthWithMBTiles_private.h"
-#import "MaplyQuadEarthWithRemoteTiles_private.h"
/// This is the private interface to WhirlyGlobeViewController.
/// Only pull this in if you're subclassing
@interface WhirlyGlobeViewController()
{
-@public
- WhirlyKitEAGLView *glView;
- WhirlyKitSceneRendererES1 *sceneRenderer;
-
+@public
WhirlyGlobe::GlobeScene *globeScene;
WhirlyGlobeView *globeView;
- WhirlyKitLayerThread *layerThread;
-
- // The standard set of layers we create
- WhirlyKitMarkerLayer *markerLayer;
- WhirlyKitLabelLayer *labelLayer;
- WhirlyKitVectorLayer *vectorLayer;
- WhirlyKitShapeLayer *shapeLayer;
- WhirlyKitSphericalChunkLayer *chunkLayer;
- WhirlyKitLayoutLayer *layoutLayer;
- WhirlyKitSelectionLayer *selectLayer;
-
- // Our own interaction layer does most of the work
- WGInteractionLayer *interactLayer;
-
- // Layers (and associated data) created for the user
- NSMutableArray *userLayers;
-
+ // Local interaction layer
+ WGInteractionLayer *globeInteractLayer;
+
// Gesture recognizers
WGPinchDelegateFixed *pinchDelegate;
PanDelegateFixed *panDelegate;
WhirlyGlobeTapDelegate *tapDelegate;
WhirlyGlobeRotateDelegate *rotateDelegate;
- AnimateViewRotation *animateRotation;
-
- // List of views we're tracking for location
- NSMutableArray *viewTrackers;
-
- // If set we'll look for selectables
- bool selection;
-
- // General rendering and other display hints
- NSDictionary *hints;
-
- // Default description dictionaries for the various data types
- NSDictionary *screenMarkerDesc,*markerDesc,*screenLabelDesc,*labelDesc,*vectorDesc,*shapeDesc,*stickerDesc;
-
- // Clear color we're using
- UIColor *theClearColor;
+ AnimateViewRotation *animateRotation;
}
-/// LoadSetup is where the Component does all the WhirlyGlobe specific setup. If you override this,
-/// be sure to call [super loadSetup] first and then do your thing.
-- (void) loadSetup;
-
-/// If you have your own WhirlyGlobeView subclass, set it up here
-- (void) loadSetup_view;
-
@end
View
628 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyBaseInteractionLayer.mm
@@ -0,0 +1,628 @@
+/*
+ * MaplyBaseInteractionLayer.mm
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import "MaplyBaseInteractionLayer_private.h"
+#import "MaplyScreenMarker.h"
+#import "MaplyMarker.h"
+#import "MaplyScreenLabel.h"
+#import "MaplyLabel.h"
+#import "MaplyVectorObject_private.h"
+#import "MaplyShape.h"
+#import "MaplySticker.h"
+#import "MaplyCoordinate.h"
+#import "ImageTexture_private.h"
+
+using namespace Eigen;
+using namespace WhirlyKit;
+
+// Sample a great circle and throw in an interpolated height at each point
+void SampleGreatCircle(MaplyCoordinate startPt,MaplyCoordinate endPt,float height,std::vector<Point3f> &pts,WhirlyKit::CoordSystemDisplayAdapter *coordAdapter)
+{
+ Point3f p0 = coordAdapter->localToDisplay(coordAdapter->getCoordSystem()->geographicToLocal(GeoCoord(startPt.x,startPt.y)));
+ Point3f p1 = coordAdapter->localToDisplay(coordAdapter->getCoordSystem()->geographicToLocal(GeoCoord(endPt.x,endPt.y)));
+
+ // Note: Dumb approach. Switch to an adaptive sampling
+ int numSamples = 300;
+ for (unsigned int ii=0;ii<=numSamples;ii++)
+ {
+ // Sample the point
+ float t = (ii/(float)numSamples);
+ Point3f pt = (p1-p0)*t + p0;
+ // This puts us on the surface of the sphere
+ pt.normalize();
+
+ // Parabolic curve
+ float b = 4*height;
+ float a = -b;
+ float thisHeight = a*(t*t) + b*t;
+
+ pt *= 1.0+thisHeight;
+ pts.push_back(pt);
+ }
+}
+
+@implementation MaplyBaseInteractionLayer
+
+@synthesize markerLayer;
+@synthesize labelLayer;
+@synthesize vectorLayer;
+@synthesize shapeLayer;
+@synthesize chunkLayer;
+@synthesize selectLayer;
+@synthesize glView;
+
+- (id)initWithView:(WhirlyKitView *)inVisualView
+{
+ self = [super init];
+ if (!self)
+ return nil;
+ visualView = inVisualView;
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
+}
+
+- (void)startWithThread:(WhirlyKitLayerThread *)inLayerThread scene:(WhirlyKit::Scene *)inScene
+{
+ layerThread = inLayerThread;
+ scene = (WhirlyGlobe::GlobeScene *)inScene;
+ userObjects = [NSMutableArray array];
+}
+
+- (void)shutdown
+{
+ layerThread = nil;
+ scene = NULL;
+ imageTextures.clear();
+}
+
+// Add an image to the cache, or find an existing one
+// Called in the layer thread
+- (SimpleIdentity)addImage:(UIImage *)image
+{
+ // Look for an existing one
+ MaplyImageTextureSet::iterator it = imageTextures.find(MaplyImageTexture(image));
+ if (it != imageTextures.end())
+ return it->texID;
+
+ // Add it and download it
+ Texture *tex = new Texture(image);
+ // tex->createInGL(YES, scene->getMemManager());
+ scene->addChangeRequest(new AddTextureReq(tex));
+
+ // Add to our cache
+ MaplyImageTexture newTex(image,tex->getId());
+ imageTextures.insert(newTex);
+
+ return newTex.texID;
+}
+
+// Actually add the markers.
+// Called in the layer thread.
+- (void)addScreenMarkersLayerThread:(NSArray *)argArray
+{
+ NSArray *markers = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+
+ // Convert to WG markers
+ NSMutableArray *wgMarkers = [NSMutableArray array];
+ for (MaplyScreenMarker *marker in markers)
+ {
+ WhirlyKitMarker *wgMarker = [[WhirlyKitMarker alloc] init];
+ wgMarker.loc = GeoCoord(marker.loc.x,marker.loc.y);
+ SimpleIdentity texID = EmptyIdentity;
+ if (marker.image)
+ texID = [self addImage:marker.image];
+ if (texID != EmptyIdentity)
+ wgMarker.texIDs.push_back(texID);
+ wgMarker.width = marker.size.width;
+ wgMarker.height = marker.size.height;
+ if (marker.selectable)
+ {
+ wgMarker.isSelectable = true;
+ wgMarker.selectID = Identifiable::genId();
+ }
+
+ [wgMarkers addObject:wgMarker];
+
+ if (marker.selectable)
+ selectObjectSet.insert(SelectObject(wgMarker.selectID,marker));
+ }
+
+ // Set up a description and create the markers in the marker layer
+ NSMutableDictionary *desc = [NSMutableDictionary dictionaryWithDictionary:inDesc];
+ [desc setObject:[NSNumber numberWithBool:YES] forKey:@"screen"];
+ SimpleIdentity markerID = [markerLayer addMarkers:wgMarkers desc:desc];
+ compObj.markerIDs.insert(markerID);
+
+ [userObjects addObject:compObj];
+}
+
+// Called in the main thread.
+- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:markers, compObj, [NSDictionary dictionaryWithDictionary:desc], nil];
+ [self performSelector:@selector(addScreenMarkersLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Actually add the markers.
+// Called in the layer thread.
+- (void)addMarkersLayerThread:(NSArray *)argArray
+{
+ NSArray *markers = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+
+ // Convert to WG markers
+ NSMutableArray *wgMarkers = [NSMutableArray array];
+ for (MaplyMarker *marker in markers)
+ {
+ WhirlyKitMarker *wgMarker = [[WhirlyKitMarker alloc] init];
+ wgMarker.loc = GeoCoord(marker.loc.x,marker.loc.y);
+ SimpleIdentity texID = EmptyIdentity;
+ if (marker.image)
+ texID = [self addImage:marker.image];
+ if (texID != EmptyIdentity)
+ wgMarker.texIDs.push_back(texID);
+ wgMarker.width = marker.size.width;
+ wgMarker.height = marker.size.height;
+ if (marker.selectable)
+ {
+ wgMarker.isSelectable = true;
+ wgMarker.selectID = Identifiable::genId();
+ }
+
+ [wgMarkers addObject:wgMarker];
+
+ if (marker.selectable)
+ selectObjectSet.insert(SelectObject(wgMarker.selectID,marker));
+ }
+
+ // Set up a description and create the markers in the marker layer
+ SimpleIdentity markerID = [markerLayer addMarkers:wgMarkers desc:inDesc];
+ compObj.markerIDs.insert(markerID);
+
+ [userObjects addObject:compObj];
+}
+
+// Add 3D markers
+- (MaplyComponentObject *)addMarkers:(NSArray *)markers desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:markers, compObj, [NSDictionary dictionaryWithDictionary:desc], nil];
+ [self performSelector:@selector(addMarkersLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Actually add the labels.
+// Called in the layer thread.
+- (void)addScreenLabelsLayerThread:(NSArray *)argArray
+{
+ NSArray *labels = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+
+ // Convert to WG markers
+ NSMutableArray *wgLabels = [NSMutableArray array];
+ for (MaplyScreenLabel *label in labels)
+ {
+ WhirlyKitSingleLabel *wgLabel = [[WhirlyKitSingleLabel alloc] init];
+ NSMutableDictionary *desc = [NSMutableDictionary dictionary];
+ wgLabel.loc = GeoCoord(label.loc.x,label.loc.y);
+ wgLabel.text = label.text;
+ SimpleIdentity texID = EmptyIdentity;
+ if (label.iconImage)
+ texID = [self addImage:label.iconImage];
+ wgLabel.iconTexture = texID;
+ if (label.size.width > 0.0)
+ [desc setObject:[NSNumber numberWithFloat:label.size.width] forKey:@"width"];
+ if (label.size.height > 0.0)
+ [desc setObject:[NSNumber numberWithFloat:label.size.height] forKey:@"height"];
+ if (label.color)
+ [desc setObject:label.color forKey:@"textColor"];
+ if (label.layoutImportance != MAXFLOAT)
+ {
+ [desc setObject:@(YES) forKey:@"layout"];
+ [desc setObject:@(label.layoutImportance) forKey:@"layoutImportance"];
+ }
+ wgLabel.screenOffset = label.offset;
+ if (label.selectable)
+ {
+ wgLabel.isSelectable = true;
+ wgLabel.selectID = Identifiable::genId();
+ }
+ if ([desc count] > 0)
+ wgLabel.desc = desc;
+
+ [wgLabels addObject:wgLabel];
+
+ if (label.selectable)
+ selectObjectSet.insert(SelectObject(wgLabel.selectID,label));
+ }
+
+ // Set up a description and create the markers in the marker layer
+ NSMutableDictionary *desc = [NSMutableDictionary dictionaryWithDictionary:inDesc];
+ [desc setObject:[NSNumber numberWithBool:YES] forKey:@"screen"];
+ SimpleIdentity labelID = [labelLayer addLabels:wgLabels desc:desc];
+ compObj.labelIDs.insert(labelID);
+
+ [userObjects addObject:compObj];
+}
+
+// Add screen space (2D) labels
+- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:labels, compObj, [NSDictionary dictionaryWithDictionary:desc], nil];
+ [self performSelector:@selector(addScreenLabelsLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Actually add the labels.
+// Called in the layer thread.
+- (void)addLabelsLayerThread:(NSArray *)argArray
+{
+ NSArray *labels = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+
+ // Convert to WG markers
+ NSMutableArray *wgLabels = [NSMutableArray array];
+ for (MaplyLabel *label in labels)
+ {
+ WhirlyKitSingleLabel *wgLabel = [[WhirlyKitSingleLabel alloc] init];
+ NSMutableDictionary *desc = [NSMutableDictionary dictionary];
+ wgLabel.loc = GeoCoord(label.loc.x,label.loc.y);
+ wgLabel.text = label.text;
+ SimpleIdentity texID = EmptyIdentity;
+ if (label.iconImage)
+ texID = [self addImage:label.iconImage];
+ wgLabel.iconTexture = texID;
+ if (label.size.width > 0.0)
+ [desc setObject:[NSNumber numberWithFloat:label.size.width] forKey:@"width"];
+ if (label.size.height > 0.0)
+ [desc setObject:[NSNumber numberWithFloat:label.size.height] forKey:@"height"];
+ if (label.color)
+ [desc setObject:label.color forKey:@"textColor"];
+ if (label.selectable)
+ {
+ wgLabel.isSelectable = true;
+ wgLabel.selectID = Identifiable::genId();
+ }
+ switch (label.justify)
+ {
+ case MaplyLabelJustifyLeft:
+ [desc setObject:@"left" forKey:@"justify"];
+ break;
+ case MaplyLabelJustiyMiddle:
+ [desc setObject:@"middle" forKey:@"justify"];
+ break;
+ case MaplyLabelJustifyRight:
+ [desc setObject:@"right" forKey:@"justify"];
+ break;
+ }
+ wgLabel.desc = desc;
+
+ [wgLabels addObject:wgLabel];
+
+ if (label.selectable)
+ selectObjectSet.insert(SelectObject(wgLabel.selectID,label));
+ }
+
+ // Set up a description and create the markers in the marker layer
+ SimpleIdentity labelID = [labelLayer addLabels:wgLabels desc:inDesc];
+ compObj.labelIDs.insert(labelID);
+
+ [userObjects addObject:compObj];
+}
+
+// Add 3D labels
+- (MaplyComponentObject *)addLabels:(NSArray *)labels desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:labels, compObj, [NSDictionary dictionaryWithDictionary:desc], nil];
+ [self performSelector:@selector(addLabelsLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Actually add the vectors.
+// Called in the layer thread.
+- (void)addVectorsLayerThread:(NSArray *)argArray
+{
+ NSArray *vectors = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ compObj.vectors = vectors;
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+ bool makeVisible = [[argArray objectAtIndex:3] boolValue];
+
+ ShapeSet shapes;
+ for (MaplyVectorObject *vecObj in vectors)
+ {
+ shapes.insert(vecObj.shapes.begin(),vecObj.shapes.end());
+ }
+
+ if (makeVisible)
+ {
+ SimpleIdentity vecID = [vectorLayer addVectors:&shapes desc:inDesc];
+ compObj.vectorIDs.insert(vecID);
+ }
+
+ [userObjects addObject:compObj];
+}
+
+// Add vectors
+- (MaplyComponentObject *)addVectors:(NSArray *)vectors desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:vectors, compObj, [NSDictionary dictionaryWithDictionary:desc], [NSNumber numberWithBool:YES], nil];
+ [self performSelector:@selector(addVectorsLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Add vectors that we'll only use for selection
+- (MaplyComponentObject *)addSelectionVectors:(NSArray *)vectors desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:vectors, compObj, [NSDictionary dictionaryWithDictionary:desc], [NSNumber numberWithBool:NO], nil];
+ [self performSelector:@selector(addVectorsLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Actually do the vector change
+// Called in the layer thread
+- (void)changeVectorLayerThread:(NSArray *)argArray
+{
+ MaplyComponentObject *vecObj = [argArray objectAtIndex:0];
+ NSDictionary *desc = [argArray objectAtIndex:1];
+
+ for (SimpleIDSet::iterator it = vecObj.vectorIDs.begin();
+ it != vecObj.vectorIDs.end(); ++it)
+ [vectorLayer changeVector:*it desc:desc];
+}
+
+// Change vector representation
+- (void)changeVectors:(MaplyComponentObject *)vecObj desc:(NSDictionary *)desc
+{
+ if (!vecObj)
+ return;
+
+ if (!desc)
+ desc = [NSDictionary dictionary];
+ NSArray *argArray = [NSArray arrayWithObjects:vecObj, desc, nil];
+
+ [self performSelector:@selector(changeVectorLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+}
+
+// Called in the layer thread
+- (void)addShapesLayerThread:(NSArray *)argArray
+{
+ CoordSystemDisplayAdapter *coordAdapter = scene->getCoordAdapter();
+ NSArray *shapes = [argArray objectAtIndex:0];
+ MaplyComponentObject *compObj = [argArray objectAtIndex:1];
+ NSDictionary *inDesc = [argArray objectAtIndex:2];
+
+ // Need to convert shapes to the form the API is expecting
+ NSMutableArray *ourShapes = [NSMutableArray array];
+ for (NSObject *shape in shapes)
+ {
+ if ([shape isKindOfClass:[MaplyShapeCircle class]])
+ {
+ MaplyShapeCircle *circle = (MaplyShapeCircle *)shape;
+ WhirlyKitCircle *newCircle = [[WhirlyKitCircle alloc] init];
+ newCircle.loc.lon() = circle.center.x;
+ newCircle.loc.lat() = circle.center.y;
+ newCircle.radius = circle.radius;
+ [ourShapes addObject:newCircle];
+ } else if ([shape isKindOfClass:[MaplyShapeSphere class]])
+ {
+ MaplyShapeSphere *sphere = (MaplyShapeSphere *)shape;
+ WhirlyKitSphere *newSphere = [[WhirlyKitSphere alloc] init];
+ newSphere.loc.lon() = sphere.center.x;
+ newSphere.loc.lat() = sphere.center.y;
+ newSphere.radius = sphere.radius;
+ newSphere.height = sphere.height;
+ [ourShapes addObject:newSphere];
+ } else if ([shape isKindOfClass:[MaplyShapeCylinder class]])
+ {
+ MaplyShapeCylinder *cyl = (MaplyShapeCylinder *)shape;
+ WhirlyKitCylinder *newCyl = [[WhirlyKitCylinder alloc] init];
+ newCyl.loc.lon() = cyl.baseCenter.x;
+ newCyl.loc.lat() = cyl.baseCenter.y;
+ newCyl.radius = cyl.radius;
+ newCyl.height = cyl.height;
+ [ourShapes addObject:newCyl];
+ } else if ([shape isKindOfClass:[MaplyShapeGreatCircle class]])
+ {
+ MaplyShapeGreatCircle *gc = (MaplyShapeGreatCircle *)shape;
+ WhirlyKitShapeLinear *lin = [[WhirlyKitShapeLinear alloc] init];
+ SampleGreatCircle(gc.startPt,gc.endPt,gc.height,lin.pts,visualView.coordAdapter);
+ lin.lineWidth = gc.lineWidth;
+ [ourShapes addObject:lin];
+ } else if ([shape isKindOfClass:[MaplyShapeLinear class]])
+ {
+ MaplyShapeLinear *lin = (MaplyShapeLinear *)shape;
+ WhirlyKitShapeLinear *newLin = [[WhirlyKitShapeLinear alloc] init];
+ MaplyCoordinate3d *coords = NULL;
+ int numCoords = [lin getCoords:&coords];
+ for (unsigned int ii=0;ii<numCoords;ii++)
+ {
+ MaplyCoordinate3d &coord = coords[ii];
+ Point3f pt = coordAdapter->localToDisplay(coordAdapter->getCoordSystem()->geographicToLocal(GeoCoord(coord.x,coord.y)));
+ pt *= (1.0+coord.z);
+ newLin.pts.push_back(pt);
+ }
+ newLin.lineWidth = lin.lineWidth;
+ [ourShapes addObject:newLin];
+ }
+ }
+
+ SimpleIdentity shapeID = [shapeLayer addShapes:ourShapes desc:inDesc];
+ compObj.shapeIDs.insert(shapeID);
+
+ [userObjects addObject:compObj];
+}
+
+// Add shapes
+- (MaplyComponentObject *)addShapes:(NSArray *)shapes desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = [NSArray arrayWithObjects:shapes, compObj, [NSDictionary dictionaryWithDictionary:desc], nil];
+ [self performSelector:@selector(addShapesLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Called in the layer thread
+- (void)addStickersLayerThread:(NSArray *)argArray
+{
+ NSArray *stickers = argArray[0];
+ MaplyComponentObject *compObj = argArray[1];
+ NSDictionary *inDesc = argArray[2];
+
+ for (MaplySticker *sticker in stickers)
+ {
+ SimpleIdentity texId = EmptyIdentity;
+ if (sticker.image)
+ texId = [self addImage:sticker.image];
+ WhirlyKitSphericalChunk *chunk = [[WhirlyKitSphericalChunk alloc] init];
+ GeoMbr geoMbr = GeoMbr(GeoCoord(sticker.ll.x,sticker.ll.y), GeoCoord(sticker.ur.x,sticker.ur.y));
+ chunk.mbr = geoMbr;
+ chunk.texId = texId;
+ chunk.drawOffset = [inDesc[@"drawOffset"] floatValue];
+ chunk.drawPriority = [inDesc[@"drawPriority"] floatValue];
+ chunk.sampleX = [inDesc[@"sampleX"] intValue];
+ chunk.sampleY = [inDesc[@"sampleY"] intValue];
+ chunk.rotation = sticker.rotation;
+ SimpleIdentity chunkId = [chunkLayer addChunk:chunk enable:true];
+ compObj.chunkIDs.insert(chunkId);
+ }
+
+ [userObjects addObject:compObj];
+}
+
+// Add stickers
+- (MaplyComponentObject *)addStickers:(NSArray *)stickers desc:(NSDictionary *)desc
+{
+ MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
+
+ NSArray *argArray = @[stickers, compObj, [NSDictionary dictionaryWithDictionary:desc]];
+ [self performSelector:@selector(addStickersLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
+
+ return compObj;
+}
+
+// Remove the object, but do it on the layer thread
+- (void)removeObjectLayerThread:(NSArray *)userObjs
+{
+ // First, let's make sure we're representing it
+ for (MaplyComponentObject *userObj in userObjs)
+ {
+ if ([userObjects containsObject:userObj])
+ {
+ // Get rid of the various layer objects
+ for (SimpleIDSet::iterator it = userObj.markerIDs.begin();
+ it != userObj.markerIDs.end(); ++it)
+ [markerLayer removeMarkers:*it];
+ for (SimpleIDSet::iterator it = userObj.labelIDs.begin();
+ it != userObj.labelIDs.end(); ++it)
+ [labelLayer removeLabel:*it];
+ for (SimpleIDSet::iterator it = userObj.vectorIDs.begin();
+ it != userObj.vectorIDs.end(); ++it)
+ [vectorLayer removeVector:*it];
+ for (SimpleIDSet::iterator it = userObj.shapeIDs.begin();
+ it != userObj.shapeIDs.end(); ++it)
+ [shapeLayer removeShapes:*it];
+ for (SimpleIDSet::iterator it = userObj.chunkIDs.begin();
+ it != userObj.chunkIDs.end(); ++it)
+ [chunkLayer removeChunk:*it];
+
+ [userObjects removeObject:userObj];
+ }
+ }
+}
+
+// Remove data associated with a user object
+- (void)removeObject:(MaplyComponentObject *)userObj
+{
+ if (userObj != nil)
+ [self performSelector:@selector(removeObjectLayerThread:) onThread:layerThread withObject:[NSArray arrayWithObject:userObj] waitUntilDone:NO];
+}
+
+// Remove a group of objects at once
+- (void)removeObjects:(NSArray *)userObjs
+{
+ [self performSelector:@selector(removeObjectLayerThread:) onThread:layerThread withObject:userObjs waitUntilDone:NO];
+}
+
+// Search for a point inside any of our vector objects
+// Runs in layer thread
+- (NSObject *)findVectorInPoint:(Point2f)pt
+{
+ NSObject *selObj = nil;
+
+ for (MaplyComponentObject *userObj in userObjects)
+ {
+ if (userObj.vectors)
+ {
+ for (MaplyVectorObject *vecObj in userObj.vectors)
+ {
+ if (vecObj.selectable)
+ {
+ // Note: Take visibility into account too
+ MaplyCoordinate coord;
+ coord.x = pt.x();
+ coord.y = pt.y();
+ if ([vecObj pointInAreal:coord])
+ {
+ selObj = vecObj;
+ break;
+ }
+ }
+ }
+
+ if (selObj)
+ break;
+ }
+ }
+
+ return selObj;
+}
+
+@end
View
516 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyBaseViewController.mm
@@ -0,0 +1,516 @@
+/*
+ * MaplyBaseViewController.mm
+ * MaplyComponent
+ *
+ * Created by Steve Gifford on 12/14/12.
+ * Copyright 2012 mousebird consulting
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#import "MaplyBaseViewController_private.h"
+
+using namespace Eigen;
+using namespace WhirlyKit;
+
+@implementation MaplyBaseViewController
+
+@synthesize selection;
+
+- (void) clear
+{
+ [glView stopAnimation];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ if (layerThread)
+ {
+ [layerThread addThingToDelete:scene];
+ [layerThread addThingToRelease:layerThread];
+ [layerThread cancel];
+ }
+
+ scene = NULL;
+ visualView = nil;
+
+ glView = nil;
+ sceneRenderer = nil;
+
+ layerThread = nil;
+
+ markerLayer = nil;
+ labelLayer = nil;
+ vectorLayer = nil;
+ shapeLayer = nil;
+ chunkLayer = nil;
+ layoutLayer = nil;
+ selectLayer = nil;
+
+ interactLayer = nil;
+
+ while ([userLayers count] > 0)
+ {
+ MaplyViewControllerLayer *layer = [userLayers objectAtIndex:0];
+ [userLayers removeObject:layer];
+ }
+ userLayers = nil;
+
+ viewTrackers = nil;
+
+ theClearColor = nil;
+}
+
+- (WhirlyKitView *) loadSetup_view
+{
+ return nil;
+}
+
+- (WhirlyKit::Scene *) loadSetup_scene
+{
+ return NULL;
+}
+
+- (MaplyBaseInteractionLayer *) loadSetup_interactionLayer
+{
+ return nil;
+}
+
+// Create the Maply or Globe view.
+// For specific parts we'll call our subclasses
+- (void) loadSetup
+{
+ userLayers = [NSMutableArray array];
+
+ // Set up an OpenGL ES view and renderer
+ glView = [[WhirlyKitEAGLView alloc] init];
+ sceneRenderer = [[WhirlyKitSceneRendererES1 alloc] init];
+ // sceneRenderer = [[WhirlyKitSceneRendererES2 alloc] init];
+ theClearColor = [UIColor blackColor];
+ [sceneRenderer setClearColor:theClearColor];
+ glView.renderer = sceneRenderer;
+ glView.frameInterval = 2; // 30 fps
+ [self.view insertSubview:glView atIndex:0];
+ self.view.backgroundColor = [UIColor blackColor];
+ self.view.opaque = YES;
+ self.view.autoresizesSubviews = YES;
+ glView.frame = self.view.bounds;
+ glView.backgroundColor = [UIColor blackColor];
+
+ // Create the textures and geometry, but in the right GL context
+ [sceneRenderer useContext];
+
+ // Turn on the model matrix optimization for drawing
+ sceneRenderer.useViewChanged = true;
+
+ // Need an empty scene and view
+ visualView = [self loadSetup_view];
+ scene = [self loadSetup_scene];
+
+ // Need a layer thread to manage the layers
+ layerThread = [[WhirlyKitLayerThread alloc] initWithScene:scene view:visualView renderer:sceneRenderer];
+
+ // Selection feedback
+ selectLayer = [[WhirlyKitSelectionLayer alloc] initWithView:visualView renderer:sceneRenderer];
+ [layerThread addLayer:selectLayer];
+
+ // Set up the vector layer where all our outlines will go
+ vectorLayer = [[WhirlyKitVectorLayer alloc] init];
+ [layerThread addLayer:vectorLayer];
+
+ // Set up the shape layer. Manages a set of simple shapes
+ shapeLayer = [[WhirlyKitShapeLayer alloc] init];
+ shapeLayer.selectLayer = selectLayer;
+ [layerThread addLayer:shapeLayer];
+
+ // Set up the chunk layer. Used for stickers.
+ chunkLayer = [[WhirlyKitSphericalChunkLayer alloc] init];
+ chunkLayer.ignoreEdgeMatching = true;
+ [layerThread addLayer:chunkLayer];
+
+ // General purpose label layer.
+ labelLayer = [[WhirlyKitLabelLayer alloc] init];
+ labelLayer.selectLayer = selectLayer;
+ [layerThread addLayer:labelLayer];
+
+ // Marker layer
+ markerLayer = [[WhirlyKitMarkerLayer alloc] init];
+ markerLayer.selectLayer = selectLayer;
+ [layerThread addLayer:markerLayer];
+
+ // 2D layout engine layer
+ layoutLayer = [[WhirlyKitLayoutLayer alloc] initWithRenderer:sceneRenderer];
+ labelLayer.layoutLayer = layoutLayer;
+ [layerThread addLayer:layoutLayer];
+
+ // Lastly, an interaction layer of our own
+ interactLayer = [self loadSetup_interactionLayer];
+ interactLayer.vectorLayer = vectorLayer;
+ interactLayer.labelLayer = labelLayer;
+ interactLayer.markerLayer = markerLayer;
+ interactLayer.shapeLayer = shapeLayer;
+ interactLayer.chunkLayer = chunkLayer;
+ interactLayer.selectLayer = selectLayer;
+ interactLayer.glView = glView;
+ [layerThread addLayer:interactLayer];
+
+ // Give the renderer what it needs
+ sceneRenderer.scene = scene;
+ sceneRenderer.theView = visualView;
+
+ viewTrackers = [NSMutableArray array];
+
+ // Kick off the layer thread
+ // This will start loading things
+ [layerThread start];
+
+ // Set up defaults for the hints
+ NSDictionary *newHints = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:YES], kWGRenderHintZBuffer,
+ nil];
+ [self setHints:newHints];
+
+ // Set up default descriptions for the various data types
+ NSDictionary *newScreenLabelDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setScreenLabelDesc:newScreenLabelDesc];
+
+ NSDictionary *newLabelDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInteger:kWGLabelDrawOffsetDefault], kWGDrawOffset,
+ [NSNumber numberWithInteger:kWGLabelDrawPriorityDefault], kWGDrawPriority,
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setLabelDesc:newLabelDesc];
+
+ NSDictionary *newScreenMarkerDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setScreenMarkerDesc:newScreenMarkerDesc];
+
+ NSDictionary *newMarkerDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInteger:kWGMarkerDrawOffsetDefault], kWGDrawOffset,
+ [NSNumber numberWithInteger:kWGMarkerDrawPriorityDefault], kWGDrawPriority,
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setMarkerDesc:newMarkerDesc];
+
+ NSDictionary *newVectorDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInteger:kWGVectorDrawOffsetDefault], kWGDrawOffset,
+ [NSNumber numberWithInteger:kWGVectorDrawPriorityDefault], kWGDrawPriority,
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setVectorDesc:newVectorDesc];
+
+ NSDictionary *newShapeDesc = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat:1.0], kWGFade,
+ nil];
+ [self setShapeDesc:newShapeDesc];
+
+ [self setStickerDesc:@{}];
+
+ selection = true;
+
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ [self loadSetup];
+}
+
+- (void)viewDidUnload
+{
+ [self clear];
+
+ [super viewDidUnload];
+}
+
+- (void)startAnimation
+{
+ [glView startAnimation];
+}
+
+- (void)stopAnimation
+{
+ [glView stopAnimation];
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+ [glView startAnimation];
+
+ [super viewWillAppear:animated];
+}
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+
+ [glView stopAnimation];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return YES;
+}
+
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name
+{
+ MaplyViewControllerLayer *newLayer = (MaplyViewControllerLayer *)[[MaplyQuadEarthWithMBTiles alloc] initWithWithLayerThread:layerThread scene:scene renderer:sceneRenderer mbTiles:name handleEdges:(sceneRenderer.zBufferMode == zBufferOn)];
+ if (!newLayer)
+ return nil;
+
+ [userLayers addObject:newLayer];
+
+ return newLayer;
+}
+
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithRemoteSource:(NSString *)baseURL imageExt:(NSString *)ext cache:(NSString *)cacheDir minZoom:(int)minZoom maxZoom:(int)maxZoom;
+{
+ MaplyQuadEarthWithRemoteTiles *newLayer = [[MaplyQuadEarthWithRemoteTiles alloc] initWithLayerThread:layerThread scene:scene renderer:sceneRenderer baseURL:baseURL ext:ext minZoom:minZoom maxZoom:maxZoom handleEdges:(sceneRenderer.zBufferMode == zBufferOn)];
+ if (!newLayer)
+ return nil;
+ newLayer.cacheDir = cacheDir;
+ [userLayers addObject:newLayer];
+
+ return newLayer;
+}
+
+#pragma mark - Defaults and descriptions
+
+// Merge the two dictionaries, add taking precidence, and then look for NSNulls
+- (NSDictionary *)mergeAndCheck:(NSDictionary *)baseDict changeDict:(NSDictionary *)addDict
+{
+ if (!addDict)
+ return baseDict;
+
+ NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithDictionary:baseDict];
+ [newDict addEntriesFromDictionary:addDict];
+
+ // Now look for NSNulls, which we use to remove things
+ NSArray *keys = [newDict allKeys];
+ for (NSString *key in keys)
+ {
+ NSObject *obj = [newDict objectForKey:key];
+ if (obj && [obj isKindOfClass:[NSNull class]])
+ [newDict removeObjectForKey:key];
+ }
+
+ return newDict;
+}
+
+// Set new hints and update any related settings
+- (void)setHints:(NSDictionary *)changeDict
+{
+ hints = [self mergeAndCheck:hints changeDict:changeDict];
+
+ // Settings we store in the hints
+ BOOL zBuffer = [hints boolForKey:kWGRenderHintZBuffer default:true];
+ sceneRenderer.zBufferMode = (zBuffer ? zBufferOn : zBufferOff);
+ BOOL culling = [hints boolForKey:kWGRenderHintCulling default:true];
+ sceneRenderer.doCulling = culling;
+}
+
+// Set the default description for screen markers
+- (void)setScreenMarkerDesc:(NSDictionary *)desc
+{
+ screenMarkerDesc = [self mergeAndCheck:screenMarkerDesc changeDict:desc];
+}
+
+// Set the default description for markers
+- (void)setMarkerDesc:(NSDictionary *)desc
+{
+ markerDesc = [self mergeAndCheck:markerDesc changeDict:desc];
+}
+
+// Set the default description for screen labels
+- (void)setScreenLabelDesc:(NSDictionary *)desc
+{
+ screenLabelDesc = [self mergeAndCheck:screenLabelDesc changeDict:desc];
+}
+
+// Set the default description for labels
+- (void)setLabelDesc:(NSDictionary *)desc
+{
+ labelDesc = [self mergeAndCheck:labelDesc changeDict:desc];
+}
+
+- (void)setVectorDesc:(NSDictionary *)desc
+{
+ vectorDesc = [self mergeAndCheck:vectorDesc changeDict:desc];
+}
+
+- (void)setShapeDesc:(NSDictionary *)desc
+{
+ shapeDesc = [self mergeAndCheck:shapeDesc changeDict:desc];
+}
+
+- (void)setStickerDesc:(NSDictionary *)desc
+{
+ stickerDesc = [self mergeAndCheck:stickerDesc changeDict:desc];
+}
+
+#pragma mark - Geometry related methods
+
+/// Add a group of screen (2D) markers
+- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers
+{
+ return [interactLayer addScreenMarkers:markers desc:screenMarkerDesc];
+}
+
+/// Add a group of 3D markers
+- (MaplyComponentObject *)addMarkers:(NSArray *)markers
+{
+ return [interactLayer addMarkers:markers desc:markerDesc];
+}
+
+/// Add a group of screen (2D) labels
+- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels
+{
+ return [interactLayer addScreenLabels:labels desc:screenLabelDesc];
+}
+
+/// Add a group of 3D labels
+- (MaplyComponentObject *)addLabels:(NSArray *)labels
+{
+ return [interactLayer addLabels:labels desc:labelDesc];
+}
+
+/// Add one or more vectors
+- (MaplyComponentObject *)addVectors:(NSArray *)vectors
+{
+ return [interactLayer addVectors:vectors desc:vectorDesc];
+}
+
+- (MaplyComponentObject *)addSelectionVectors:(NSArray *)vectors
+{
+ return [interactLayer addSelectionVectors:vectors desc:vectorDesc];
+}
+
+- (void)changeVector:(MaplyComponentObject *)compObj desc:(NSDictionary *)desc
+{
+ [interactLayer changeVectors:compObj desc:desc];
+}
+
+/// Add one or more shapes
+- (MaplyComponentObject *)addShapes:(NSArray *)shapes
+{
+ return [interactLayer addShapes:shapes desc:shapeDesc];
+}
+
+- (MaplyComponentObject *)addStickers:(NSArray *)stickers
+{
+ return [interactLayer addStickers:stickers desc:stickerDesc];
+}
+
+/// Add a view to track to a particular location
+- (void)addViewTracker:(WGViewTracker *)viewTrack
+{
+ // Make sure we're not duplicating and add the object
+ [self removeViewTrackForView:viewTrack.view];
+ [viewTrackers addObject:viewTrack];
+
+ // Hook it into the renderer
+ ViewPlacementGenerator *vpGen = scene->getViewPlacementGenerator();
+ vpGen->addView(GeoCoord(viewTrack.loc.x,viewTrack.loc.y),viewTrack.view,DrawVisibleInvalid,DrawVisibleInvalid);
+
+ // And add it to the view hierarchy
+ if ([viewTrack.view superview] == nil)
+ [glView addSubview:viewTrack.view];
+}
+
+/// Remove the view tracker associated with the given UIView
+- (void)removeViewTrackForView:(UIView *)view
+{
+ // Look for the entry
+ WGViewTracker *theTracker = nil;
+ for (WGViewTracker *viewTrack in viewTrackers)
+ if (viewTrack.view == view)
+ {
+ theTracker = viewTrack;
+ break;
+ }
+
+ if (theTracker)
+ {
+ [viewTrackers removeObject:theTracker];
+ ViewPlacementGenerator *vpGen = scene->getViewPlacementGenerator();
+ vpGen->removeView(theTracker.view);
+ if ([theTracker.view superview] == glView)
+ [theTracker.view removeFromSuperview];
+ }
+}
+
+
+/// Remove the data associated with an object the user added earlier
+- (void)removeObject:(WGComponentObject *)theObj
+{
+ [interactLayer removeObject:theObj];
+}
+
+- (void)removeObjects:(NSArray *)theObjs
+{
+ [interactLayer removeObjects:theObjs];
+}
+
+- (void)removeLayer:(MaplyViewControllerLayer *)layer
+{
+ bool found = false;
+ for (MaplyViewControllerLayer *theLayer in userLayers)
+ {
+ if (theLayer == layer)
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return;
+
+ [layer cleanupLayers:layerThread scene:scene];
+ [userLayers removeObject:layer];
+}
+
+- (void)removeAllLayers
+{
+ for (MaplyViewControllerLayer *theLayer in userLayers)
+ {
+ [theLayer cleanupLayers:layerThread scene:scene];
+ }
+ [userLayers removeAllObjects];
+}
+
+#pragma mark - Properties
+
+- (UIColor *)clearColor
+{
+ return theClearColor;
+}
+
+- (void)setClearColor:(UIColor *)clearColor
+{
+ theClearColor = clearColor;
+ [sceneRenderer setClearColor:clearColor];
+}
+
+- (MaplyCoordinate3d)displayPointFromGeo:(MaplyCoordinate)geoCoord
+{
+ MaplyCoordinate3d displayCoord;
+ Point3f pt = visualView.coordAdapter->localToDisplay(visualView.coordAdapter->getCoordSystem()->geographicToLocal(GeoCoord(geoCoord.x,geoCoord.y)));
+
+ displayCoord.x = pt.x(); displayCoord.y = pt.y(); displayCoord.z = pt.z();
+ return displayCoord;
+}
+
+@end
View
347 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyInteractionLayer.mm
@@ -33,20 +33,27 @@
@implementation MaplyInteractionLayer
{
- WhirlyKitLayerThread * __weak layerThread;
- Maply::MapScene *scene;
- ImageTextureSet imageTextures;
+ Maply::MapScene *mapScene;
+ MaplyView *mapView;
}
-@synthesize markerLayer;
-@synthesize labelLayer;
-@synthesize vectorLayer;
-@synthesize selectLayer;
-@synthesize glView;
@synthesize viewController;
+- (id)initWithMapView:(MaplyView *)inMapView
+{
+ self = [super initWithView:inMapView];
+ if (!self)
+ return nil;
+ mapView = inMapView;
+
+ return self;
+}
+
- (void)startWithThread:(WhirlyKitLayerThread *)inLayerThread scene:(WhirlyKit::Scene *)inScene
{
+ [super startWithThread:inLayerThread scene:inScene];
+ mapScene = (Maply::MapScene *)inScene;
+
layerThread = inLayerThread;
scene = (Maply::MapScene *)inScene;
userObjects = [NSMutableArray array];
@@ -60,329 +67,7 @@ - (void)dealloc
/// Clean all your stuff out of the scenegraph and so forth.
- (void)shutdown
{
- layerThread = nil;
- scene = NULL;
- imageTextures.clear();
-}
-
-// Add an image to the cache, or find an existing one
-// Called in the layer thread
-// Note: Share this between the interaction layers
-- (SimpleIdentity)addImage:(UIImage *)image
-{
- // Look for an existing one
- ImageTextureSet::iterator it = imageTextures.find(ImageTexture(image));
- if (it != imageTextures.end())
- return it->texID;
-
- // Add it and download it
- Texture *tex = new Texture(image);
-// tex->createInGL(YES, scene->getMemManager());
- scene->addChangeRequest(new AddTextureReq(tex));
-
- // Add to our cache
- ImageTexture newTex(image,tex->getId());
- imageTextures.insert(newTex);
-
- return newTex.texID;
-}
-
-// Actually add the markers.
-// Called in the layer thread.
-- (void)addScreenMarkersLayerThread:(NSArray *)argArray
-{
- NSArray *markers = [argArray objectAtIndex:0];
- MaplyComponentObject *compObj = [argArray objectAtIndex:1];
- NSDictionary *inDesc = [argArray objectAtIndex:2];
-
- // Convert to Maply markers
- NSMutableArray *wgMarkers = [NSMutableArray array];
- for (WGScreenMarker *marker in markers)
- {
- WhirlyKitMarker *wgMarker = [[WhirlyKitMarker alloc] init];
- wgMarker.loc = GeoCoord(marker.loc.x,marker.loc.y);
- SimpleIdentity texID = EmptyIdentity;
- if (marker.image)
- texID = [self addImage:marker.image];
- if (texID != EmptyIdentity)
- wgMarker.texIDs.push_back(texID);
- wgMarker.width = marker.size.width;
- wgMarker.height = marker.size.height;
- wgMarker.isSelectable = true;
- wgMarker.selectID = Identifiable::genId();
-
- [wgMarkers addObject:wgMarker];
-
- selectObjectSet.insert(SelectObject(wgMarker.selectID,marker));
- }
-
- // Set up a description and create the markers in the marker layer
- NSMutableDictionary *desc = [NSMutableDictionary dictionaryWithDictionary:inDesc];
- [desc setObject:[NSNumber numberWithBool:YES] forKey:@"screen"];
- SimpleIdentity markerID = [markerLayer addMarkers:wgMarkers desc:desc];
- compObj.markerIDs.insert(markerID);
-
- [userObjects addObject:compObj];
-}
-
-// Called in the main thread.
-- (MaplyComponentObject *)addScreenMarkers:(NSArray *)markers desc:(NSDictionary *)desc
-{
- MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
-
- NSArray *argArray = [NSArray arrayWithObjects:markers, compObj, desc, nil];
- [self performSelector:@selector(addScreenMarkersLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
-
- return compObj;
-}
-
-// Actually add the markers.
-// Called in the layer thread.
-- (void)addMarkersLayerThread:(NSArray *)argArray
-{
- NSArray *markers = [argArray objectAtIndex:0];
- MaplyComponentObject *compObj = [argArray objectAtIndex:1];
- NSDictionary *inDesc = [argArray objectAtIndex:2];
-
- // Convert to WG markers
- NSMutableArray *wgMarkers = [NSMutableArray array];
- for (WGMarker *marker in markers)
- {
- WhirlyKitMarker *wgMarker = [[WhirlyKitMarker alloc] init];
- wgMarker.loc = GeoCoord(marker.loc.x,marker.loc.y);
- SimpleIdentity texID = EmptyIdentity;
- if (marker.image)
- texID = [self addImage:marker.image];
- if (texID != EmptyIdentity)
- wgMarker.texIDs.push_back(texID);
- wgMarker.width = marker.size.width;
- wgMarker.height = marker.size.height;
- wgMarker.isSelectable = true;
- wgMarker.selectID = Identifiable::genId();
-
- [wgMarkers addObject:wgMarker];
-
- selectObjectSet.insert(SelectObject(wgMarker.selectID,marker));
- }
-
- // Set up a description and create the markers in the marker layer
- SimpleIdentity markerID = [markerLayer addMarkers:wgMarkers desc:inDesc];
- compObj.markerIDs.insert(markerID);
-
- [userObjects addObject:compObj];
-}
-
-// Add 3D markers
-- (MaplyComponentObject *)addMarkers:(NSArray *)markers desc:(NSDictionary *)desc
-{
- MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
-
- NSArray *argArray = [NSArray arrayWithObjects:markers, compObj, desc, nil];
- [self performSelector:@selector(addMarkersLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
-
- return compObj;
-}
-
-// Actually add the labels.
-// Called in the layer thread.
-- (void)addScreenLabelsLayerThread:(NSArray *)argArray
-{
- NSArray *labels = [argArray objectAtIndex:0];
- MaplyComponentObject *compObj = [argArray objectAtIndex:1];
- NSDictionary *inDesc = [argArray objectAtIndex:2];
-
- // Convert to WG markers
- NSMutableArray *wgLabels = [NSMutableArray array];
- for (MaplyScreenLabel *label in labels)
- {
- WhirlyKitSingleLabel *wgLabel = [[WhirlyKitSingleLabel alloc] init];
- NSMutableDictionary *desc = [NSMutableDictionary dictionary];
- wgLabel.loc = GeoCoord(label.loc.x,label.loc.y);
- wgLabel.text = label.text;
- SimpleIdentity texID = EmptyIdentity;
- if (label.iconImage)
- texID = [self addImage:label.iconImage];
- wgLabel.iconTexture = texID;
- if (label.size.width > 0.0)
- [desc setObject:[NSNumber numberWithFloat:label.size.width] forKey:@"width"];
- if (label.size.height > 0.0)
- [desc setObject:[NSNumber numberWithFloat:label.size.height] forKey:@"height"];
- wgLabel.isSelectable = true;
- wgLabel.screenOffset = label.offset;
- wgLabel.selectID = Identifiable::genId();
- if ([desc count] > 0)
- wgLabel.desc = desc;
-
- [wgLabels addObject:wgLabel];
-
- selectObjectSet.insert(SelectObject(wgLabel.selectID,label));
- }
-
- // Set up a description and create the markers in the marker layer
- NSMutableDictionary *desc = [NSMutableDictionary dictionaryWithDictionary:inDesc];
- [desc setObject:[NSNumber numberWithBool:YES] forKey:@"screen"];
- SimpleIdentity labelID = [labelLayer addLabels:wgLabels desc:desc];
- compObj.labelIDs.insert(labelID);
-
- [userObjects addObject:compObj];
-}
-
-// Add screen space (2D) labels
-- (MaplyComponentObject *)addScreenLabels:(NSArray *)labels desc:(NSDictionary *)desc
-{
- MaplyComponentObject *compObj = [[MaplyComponentObject alloc] init];
-
- NSArray *argArray = [NSArray arrayWithObjects:labels, compObj, desc, nil];
- [self performSelector:@selector(addScreenLabelsLayerThread:) onThread:layerThread withObject:argArray waitUntilDone:NO];
-
- return compObj;
-}
-
-// Actually add the labels.
-// Called in the layer thread.
-- (void)addLabelsLayerThread:(NSArray *)argArray
-{
- NSArray *labels = [argArray objectAtIndex:0];
- MaplyComponentObject *compObj = [argArray objectAtIndex:1];
- NSDictionary *inDesc = [argArray objectAtIndex:2];
-
- // Convert to WG markers
- NSMutableArray *wgLabels = [NSMutableArray array];