summaryrefslogtreecommitdiff
path: root/platform/macos
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-13 12:55:01 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-19 09:50:08 -0700
commit7f36e0cf769f6fe7a759b1cf6c56948c4c141fef (patch)
tree2b72187a6306df9d97d4b57007bd64c86a4bf4c7 /platform/macos
parentb7c7d3fdab283d7bf03d8acf68b9cfd478d6973f (diff)
downloadqtlocation-mapboxgl-7f36e0cf769f6fe7a759b1cf6c56948c4c141fef.tar.gz
[iOS][macOS] Export `MGLImageSource`, add and update documentation. Use animated ImageSource demo in iOS test app
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/app/MapDocument.m30
-rw-r--r--platform/macos/docs/guides/For Style Authors.md9
-rw-r--r--platform/macos/macos.xcodeproj/project.pbxproj2
-rw-r--r--platform/macos/src/MGLMapView.mm16
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.h2
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.mm4
6 files changed, 39 insertions, 24 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 281497ac92..94bf18dea1 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -622,10 +622,10 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:@"southeast_0"];
MGLCoordinateBounds bounds = { {22.551103322318994, -90.24006072802854}, {36.928147474567794, -75.1441643681673} };
- MGLImageSource *imageSource = [[MGLImageSource alloc] initWithIdentifier:@"radar-source" bounds:bounds image:image];
+ MGLImageSource *imageSource = [[MGLImageSource alloc] initWithIdentifier:@"animated-radar-source" coordinateQuad:MGLCoordinateQuadFromCoordinateBounds(bounds) image:image];
[self.mapView.style addSource:imageSource];
- MGLRasterStyleLayer * imageLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"radar-layer" source:imageSource];
+ MGLRasterStyleLayer * imageLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"animated-radar-layer" source:imageSource];
[self.mapView.style addLayer:imageLayer];
[NSTimer scheduledTimerWithTimeInterval:1.0
@@ -637,12 +637,15 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
- (void)updateAnimatedImageSource:(NSTimer *)timer {
+ static int radarSuffix = 0;
MGLImageSource *imageSource = (MGLImageSource *)timer.userInfo;
- double timeInterval = timer.fireDate.timeIntervalSinceReferenceDate;
- int radarSuffix = (int)timeInterval % 4;
- MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:[NSString stringWithFormat:@"southeast_%d", radarSuffix]];
+ MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:[NSString stringWithFormat:@"southeast_%d", radarSuffix++]];
[imageSource setValue:image forKey:@"image"];
+
+ if(radarSuffix > 3) {
+ radarSuffix = 0 ;
+ }
}
- (IBAction)insertCustomStyleLayer:(id)sender {
@@ -741,10 +744,11 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"ams" URL:geoJSONURL options:nil];
[self.mapView.style addSource:source];
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source];
- fillLayer.fillColor = [MGLStyleValue<NSColor *> valueWithRawValue:[NSColor greenColor]];
- fillLayer.predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"type", @"park"];
- [self.mapView.style addLayer:fillLayer];
+ MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"test" source:source];
+ circleLayer.circleColor = [MGLStyleValue<NSColor *> valueWithRawValue:[NSColor greenColor]];
+ circleLayer.circleRadius = [MGLStyleValue<NSNumber *> valueWithRawValue:[NSNumber numberWithInteger:40]];
+// fillLayer.predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"type", @"park"];
+ [self.mapView.style addLayer:circleLayer];
MGLSource *streetsSource = [self.mapView.style sourceWithIdentifier:@"composite"];
if (streetsSource) {
@@ -764,12 +768,12 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
[self.mapView.style addLayer:theaterLayer];
}
- MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:@"RadarImage"];
+ NSURL *imageURL = [NSURL URLWithString:@"https://www.mapbox.com/mapbox-gl-js/assets/radar.gif"];
MGLCoordinateQuad quad = { {46.437, -80.425},
- {46.437, -71.516},
+ {37.936, -80.425},
{37.936, -71.516},
- {37.936, -80.425} };
- MGLImageSource *imageSource = [[MGLImageSource alloc] initWithIdentifier:@"radar-source" coordinates:quad image:image];
+ {46.437, -71.516} };
+ MGLImageSource *imageSource = [[MGLImageSource alloc] initWithIdentifier:@"radar-source" coordinateQuad:quad URL:imageURL];
[self.mapView.style addSource:imageSource];
MGLRasterStyleLayer * imageLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"radar-layer" source:imageSource];
diff --git a/platform/macos/docs/guides/For Style Authors.md b/platform/macos/docs/guides/For Style Authors.md
index 164b1b58bf..3cacc81376 100644
--- a/platform/macos/docs/guides/For Style Authors.md
+++ b/platform/macos/docs/guides/For Style Authors.md
@@ -116,8 +116,9 @@ In style JSON | In the SDK
`geojson` | `MGLShapeSource`
`raster` | `MGLRasterSource`
`vector` | `MGLVectorSource`
+`image` | `MGLImageSource`
-`canvas`, `image`, and `video` sources are not supported.
+`canvas` and `video` sources are not supported.
### Tile sources
@@ -158,6 +159,12 @@ To create a shape source from local GeoJSON data, first
[convert the GeoJSON data into a shape](working-with-geojson-data.html#converting-geojson-data-into-shape-objects),
then use the `-[MGLShapeSource initWithIdentifier:shape:options:]` method.
+### Image sources
+
+Image sources accept a non-axis aligned quadrilateral as their geographic coordinates.
+These coordinates, in `MGLCoordinateQuad`, are described in counterclockwise order,
+in contrast to the clockwise order defined in the style specification.
+
## Configuring the map content’s appearance
Each layer defined by the style JSON file is represented at runtime by a style
diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj
index 248f913a35..723bbc6f4b 100644
--- a/platform/macos/macos.xcodeproj/project.pbxproj
+++ b/platform/macos/macos.xcodeproj/project.pbxproj
@@ -274,7 +274,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
- 07A019EA1ED662D800ACD43E /* MGLImageSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLImageSource_Private.h; sourceTree = "<group>"; };
07A019EB1ED662D800ACD43E /* MGLImageSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLImageSource.h; sourceTree = "<group>"; };
07A019EC1ED662D800ACD43E /* MGLImageSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLImageSource.mm; sourceTree = "<group>"; };
07BA4CAB1EE21887004528F5 /* MGLImageSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLImageSourceTests.m; sourceTree = "<group>"; };
@@ -671,7 +670,6 @@
DA8F25951D51CAC70010E6B5 /* MGLVectorSource.h */,
DA7DC9801DED5F5C0027472F /* MGLVectorSource_Private.h */,
DA8F25961D51CAC70010E6B5 /* MGLVectorSource.mm */,
- 07A019EA1ED662D800ACD43E /* MGLImageSource_Private.h */,
07A019EB1ED662D800ACD43E /* MGLImageSource.h */,
07A019EC1ED662D800ACD43E /* MGLImageSource.mm */,
);
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index a8a84522a5..d2cb5e7100 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -20,6 +20,7 @@
#import "MGLPolyline.h"
#import "MGLAnnotationImage.h"
#import "MGLMapViewDelegate.h"
+#import "MGLImageSource.h"
#import <mbgl/map/map.hpp>
#import <mbgl/map/view.hpp>
@@ -943,13 +944,16 @@ public:
}
}
-- (void)sourceDidChange {
+- (void)sourceDidChange:(MGLSource *)source {
if (!_mbglMap) {
return;
}
-
- [self installAttributionView];
+ // Attribution only applies to tiled sources
+ if ([source isKindOfClass:[MGLTileSource class]]) {
+ [self installAttributionView];
+ }
self.needsUpdateConstraints = YES;
+ self.needsDisplay = YES;
}
#pragma mark Printing
@@ -2847,8 +2851,10 @@ public:
[nativeView mapViewDidFinishLoadingStyle];
}
- void onSourceChanged(mbgl::style::Source&) override {
- [nativeView sourceDidChange];
+ void onSourceChanged(mbgl::style::Source& source) override {
+ NSString *identifier = @(source.getID().c_str());
+ MGLSource * nativeSource = [nativeView.style sourceWithIdentifier:identifier];
+ [nativeView sourceDidChange:nativeSource];
}
mbgl::gl::ProcAddress initializeExtension(const char* name) override {
diff --git a/platform/macos/src/NSImage+MGLAdditions.h b/platform/macos/src/NSImage+MGLAdditions.h
index 0e57784bc5..c08fc57bea 100644
--- a/platform/macos/src/NSImage+MGLAdditions.h
+++ b/platform/macos/src/NSImage+MGLAdditions.h
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier;
-- (mbgl::PremultipliedImage) mgl_PremultipliedImage;
+- (mbgl::PremultipliedImage) mgl_premultipliedImage;
@end
diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm
index e4ef38eea5..6abe53e9ae 100644
--- a/platform/macos/src/NSImage+MGLAdditions.mm
+++ b/platform/macos/src/NSImage+MGLAdditions.mm
@@ -33,7 +33,7 @@
}
- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier {
- mbgl::PremultipliedImage cPremultipliedImage = self.mgl_PremultipliedImage;
+ mbgl::PremultipliedImage cPremultipliedImage = self.mgl_premultipliedImage;
auto imageWidth = cPremultipliedImage.size.width;
return std::make_unique<mbgl::style::Image>([identifier UTF8String],
std::move(cPremultipliedImage),
@@ -41,7 +41,7 @@
[self isTemplate]);
}
-- (mbgl::PremultipliedImage)mgl_PremultipliedImage {
+- (mbgl::PremultipliedImage)mgl_premultipliedImage {
// Create a bitmap image representation from the image, respecting backing
// scale factor and any resizing done on the image at runtime.
// http://www.cocoabuilder.com/archive/cocoa/82430-nsimage-getting-raw-bitmap-data.html#82431