#pragma once
#include "properties.h"
-#include "ease.h"
+#include <functional>
#include <memory>
-#include <vector>
#include <string>
-
-/* Tangram API
- *
- * Primary interface for controlling and managing the lifecycle of a Tangram
- * map surface
- */
+#include <vector>
namespace Tangram {
class DataSource;
-// Create resources and initialize the map view using the scene file at the
-// given resource path
-void initialize(const char* _scenePath);
+struct TouchItem {
+ std::shared_ptr<Properties> properties;
+ float position[2];
+ float distance;
+};
+
+struct SceneUpdate {
+ std::string keys;
+ std::string value;
+};
+
+enum class EaseType : char {
+ linear = 0,
+ cubic,
+ quint,
+ sine,
+};
+
+class Map {
+
+public:
+
+ // Create an empty map object. To display a map, call either loadScene() or loadSceneAsync().
+ Map();
+ ~Map();
+
+ // Load the scene at the given absolute file path asynchronously
+ void loadSceneAsync(const char* _scenePath, bool _useScenePosition = false,
+ std::function<void(void*)> _platformCallback = {}, void *_cbData = nullptr);
+
+ // Load the scene at the given absolute file path synchronously
+ void loadScene(const char* _scenePath, bool _useScenePosition = false);
+
+ // Request an update to the scene configuration; the path is a series of yaml keys
+ // separated by a '.' and the value is a string of yaml to replace the current value
+ // at the given path in the scene
+ void queueSceneUpdate(const char* _path, const char* _value);
+
+ // Apply all previously requested scene updates
+ void applySceneUpdates();
+
+ // Initialize graphics resources; OpenGL context must be created prior to calling this
+ void setupGL();
-// Load the scene at the given absolute file path asynchronously
-void loadSceneAsync(const char* _scenePath, bool _useScenePosition = false,
- std::function<void(void*)> _platformCallback = {}, void *_cbData = nullptr);
-// Load the scene at the given absolute file path synchronously
-void loadScene(const char* _scenePath, bool _useScenePosition = false);
+ // Resize the map view to a new width and height (in pixels)
+ void resize(int _newWidth, int _newHeight);
-// Request an update to the scene configuration; the path is a series of yaml keys
-// separated by a '.' and the value is a string of yaml to replace the current value
-// at the given path in the scene
-void queueSceneUpdate(const char* _path, const char* _value);
+ // Update the map state with the time interval since the last update, returns
+ // true when the current view is completely loaded (all tiles are available and
+ // no animation in progress)
+ bool update(float _dt);
-// Apply all previously requested scene updates
-void applySceneUpdates();
+ // Render a new frame of the map view (if needed)
+ void render();
-// Initialize graphics resources; OpenGL context must be created prior to calling this
-void setupGL();
+ // Gets the viewport height in physical pixels (framebuffer size)
+ int getViewportHeight();
-// Resize the map view to a new width and height (in pixels)
-void resize(int _newWidth, int _newHeight);
+ // Gets the viewport width in physical pixels (framebuffer size)
+ int getViewportWidth();
-// Update the map state with the time interval since the last update, returns
-// true when the current view is completely loaded (all tiles are available and
-// no animation in progress)
-bool update(float _dt);
+ // Set the ratio of hardware pixels to logical pixels (defaults to 1.0)
+ void setPixelScale(float _pixelsPerPoint);
-// Render a new frame of the map view (if needed)
-void render();
+ // Gets the pixel scale
+ float getPixelScale();
-// Set the position of the map view in degrees longitude and latitude; if duration
-// (in seconds) is provided, position eases to the set value over the duration;
-// calling either version of the setter overrides all previous calls
-void setPosition(double _lon, double _lat);
-void setPosition(double _lon, double _lat, float _duration, EaseType _e = EaseType::quint);
+ // Capture a snapshot of the current frame and store it in the allocated _data
+ // _data is expected to be of size getViewportHeight() * getViewportWidth()
+ // Pixel data is stored starting from the lower left corner of the viewport
+ // Each pixel(x, y) would be located at _data[y * getViewportWidth() + x]
+ // Each unsigned int corresponds to an RGBA pixel value
+ void captureSnapshot(unsigned int* _data);
-// Set the values of the arguments to the position of the map view in degrees
-// longitude and latitude
-void getPosition(double& _lon, double& _lat);
+ // Set the position of the map view in degrees longitude and latitude; if duration
+ // (in seconds) is provided, position eases to the set value over the duration;
+ // calling either version of the setter overrides all previous calls
+ void setPosition(double _lon, double _lat);
+ void setPositionEased(double _lon, double _lat, float _duration, EaseType _e = EaseType::quint);
-// Set the fractional zoom level of the view; if duration (in seconds) is provided,
-// zoom eases to the set value over the duration; calling either version of the setter
-// overrides all previous calls
-void setZoom(float _z);
-void setZoom(float _z, float _duration, EaseType _e = EaseType::quint);
+ // Set the values of the arguments to the position of the map view in degrees
+ // longitude and latitude
+ void getPosition(double& _lon, double& _lat);
-// Get the fractional zoom level of the view
-float getZoom();
+ // Set the fractional zoom level of the view; if duration (in seconds) is provided,
+ // zoom eases to the set value over the duration; calling either version of the setter
+ // overrides all previous calls
+ void setZoom(float _z);
+ void setZoomEased(float _z, float _duration, EaseType _e = EaseType::quint);
-// Set the counter-clockwise rotation of the view in radians; 0 corresponds to
-// North pointing up; if duration (in seconds) is provided, rotation eases to the
-// the set value over the duration; calling either version of the setter overrides
-// all previous calls
-void setRotation(float _radians);
-void setRotation(float _radians, float _duration, EaseType _e = EaseType::quint);
+ // Get the fractional zoom level of the view
+ float getZoom();
-// Get the counter-clockwise rotation of the view in radians; 0 corresponds to
-// North pointing up
-float getRotation();
+ // Set the counter-clockwise rotation of the view in radians; 0 corresponds to
+ // North pointing up; if duration (in seconds) is provided, rotation eases to the
+ // the set value over the duration; calling either version of the setter overrides
+ // all previous calls
+ void setRotation(float _radians);
+ void setRotationEased(float _radians, float _duration, EaseType _e = EaseType::quint);
-// Set the tilt angle of the view in radians; 0 corresponds to straight down;
-// if duration (in seconds) is provided, tilt eases to the set value over the
-// duration; calling either version of the setter overrides all previous calls
-void setTilt(float _radians);
-void setTilt(float _radians, float _duration, EaseType _e = EaseType::quint);
+ // Get the counter-clockwise rotation of the view in radians; 0 corresponds to
+ // North pointing up
+ float getRotation();
-// Get the tilt angle of the view in radians; 0 corresponds to straight down
-float getTilt();
+ // Set the tilt angle of the view in radians; 0 corresponds to straight down;
+ // if duration (in seconds) is provided, tilt eases to the set value over the
+ // duration; calling either version of the setter overrides all previous calls
+ void setTilt(float _radians);
+ void setTiltEased(float _radians, float _duration, EaseType _e = EaseType::quint);
-// Given coordinates in screen space (x right, y down), set the output longitude and
-// latitude to the geographic location corresponding to that point; returns false if
-// no geographic position corresponds to the screen location, otherwise returns true
-bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat);
+ // Get the tilt angle of the view in radians; 0 corresponds to straight down
+ float getTilt();
-// Given longitude and latitude coordinates, set the output coordinates to the
-// corresponding point in screen space (x right, y down); returns false if the
-// point is not visible on the screen, otherwise returns true
-bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y);
+ // Set the camera type (0 = perspective, 1 = isometric, 2 = flat)
+ void setCameraType(int _type);
-// Set the ratio of hardware pixels to logical pixels (defaults to 1.0)
-void setPixelScale(float _pixelsPerPoint);
+ // Get the camera type (0 = perspective, 1 = isometric, 2 = flat)
+ int getCameraType();
-// Set the camera type (0 = perspective, 1 = isometric, 2 = flat)
-void setCameraType(int _type);
+ // Given coordinates in screen space (x right, y down), set the output longitude and
+ // latitude to the geographic location corresponding to that point; returns false if
+ // no geographic position corresponds to the screen location, otherwise returns true
+ bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat);
-// Get the camera type (0 = perspective, 1 = isometric, 2 = flat)
-int getCameraType();
+ // Given longitude and latitude coordinates, set the output coordinates to the
+ // corresponding point in screen space (x right, y down); returns false if the
+ // point is not visible on the screen, otherwise returns true
+ bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y);
-// Add a data source for adding drawable map data, which will be styled
-// according to the scene file using the provided data source name;
-void addDataSource(std::shared_ptr<DataSource> _source);
+ // Add a data source for adding drawable map data, which will be styled
+ // according to the scene file using the provided data source name;
+ void addDataSource(std::shared_ptr<DataSource> _source);
-// Remove a data source from the map; returns true if the source was found
-// and removed, otherwise returns false.
-bool removeDataSource(DataSource& _source);
+ // Remove a data source from the map; returns true if the source was found
+ // and removed, otherwise returns false.
+ bool removeDataSource(DataSource& _source);
-void clearDataSource(DataSource& _source, bool _data, bool _tiles);
+ void clearDataSource(DataSource& _source, bool _data, bool _tiles);
-// Respond to a tap at the given screen coordinates (x right, y down)
-void handleTapGesture(float _posX, float _posY);
+ // Respond to a tap at the given screen coordinates (x right, y down)
+ void handleTapGesture(float _posX, float _posY);
-// Respond to a double tap at the given screen coordinates (x right, y down)
-void handleDoubleTapGesture(float _posX, float _posY);
+ // Respond to a double tap at the given screen coordinates (x right, y down)
+ void handleDoubleTapGesture(float _posX, float _posY);
-// Respond to a drag with the given displacement in screen coordinates (x right, y down)
-void handlePanGesture(float _startX, float _startY, float _endX, float _endY);
+ // Respond to a drag with the given displacement in screen coordinates (x right, y down)
+ void handlePanGesture(float _startX, float _startY, float _endX, float _endY);
-// Respond to a fling from the given position with the given velocity in screen coordinates
-void handleFlingGesture(float _posX, float _posY, float _velocityX, float _velocityY);
+ // Respond to a fling from the given position with the given velocity in screen coordinates
+ void handleFlingGesture(float _posX, float _posY, float _velocityX, float _velocityY);
-// Respond to a pinch at the given position in screen coordinates with the given
-// incremental scale
-void handlePinchGesture(float _posX, float _posY, float _scale, float _velocity);
+ // Respond to a pinch at the given position in screen coordinates with the given
+ // incremental scale
+ void handlePinchGesture(float _posX, float _posY, float _scale, float _velocity);
-// Respond to a rotation gesture with the given incremental rotation in radians
-void handleRotateGesture(float _posX, float _posY, float _rotation);
+ // Respond to a rotation gesture with the given incremental rotation in radians
+ void handleRotateGesture(float _posX, float _posY, float _rotation);
-// Respond to a two-finger shove with the given distance in screen coordinates
-void handleShoveGesture(float _distance);
+ // Respond to a two-finger shove with the given distance in screen coordinates
+ void handleShoveGesture(float _distance);
-// Set whether the OpenGL state will be cached between subsequent frames; this improves rendering
-// efficiency, but can cause errors if your application code makes OpenGL calls (false by default)
-void useCachedGlState(bool _use);
+ // Set whether the OpenGL state will be cached between subsequent frames; this improves rendering
+ // efficiency, but can cause errors if your application code makes OpenGL calls (false by default)
+ void useCachedGlState(bool _use);
+
+ const std::vector<TouchItem>& pickFeaturesAt(float _x, float _y);
+
+ // Run this task asynchronously to Tangram's main update loop.
+ void runAsyncTask(std::function<void()> _task);
+
+private:
+
+ class Impl;
+ std::unique_ptr<Impl> impl;
+
+};
enum DebugFlags {
freeze_tiles = 0, // While on, the set of tiles currently being drawn will not update to match the view
// Toggle the boolean state of a debug feature (see debug.h)
void toggleDebugFlag(DebugFlags _flag);
-// Run this task on Tangram's main update loop.
-void runOnMainLoop(std::function<void()> _task);
-
-// Run this task asynchronously to Tangram's main update loop.
-void runAsyncTask(std::function<void()> _task);
-
-// Gets the viewport height in physical pixels (framebuffer size)
-int getViewportHeight();
-
-// Gets the viewport width in physical pixels (framebuffer size)
-int getViewportWidth();
-
-// Gets the pixel scale
-float getPixelScale();
-
-// Capture a snapshot of the current frame and store it in the allocated _data
-// _data is expected to be of size getViewportHeight() * getViewportWidth()
-// Pixel data is stored starting from the lower left corner of the viewport
-// Each pixel(x, y) would be located at _data[y * getViewportWidth() + x]
-// Each unsigned int corresponds to an RGBA pixel value
-void captureSnapshot(unsigned int* _data);
-
-struct TouchItem {
- std::shared_ptr<Properties> properties;
- float position[2];
- float distance;
-};
-
-const std::vector<TouchItem>& pickFeaturesAt(float _x, float _y);
-
-float frameTime();
-
}
});
m_readyCb = callback;
+ // TODO: What to do for multiple instances
setEvasGlAPI(m_api);
initUrlRequests();
// Set up the tangram map.
- Tangram::initialize(NORMAL_SCENE_FILE_PATH);
- Tangram::loadScene(NORMAL_SCENE_FILE_PATH);
+ m_map = new Tangram::Map();
+ m_map->loadScene(NORMAL_SCENE_FILE_PATH);
// Make the GL context current and perform GL setup.
evas_gl_make_current(m_gl, m_surface, m_context);
- Tangram::setupGL();
- Tangram::resize(m_w, m_h);
+ m_map->setupGL();
+ m_map->resize(m_w, m_h);
readyMapCb((void*)view);
m_isInitialized = true;
evas_gl_config_free(m_config);
}
+ if (m_map) {
+ delete m_map;
+ m_map = nullptr;
+ }
+
return MAPZEN_ERROR_NONE;
}
m_w = w;
m_h = h;
evas_gl_make_current(m_gl, m_surface, m_context);
- Tangram::resize(m_w, m_h);
+ m_map->resize(m_w, m_h);
setupOpenGlSurface(view);
}
if (m_zoom != zoom) {
m_zoom = zoom;
- Tangram::setZoom(zoom);
+ m_map->setZoom(zoom);
}
if (m_angle != angle) {
m_angle = angle;
- Tangram::setRotation(degrees_to_radians(angle));
+ m_map->setRotation(degrees_to_radians(angle));
}
double lng = 0, lat = 0;
if (m_lng != lng || m_lat != lat) {
m_lng = lng;
m_lat = lat;
- Tangram::setPosition(m_lng, m_lat);
+ m_map->setPosition(m_lng, m_lat);
}
requestRender();
double x = 0.5 * m_w + (double)delta_x;
double y = 0.5 * m_h + (double)delta_y;
double lng, lat = 0.0;
- Tangram::screenPositionToLngLat(x, y, &lng, &lat);
- Tangram::setPosition(lng, lat);
+ m_map->screenPositionToLngLat(x, y, &lng, &lat);
+ m_map->setPosition(lng, lat);
MAPS_LOGD("Moved with delta x: %d, y: %d to coordinates lon: %f, lat: %f", delta_x, delta_y, lng, lat);
}
double longitude = 0, latitude = 0;
- Tangram::getPosition(longitude, latitude);
+ m_map->getPosition(longitude, latitude);
longitude = wrap_longitude(longitude);
latitude = wrap_latitude(latitude);
}
double longitude = (double)x, latitude = (double)y;
- Tangram::screenPositionToLngLat(x, y, &longitude, &latitude);
+ m_map->screenPositionToLngLat(x, y, &longitude, &latitude);
longitude = wrap_longitude(longitude);
latitude = wrap_latitude(latitude);
maps_coordinates_get_longitude(coord, &lng);
double screenx, screeny;
- Tangram::lngLatToScreenPosition(lng, lat, &screenx, &screeny);
+ m_map->lngLatToScreenPosition(lng, lat, &screenx, &screeny);
*x = (int)screenx;
*y = (int)screeny;
return MAPZEN_ERROR_OUT_OF_MEMORY;
}
- Tangram::captureSnapshot(pixels);
+ m_map->captureSnapshot(pixels);
for (int i = 0; i < m_h; ++i) {
memcpy((unsigned int*)*data + m_w * i, pixels + m_w * (m_h - i - 1), m_w);
return;
}
m_viewType = newViewType;
- Tangram::loadScene(newSceneFile);
+ m_map->loadScene(newSceneFile);
}
}
evas_gl_make_current(tv->m_gl, tv->m_surface, tv->m_context);
tv->m_api->glViewport(0, 0, tv->m_w, tv->m_h);
- Tangram::update(0);
- Tangram::render();
+ if (tv->m_map) {
+ tv->m_map->update(0);
+ tv->m_map->render();
+ MAPS_LOGD("pixelGetCb called on TangramView");
+ } else {
+ MAPS_LOGD("tv->m_map is null, in pixelGelCb");
+ }
- MAPS_LOGD("pixelGetCb called on TangramView");
}
void TangramView::renderingCb(void *data) {