forked from jokeruzzo/ofxMapBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRMMapKit.h
executable file
·201 lines (123 loc) · 5.1 KB
/
RMMapKit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// *
// \
// \
// \
// \
// \
// *
// made by Martijn Mellema
// Interaction Designer from Arnhem, The Netherlands
// www.martijnmellema.nl
#pragma once
#include "ofMain.h"
#include "MapBox.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"
#include "mapController.h"
#include "ofxLocation.h"
#define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))
@class readJSON;
// these are the types you can set for the map
// this is a type, similar to ofPoint, but with better precision for storing latitude and longitude
typedef CLLocationCoordinate2D ofxMapKitLocation;
typedef enum : NSUInteger {
UserTrackingModeNone = 0,
UserTrackingModeFollow = 1,
UserTrackingModeFollowWithHeading = 2
} UserTrackingMode;
class RMMapKit {
public:
RMMapKit();
virtual ~RMMapKit();
// hide the mapview
void close();
// offline map
void offlineMap(string map);
// MBtiles map. If you can host your own map do it with: https://github.com/mapbox/tilestream
void onlineMap(string url);
void retinaDisplay(bool b);
float metersPerPixel();
// returns .longitude .latitude
ofxLocation projectedPointToCoordinate(ofPoint projectedPoint);
// latitude is south/north (-90...90)
// longitude is east/west (-180...180)
// set center (latitude,longitude) of map
void setCenter(double latitude, double longitude, bool animated = true);
// set whether user is allowed to zoom in or not
void setMapZoom(float zoomLevel,bool animated);
// needs to be fixed
void setMinZoom (float minZoom);
// needs to be fixed
void setMaxZoom (float maxZoom);
// set whether user is allowed to scroll the view or not
void setAllowScroll(bool b);
void allowZoom(bool b);
// returns whether the user location is visible in the current map region
bool isUserOnScreen();
// return current center of map (latitude, longitude)
ofxLocation getCenterLocation();
// convert location (latitude, longitude) to screen coordinates (i.e. pixels)
ofPoint getScreenCoordinatesForLocation(double latitude, double longitude);
ofPoint getScreenCoordinatesForLocation(CLLocationCoordinate2D loc);
// convert screen coordinates (i.e. pixels) to location (latitude, longitude)
ofxLocation getLocationForScreenCoordinates(float x, float y);
// convert location (latitude, longitude) to projected point
RMProjectedPoint locationToProjectedPoint(double latitude, double longitude);
// convert projected point to screen coordinates (i.e. pixels)
ofPoint getScreenCoordinatesForProjectedPoint(RMProjectedPoint point);
// convert location (latitude, longitude) and span (in degrees) to screen coordinates (i.e. pixels)
ofRectangle getScreenRectForRegion(double latitude, double latitudeDelta, double longitudeDelta);
// convert location (latitude, longitude) and span (in meters) to screen coordinates (i.e. pixels)
ofRectangle getScreenRectForRegionWithMeters(double latitude, double longitude, double metersLatitude, double metersLongitude);
void geoJSON(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude, bool instructions);
// returns whether the map is open or not
bool isOpen();
// listeners
RMMapView *getMKMapView();
/*
For drawing a route
*/
void addAnnotation(vector<ofxLocation> coordinates, string routeId);
// not finished yet
void addImageMarker(ofxLocation coordinate, string routeId, UIImage* image);
// just a standard marker
void addMarker(ofxLocation coordinates, string routeId);
// creates route from GEOJSON
void addGeoJSON(string data);
// enable/disable annotation
void setAnnotation(string routeId, bool b);
void updateAnnotation(ofxLocation coordinates, string routeId);
// returns if it's possible to zoom
bool bZoom();
// returns zoom level
float getZoom();
// returns if scrolling is enabled
bool bisScrollEnabled();
// sets scrolling
void setScrollEnabled(bool b);
void detectRetina();
double distance(ofxLocation locBegin, ofxLocation locEnd);
// projectionPoint converter
ofxLocation customProjectionPoint(string EPSG, ofPoint location);
bool isUserLocationUpdating();
ofxLocation getUserLocation();
void setUserPosition( double degrees, float zoom);
void setUserPosition( double degrees, ofxLocation loc);
void hideButtons();
void showButtons();
/*
Rotating the map
*/
void rotateMap(double degrees, float seconds);
void rotateUser(UserTrackingMode mode);
void rotateMap(double degrees);
BOOL isRotating();
protected:
vector <CLLocationCoordinate2D> locationData;
readJSON *jsonRoute;
RMMBTilesSource *offlineSource;
RMMapBoxSource *onlineSource;
bool offline;
bool initRoute;
CLLocationCoordinate2D makeCLLocation(double latitude, double longitude);
};