Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for loading an MBTiles file from the filesystem

Fix bug with 'northUp' always being true
Add setHeading:position: to WhirlyGlobeViewController
Add code to set the drawPriority of the tileLoader so multiple layers don't z-fight.
  • Loading branch information...
commit bba4285c5ac41e19783a8d078c9a960775b7aa07 1 parent f62b36f
Juan J. Collas authored
View
3  WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/MaplyBaseViewController.h
@@ -46,6 +46,9 @@
/// Add a quad tree paged earth layer with MapBox Tiles on top
- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name;
+/// Add a quad tree paged earth layer with MapBox Tiles on top from a specified path
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTilesPath:(NSString *)path;
+
/// Add a quad tree paged earth layer with
- (MaplyViewControllerLayer *)addQuadEarthLayerWithRemoteSource:(NSString *)baseURL imageExt:(NSString *)ext cache:(NSString *)cachdDir minZoom:(int)minZoom maxZoom:(int)maxZoom;
View
3  WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/WhirlyGlobeViewController.h
@@ -104,6 +104,9 @@
/// Get the current position and height
- (void)getPosition:(WGCoordinate *)pos height:(float *)height;
+/// Set heading about current position
+- (void) setHeading:(CGFloat) rotationHeading position:(WGCoordinate)newPos;
+
/// Add a spherical earth layer with the given set of base images
- (WGViewControllerLayer *)addSphericalEarthLayerWithImageSet:(NSString *)name;
View
4 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/include/private/MaplyQuadEarthWithMBTiles_private.h
@@ -22,9 +22,9 @@
@interface MaplyQuadEarthWithMBTiles : MaplyViewControllerLayer
-/// Set up a spherical earth layer with an MBTiles archive.
+/// Set up a spherical earth layer with an MBTiles archive from a specified path.
/// Returns nil on failure.
-- (id)initWithWithLayerThread:(WhirlyKitLayerThread *)layerThread scene:(WhirlyKit::Scene *)scene renderer:(WhirlyKitSceneRendererES *)renderer mbTiles:(NSString *)mbTilesName handleEdges:(bool)edges;
+- (id)initWithWithLayerThread:(WhirlyKitLayerThread *)layerThread scene:(WhirlyKit::Scene *)scene renderer:(WhirlyKitSceneRendererES *)renderer mbTilesPath:(NSString *)mbTilesPath handleEdges:(bool)edges;
/// Clean up any and all resources
- (void)cleanupLayers:(WhirlyKitLayerThread *)layerThread scene:(WhirlyKit::Scene *)scene;
View
13 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyBaseViewController.mm
@@ -267,7 +267,18 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTiles:(NSString *)name
{
- MaplyViewControllerLayer *newLayer = (MaplyViewControllerLayer *)[[MaplyQuadEarthWithMBTiles alloc] initWithWithLayerThread:layerThread scene:scene renderer:sceneRenderer mbTiles:name handleEdges:(sceneRenderer.zBufferMode == zBufferOn)];
+ NSString *infoPath = [[NSBundle mainBundle] pathForResource:name ofType:@"mbtiles"];
+ if (!infoPath)
+ {
+ return nil;
+ }
+
+ return [self addQuadEarthLayerWithMBTilesPath:infoPath];
+}
+
+- (MaplyViewControllerLayer *)addQuadEarthLayerWithMBTilesPath:(NSString *)path
+{
+ MaplyViewControllerLayer *newLayer = (MaplyViewControllerLayer *)[[MaplyQuadEarthWithMBTiles alloc] initWithWithLayerThread:layerThread scene:scene renderer:sceneRenderer mbTilesPath:path handleEdges:(sceneRenderer.zBufferMode == zBufferOn)];
if (!newLayer)
return nil;
View
10 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/MaplyQuadEarthWithMBTiles.mm
@@ -19,6 +19,7 @@
*/
#import "MaplyQuadEarthWithMBTiles_private.h"
+#import "LayerThread.h"
@implementation MaplyQuadEarthWithMBTiles
{
@@ -27,23 +28,24 @@ @implementation MaplyQuadEarthWithMBTiles
WhirlyKitMBTileQuadSource *dataSource;
}
-- (id)initWithWithLayerThread:(WhirlyKitLayerThread *)layerThread scene:(WhirlyKit::Scene *)scene renderer:(WhirlyKitSceneRendererES *)renderer mbTiles:(NSString *)mbName handleEdges:(bool)edges
+- (id)initWithWithLayerThread:(WhirlyKitLayerThread *)layerThread scene:(WhirlyKit::Scene *)scene renderer:(WhirlyKitSceneRendererES *)renderer mbTilesPath:(NSString *)mbPathName handleEdges:(bool)edges
{
self = [super init];
if (self)
{
- NSString *infoPath = [[NSBundle mainBundle] pathForResource:mbName ofType:@"mbtiles"];
- if (!infoPath)
+ if ([[NSFileManager defaultManager] fileExistsAtPath:mbPathName] == NO)
{
self = nil;
return nil;
}
- dataSource = [[WhirlyKitMBTileQuadSource alloc] initWithPath:infoPath];
+ dataSource = [[WhirlyKitMBTileQuadSource alloc] initWithPath:mbPathName];
tileLoader = [[WhirlyKitQuadTileLoader alloc] initWithDataSource:dataSource];
tileLoader.coverPoles = true;
quadLayer = [[WhirlyKitQuadDisplayLayer alloc] initWithDataSource:dataSource loader:tileLoader renderer:renderer];
tileLoader.ignoreEdgeMatching = !edges;
[layerThread addLayer:quadLayer];
+
+ tileLoader.drawPriority = [layerThread activeLayers] - 1;
}
return self;
View
55 WhirlyGlobeSrc/WhirlyGlobe-MaplyComponent/src/WhirlyGlobeViewController.mm
@@ -21,6 +21,7 @@
#import <WhirlyGlobe.h>
#import "WhirlyGlobeViewController.h"
#import "WhirlyGlobeViewController_private.h"
+#import "GlobeMath.h"
using namespace Eigen;
using namespace WhirlyKit;
@@ -262,7 +263,7 @@ - (void)rotateToPoint:(GeoCoord)whereGeo time:(NSTimeInterval)howLong
// Construct a quaternion to rotate from where we are to where
// the user tapped
- Eigen::Quaternionf newRotQuat = [globeView makeRotationToGeoCoord:whereGeo keepNorthUp:YES];
+ Eigen::Quaternionf newRotQuat = [globeView makeRotationToGeoCoord:whereGeo keepNorthUp:[self keepNorthUp]];
// Rotate to the given position over time
animateRotation = [[AnimateViewRotation alloc] initWithView:globeView rot:newRotQuat howLong:howLong];
@@ -338,6 +339,58 @@ - (void)getPosition:(WGCoordinate *)pos height:(float *)height
pos->x = geoCoord.lon(); pos->y = geoCoord.lat();
}
+// Set heading about current position
+- (void) setHeading:(CGFloat) rotationHeading position:(WGCoordinate)newPos
+{
+ CoordSystemDisplayAdapter *coordAdapter = scene->getCoordAdapter();
+ Eigen::Quaternionf startQuat = [globeView rotQuat];
+ Eigen::Quaternionf northQuat;
+ {
+// Point3f worldLoc = GeoCoordSystem::LocalToGeocentricish(GeoCoord(newPos.x,newPos.y));
+
+ //calculate north Quaternion
+ Point3f localPt = coordAdapter->getCoordSystem()->geographicToLocal(GeoCoord(newPos.x,newPos.y));
+ Point3f worldLoc = coordAdapter->normalForLocal(localPt);
+
+ // Let's rotate to where they tapped over a 1sec period
+ Vector3f curUp = [globeView currentUp];
+
+ // The rotation from where we are to where we tapped
+ Eigen::Quaternionf endRot;
+ endRot = QuatFromTwoVectors(worldLoc,curUp);
+ Eigen::Quaternionf curRotQuat = startQuat;
+ Eigen::Quaternionf newRotQuat = curRotQuat * endRot;
+
+
+
+ if ( YES )
+ {
+ // We'd like to keep the north pole pointed up
+ // So we look at where the north pole is going
+ Vector3f northPole = (newRotQuat * Vector3f(0,0,1)).normalized();
+ if (northPole.y() != 0.0)
+ {
+ // Then rotate it back on to the YZ axis
+ // This will keep it upward
+ float ang = atanf(northPole.x()/northPole.y());
+ // However, the pole might be down now
+ // If so, rotate it back up
+ if (northPole.y() < 0.0)
+ ang += M_PI;
+ Eigen::AngleAxisf upRot(ang,worldLoc);
+ newRotQuat = newRotQuat * upRot;
+ }
+ }
+ northQuat = newRotQuat;
+
+ }
+
+ Vector3f axis = [globeView currentUp];
+ Eigen::AngleAxisf rotQuat(rotationHeading, axis);
+ Eigen::Quaternionf newRotQuat = northQuat * rotQuat;
+ [globeView setRotQuat:newRotQuat];
+}
+
// Called back on the main thread after the interaction thread does the selection
- (void)handleSelection:(WhirlyGlobeTapMessage *)msg didSelect:(NSObject *)selectedObj
{
View
3  WhirlyGlobeSrc/WhirlyGlobeLib/include/LayerThread.h
@@ -67,6 +67,9 @@
/// Remove the given layer.
- (void)removeLayer:(NSObject<WhirlyKitLayer> *)layer;
+/// Return count of layers.
+- (NSInteger)activeLayers;
+
/// Add a C++ object to be deleted after the thread has stopped
/// Always clal this from the main thread before you cancel the layer thread
- (void)addThingToDelete:(WhirlyKit::DelayedDeletable *)thing;
View
6 WhirlyGlobeSrc/WhirlyGlobeLib/src/LayerThread.mm
@@ -91,6 +91,12 @@ - (void)removeLayerThread:(NSObject<WhirlyKitLayer> *)layer
}
}
+/// Return count of layers.
+- (NSInteger)activeLayers
+{
+ return [layers count];
+}
+
- (void)addThingToDelete:(WhirlyKit::DelayedDeletable *)thing
{
thingsToDelete.push_back(thing);
Please sign in to comment.
Something went wrong with that request. Please try again.