Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
squash of #1655: shape annotations support for core & iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Jun 16, 2015
1 parent e75e538 commit bd0bf29
Show file tree
Hide file tree
Showing 43 changed files with 17,075 additions and 263 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Expand Up @@ -17,3 +17,7 @@
[submodule "platform/ios/vendor/SMCalloutView"]
path = platform/ios/vendor/SMCalloutView
url = https://github.com/nfarina/calloutview.git

[submodule "src/mbgl/util/geojsonvt"]
path = src/mbgl/util/geojsonvt
url = https://github.com/mapbox/geojson-vt-cpp
11 changes: 7 additions & 4 deletions Makefile
Expand Up @@ -39,18 +39,21 @@ else
SMCalloutView:
endif

geojsonvt:
git submodule update --init src/mbgl/util/geojsonvt

KIF:
git submodule update --init test/ios/KIF


#### Build files ###############################################################

.PRECIOUS: Makefile/project
Makefile/project: config/$(HOST).gypi styles/styles SMCalloutView
Makefile/project: config/$(HOST).gypi styles/styles SMCalloutView geojsonvt
deps/run_gyp gyp/$(HOST).gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f make

.PRECIOUS: Xcode/project
Xcode/project: config/$(HOST).gypi styles/styles SMCalloutView
Xcode/project: config/$(HOST).gypi styles/styles SMCalloutView geojsonvt
deps/run_gyp gyp/$(HOST).gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f xcode


Expand Down Expand Up @@ -115,7 +118,7 @@ xproj: xosx-proj
#### iOS application builds ####################################################

.PRECIOUS: Xcode/ios
Xcode/ios: gyp/ios.gyp config/ios.gypi styles/styles SMCalloutView
Xcode/ios: gyp/ios.gyp config/ios.gypi styles/styles SMCalloutView geojsonvt
deps/run_gyp gyp/ios.gyp $(CONFIG_ios) $(LIBS_ios) --generator-output=./build/ios -f xcode

.PHONY: ios-proj ios isim ipackage
Expand Down Expand Up @@ -172,7 +175,7 @@ run-xlinux: xlinux

.PRECIOUS: Makefile/android-%
Makefile/android-%: CMD = deps/run_gyp android/mapboxgl-app.gyp $(CONFIG_android-$*) $(LIBS_android) --generator-output=./build/android-$* -f make-android
Makefile/android-%: config/android-%.gypi styles/styles
Makefile/android-%: config/android-%.gypi styles/styles geojsonvt
@echo $(CMD)
@$(ENV_android-$*) $(CMD)

Expand Down
12 changes: 12 additions & 0 deletions gyp/platform-ios.gypi
Expand Up @@ -36,6 +36,18 @@
'../platform/ios/MGLUserLocationAnnotationView.m',
'../include/mbgl/ios/MGLTypes.h',
'../platform/ios/MGLTypes.m',
'../include/mbgl/ios/MGLMultiPoint.h',
'../platform/ios/MGLMultiPoint_Private.h',
'../platform/ios/MGLMultiPoint.mm',
'../include/mbgl/ios/MGLOverlay.h',
'../include/mbgl/ios/MGLPointAnnotation.h',
'../platform/ios/MGLPointAnnotation.m',
'../include/mbgl/ios/MGLPolyline.h',
'../platform/ios/MGLPolyline.m',
'../include/mbgl/ios/MGLPolygon.h',
'../platform/ios/MGLPolygon.m',
'../include/mbgl/ios/MGLShape.h',
'../platform/ios/MGLShape.m',
'../platform/ios/NSBundle+MGLAdditions.h',
'../platform/ios/NSBundle+MGLAdditions.m',
'../platform/ios/NSException+MGLAdditions.h',
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/ios/MGLAnnotation.h
Expand Up @@ -4,7 +4,7 @@

NS_ASSUME_NONNULL_BEGIN

/** The MGLAnnotation protocol is used to provide annotation-related information to a map view. To use this protocol, you adopt it in any custom objects that store or represent annotation data. Each object then serves as the source of information about a single map annotation and provides critical information, such as the annotation’s location on the map. Annotation objects do not provide the visual representation of the annotation but typically coordinate (in conjunction with the map view’s delegate) the creation of an appropriate objects to handle the display.
/** The `MGLAnnotation` protocol is used to provide annotation-related information to a map view. To use this protocol, you adopt it in any custom objects that store or represent annotation data. Each object then serves as the source of information about a single map annotation and provides critical information, such as the annotation’s location on the map. Annotation objects do not provide the visual representation of the annotation but typically coordinate (in conjunction with the map view’s delegate) the creation of an appropriate objects to handle the display.
*
* An object that adopts this protocol must implement the `coordinate` property. The other methods of this protocol are optional. */
@protocol MGLAnnotation <NSObject>
Expand Down
29 changes: 29 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Expand Up @@ -6,6 +6,9 @@
NS_ASSUME_NONNULL_BEGIN

@class MGLUserLocation;
@class MGLPolyline;
@class MGLPolygon;
@class MGLShape;

@protocol MGLMapViewDelegate;
@protocol MGLAnnotation;
Expand Down Expand Up @@ -304,6 +307,30 @@ IB_DESIGNABLE
* @return The marker symbol to display for the specified annotation or `nil` if you want to display the default symbol. */
- (nullable NSString *)mapView:(MGLMapView *)mapView symbolNameForAnnotation:(id <MGLAnnotation>)annotation;

/** Returns the alpha value to use when rendering a shape annotation. Defaults to `1.0`.
* @param mapView The map view rendering the shape annotation.
* @param annotation The annotation being rendered.
* @return An alpha value between `0` and `1.0`. */
- (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation;

/** Returns the stroke color to use when rendering a shape annotation. Defaults to black.
* @param mapView The map view rendering the shape annotation.
* @param annotation The annotation being rendered.
* @return A color to use for the shape outline. */
- (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation;

/** Returns the fill color to use when rendering a polygon annotation. Defaults to blue.
* @param mapView The map view rendering the polygon annotation.
* @param annotation The annotation being rendered.
* @return A color to use for the polygon interior. */
- (UIColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(MGLPolygon *)annotation;

/** Returns the line width to use when rendering a polyline annotation. Defaults to `3.0`.
* @param mapView The map view rendering the polygon annotation.
* @param annotation The annotation being rendered.
* @return A line width for the polyline. */
- (CGFloat)mapView:(MGLMapView *)mapView lineWidthForPolylineAnnotation:(MGLPolyline *)annotation;

/** Returns a Boolean value indicating whether the annotation is able to display extra information in a callout bubble.
*
* If the value returned is `YES`, a standard callout bubble is shown when the user taps a selected annotation. The callout uses the title and subtitle text from the associated annotation object. If there is no title text, though, the annotation will not show a callout. The callout also displays any custom callout views returned by the delegate for the left and right callout accessory views.
Expand Down Expand Up @@ -371,6 +398,8 @@ IB_DESIGNABLE

#pragma mark - Tracking the User Location

/** @name Tracking the User Location */

/** Tells the delegate that the map view will begin tracking the user’s location.
*
* This method is called when the value of the showsUserLocation property changes to `YES`.
Expand Down
17 changes: 17 additions & 0 deletions include/mbgl/ios/MGLMultiPoint.h
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLShape.h"

/** The `MGLMultiPoint` class is an abstract superclass used to define shapes composed of multiple points. You should not create instances of this class directly. Instead, you should create instances of the `MGLPolyline` or `MGLPolygon` classes. However, you can use the method and properties of this class to access information about the specific points associated with the line or polygon. */
@interface MGLMultiPoint : MGLShape

/** The number of points associated with the shape. (read-only) */
@property (nonatomic, readonly) NSUInteger pointCount;

/** Retrieves one or more coordinates associated with the shape.
* @param coords On input, you must provide a C array of structures large enough to hold the desired number of coordinates. On output, this structure contains the requested coordinate data.
* @param range The range of points you want. The `location` field indicates the first point you are requesting, with `0` being the first point, `1` being the second point, and so on. The `length` field indicates the number of points you want. The array in _`coords`_ must be large enough to accommodate the number of requested coordinates. */
- (void)getCoordinates:(CLLocationCoordinate2D *)coords range:(NSRange)range;

@end
31 changes: 31 additions & 0 deletions include/mbgl/ios/MGLOverlay.h
@@ -0,0 +1,31 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLAnnotation.h"
#import "MGLTypes.h"

/** The `MGLOverlay` protocol defines a specific type of annotation that represents both a point and an area on a map. Overlay objects are essentially data objects that contain the geographic data needed to represent the map area. For example, overlays can take the form of common shapes such as rectangles and circles. They can also describe polygons and other complex shapes.
*
* You use overlays to layer more sophisticated content on top of a map view. For example, you could use an overlay to show the boundaries of a national park or trace a bus route along city streets. Mapbox GL defines several concrete classes that conform to this protocol and define standard shapes.
*
* Because overlays are also annotations, they have similar usage pattern to annotations. When added to a map view using the `addOverlay:` method, that view detects whenever the overlay’s defined region intersects the visible portion of the map. At that point, the map view asks its delegate to provide a special overlay view to draw the visual representation of the overlay. If you add an overlay to a map view as an annotation instead, it is treated as an annotation with a single point. */
@protocol MGLOverlay <MGLAnnotation>

/* The approximate center point of the overlay area. (required) (read-only)
*
* This point is typically set to the center point of the map’s bounding rectangle. It is used as the anchor point for any callouts displayed for the annotation. */
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

/** The cooordinate rectangle that encompasses the overlay. (required) (read-only)
*
* This property contains the smallest rectangle that completely encompasses the overlay. Implementers of this protocol must set this area when implementing their overlay class, and after setting it, you must not change it. */
@property (nonatomic, readonly) MGLCoordinateBounds overlayBounds;

/** Returns a Boolean indicating whether the specified rectangle intersects the receiver’s shape.
*
* You can implement this method to provide more specific bounds checking for an overlay. If you do not implement it, the bounding rectangle is used to detect intersections.
* @param overlayBounds The rectangle to intersect with the receiver’s area.
* @return `YES` if any part of the map rectangle intersects the receiver’s shape or `NO` if it does not. */
- (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds;

@end
12 changes: 12 additions & 0 deletions include/mbgl/ios/MGLPointAnnotation.h
@@ -0,0 +1,12 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLShape.h"

/** The `MGLPointAnnotation` class defines a concrete annotation object located at a specified point. You can use this class, rather than define your own, in situations where all you want to do is associate a point on the map with a title. */
@interface MGLPointAnnotation : MGLShape

/** The coordinate point of the annotation, specified as a latitude and longitude. */
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;

@end
17 changes: 17 additions & 0 deletions include/mbgl/ios/MGLPolygon.h
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLMultiPoint.h"
#import "MGLOverlay.h"

/** The `MGLPolygon` class represents a shape consisting of one or more points that define a closed polygon. The points are connected end-to-end in the order they are provided. The first and last points are connected to each other to create the closed shape. */
@interface MGLPolygon : MGLMultiPoint <MGLOverlay>

/** Creates and returns an `MGLPolygon` object from the specified set of coordinates.
* @param coords The array of coordinates defining the shape. The data in this array is copied to the new object.
* @param count The number of items in the _`coords`_ array.
* @return A new polygon object. */
+ (instancetype)polygonWithCoordinates:(CLLocationCoordinate2D *)coords
count:(NSUInteger)count;

@end
17 changes: 17 additions & 0 deletions include/mbgl/ios/MGLPolyline.h
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLMultiPoint.h"
#import "MGLOverlay.h"

/** The `MGLPolyline` class represents a shape consisting of one or more points that define connecting line segments. The points are connected end-to-end in the order they are provided. The first and last points are not connected to each other. */
@interface MGLPolyline : MGLMultiPoint <MGLOverlay>

/** Creates and returns an `MGLPolygon` object from the specified set of coordinates.
* @param coords The array of coordinates defining the shape. The data in this array is copied to the new object.
* @param count The number of items in the _`coords`_ array.
* @return A new polyline object. */
+ (instancetype)polylineWithCoordinates:(CLLocationCoordinate2D *)coords
count:(NSUInteger)count;

@end
14 changes: 14 additions & 0 deletions include/mbgl/ios/MGLShape.h
@@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>

#import "MGLAnnotation.h"

/** The `MGLShape` class is an abstract class that defines the basic properties for all shape-based annotation objects. This class must be subclassed and cannot be used as is. Subclasses are responsible for defining the geometry of the shape and providing an appropriate value for the coordinate property inherited from the `MGLAnnotation` protocol. */
@interface MGLShape : NSObject <MGLAnnotation>

/** The title of the shape annotation. The default value of this property is `nil`. */
@property (nonatomic, copy) NSString *title;

/** The subtitle of the shape annotation. The default value of this property is `nil`. */
@property (nonatomic, copy) NSString *subtitle;

@end
9 changes: 7 additions & 2 deletions include/mbgl/ios/MGLTypes.h
@@ -1,4 +1,5 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#if !__has_feature(nullability)
#define NS_ASSUME_NONNULL_BEGIN
Expand All @@ -13,8 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString * const MGLErrorDomain;

/** The mode used to track the user location on the map. */
typedef NS_ENUM(NSUInteger, MGLUserTrackingMode)
{
typedef NS_ENUM(NSUInteger, MGLUserTrackingMode) {
/** The map does not follow the user location. */
MGLUserTrackingModeNone = 0,
/** The map follows the user location. */
Expand All @@ -23,4 +23,9 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingMode)
MGLUserTrackingModeFollowWithHeading
};

typedef struct {
CLLocationCoordinate2D sw;
CLLocationCoordinate2D ne;
} MGLCoordinateBounds;

NS_ASSUME_NONNULL_END
6 changes: 6 additions & 0 deletions include/mbgl/ios/MapboxGL.h
@@ -1,5 +1,11 @@
#import "MGLAccountManager.h"
#import "MGLAnnotation.h"
#import "MGLMapView.h"
#import "MGLMultiPoint.h"
#import "MGLOverlay.h"
#import "MGLPointAnnotation.h"
#import "MGLPolygon.h"
#import "MGLPolyline.h"
#import "MGLShape.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"
26 changes: 21 additions & 5 deletions include/mbgl/map/map.hpp
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/vec.hpp>
Expand All @@ -13,6 +14,7 @@
#include <functional>
#include <vector>
#include <memory>
#include <unordered_map>

namespace mbgl {

Expand All @@ -26,6 +28,16 @@ namespace util {
template <class T> class Thread;
}

enum class AnnotationType : uint8_t {
Any = 0,
Point = 1 << 0,
Shape = 1 << 1,
};

using AnnotationIDs = std::vector<uint32_t>;
using AnnotationSegment = std::vector<LatLng>;
using AnnotationSegments = std::vector<AnnotationSegment>;

class Map : private util::noncopyable {
friend class View;

Expand Down Expand Up @@ -112,12 +124,16 @@ class Map : private util::noncopyable {
void setDefaultPointAnnotationSymbol(const std::string&);
double getTopOffsetPixelsForAnnotationSymbol(const std::string&);
uint32_t addPointAnnotation(const LatLng&, const std::string& symbol);
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>&,
const std::vector<std::string>& symbols);
AnnotationIDs addPointAnnotations(const AnnotationSegment&,
const std::vector<std::string>& symbols);
uint32_t addShapeAnnotation(const AnnotationSegments&,
const StyleProperties&);
AnnotationIDs addShapeAnnotations(const std::vector<AnnotationSegments>&,
const std::vector<StyleProperties>&);
void removeAnnotation(uint32_t);
void removeAnnotations(const std::vector<uint32_t>&);
std::vector<uint32_t> getAnnotationsInBounds(const LatLngBounds&);
LatLngBounds getBoundsForAnnotations(const std::vector<uint32_t>&);
void removeAnnotations(const AnnotationIDs&);
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const AnnotationType& = AnnotationType::Any);
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&);

// Memory
void setSourceTileCacheSize(size_t);
Expand Down
Expand Up @@ -3,7 +3,6 @@

#include <mbgl/util/variant.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/piecewisefunction_properties.hpp>

#include <array>
#include <string>
Expand Down
File renamed without changes.
14 changes: 13 additions & 1 deletion include/mbgl/util/geo.hpp
Expand Up @@ -41,12 +41,24 @@ struct LatLngBounds {
if (point.longitude > ne.longitude) ne.longitude = point.longitude;
}

inline bool contains(const LatLng& point) {
inline void extend(const LatLngBounds& bounds) {
extend(bounds.sw);
extend(bounds.ne);
}

inline bool contains(const LatLng& point) const {
return (point.latitude >= sw.latitude &&
point.latitude <= ne.latitude &&
point.longitude >= sw.longitude &&
point.longitude <= ne.longitude);
}

inline bool intersects(const LatLngBounds area) const {
return (area.ne.latitude > sw.latitude &&
area.sw.latitude < ne.latitude &&
area.ne.longitude > sw.longitude &&
area.sw.longitude < ne.longitude);
}
};

}
Expand Down
12 changes: 0 additions & 12 deletions ios/app/MBXAnnotation.h

This file was deleted.

0 comments on commit bd0bf29

Please sign in to comment.