Implements maps_view interface and TangramView 12/80312/2
authorMatt Blair <blair1618@gmail.com>
Thu, 14 Jul 2016 12:21:55 +0000 (08:21 -0400)
committerJongmun Woo <jongmun.woo@samsung.com>
Tue, 19 Jul 2016 01:12:24 +0000 (18:12 -0700)
Change-Id: Ibf45db54d515a09535667e7dc643837a472c1a86

config/scene/scene.yaml [new file with mode: 0644]
include/mapzen_plugin.h
packaging/maps-plugin-mapzen.spec
src/mapzen/mapzen_api.cpp
src/mapzen/mapzen_api.hpp
src/mapzen/mapzen_util.c
src/mapzen/mapzen_util.h
src/mapzen/tangram/tangram.h
src/mapzen/tangram_view.cpp
src/mapzen/tangram_view.hpp
src/mapzen_plugin.c

diff --git a/config/scene/scene.yaml b/config/scene/scene.yaml
new file mode 100644 (file)
index 0000000..f703888
--- /dev/null
@@ -0,0 +1,249 @@
+global:
+    default_order: function() { return feature.sort_key || 0; }
+
+scene:
+    background:
+        color: '#8db7d5'
+cameras:
+    iso-camera:
+        # Manhattan
+        position: [-74.00976419448854, 40.70532700869127, 16]
+        type: isometric
+        axis: [0, 1]
+        active: false
+    perspective-camera:
+        # Manhattan
+        position: [-74.00976419448854, 40.70532700869127, 16]
+        type: perspective
+        fov: 45
+        active: true
+
+lights:
+    light1:
+        type: directional
+        origin: world
+        direction: [1, 1, -1]
+        diffuse: [.3, .3, .3, 1.]
+        ambient: [0.7, 0.7, 0.7, 1.]
+
+styles:
+    flatcolor:
+        base: polygons
+        lighting: false
+    heightglow:
+        base: polygons
+        lighting: vertex
+        shaders:
+            blocks:
+                color: "color.rgb += vec3(worldPosition().z / 800.);"
+    heightglowline:
+        base: lines
+        mix: heightglow
+    dashes:
+        base: lines
+        dash: [1, 1]
+        dash_background_color: lightgrey
+
+sources:
+    osm:
+        type: MVT
+        url:  https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt
+        max_zoom: 16
+        url_params:
+            api_key: vector-tiles-tyHL4AY
+
+layers:
+    touch:
+        data: { source: touch }
+        line:
+          filter: { type: line }
+          draw:
+            lines:
+              color: function () { return feature.color || 'black'; }
+              order: 50
+              width: 2px
+        poly:
+            filter: { type: poly }
+            draw:
+              polygons:
+                color: magenta
+                order: 40
+        point:
+            filter: { type: point }
+            draw:
+              icons:
+                sprite: sunburst
+                collide: false
+                transition:
+                    [show, hide]:
+                        time: 0s
+
+    earth:
+        data: { source: osm }
+        draw:
+            polygons:
+                order: 0
+                color: '#f0ebeb'
+    landuse:
+        data: { source: osm }
+        filter:
+            name: true
+            any:
+                - { $zoom: { min: 9 }, area: { min: 10000000 } }
+                - { $zoom: { min: 10 }, area: { min: 3300000 } }
+                - { $zoom: { min: 12 }, area: { min: 1000000 } }
+                - { $zoom: { min: 13 }, area: { min: 10000 } }
+                - { $zoom: { min: 15 } }
+        draw:
+            polygons:
+                order: 1
+                color: '#fffffa'
+                interactive: true # currently ignored
+        green:
+            filter: { kind: [park, graveyard, cemetery, forest, recreation_ground] }
+            draw:
+                polygons:
+                    order: 2
+                    color: '#89ab84'
+        blue:
+            filter: { kind: [commercial, industrial] }
+            draw:
+                polygons:
+                    color: '#C0CDCD'
+        orange:
+            filter: { kind: [university] }
+            draw:
+                polygons:
+                    color: '#D9CFC3'
+
+    water:
+        data: { source: osm }
+        filter:
+            any:
+                # show smaller water areas at higher zooms
+                - { $zoom: { min: 0 }, area: { min: 10000000 } }
+                - { $zoom: { min: 10 }, area: { min: 1000000 } }
+                - { $zoom: { min: 12 }, area: { min: 100000 } }
+                - { $zoom: { min: 15 }, area: { min: 1000 } }
+                - { $zoom: { min: 18 } }
+        draw:
+            flatcolor:
+                order: 3
+                color: '#8db7d5'
+
+    roads:
+        data: { source: osm }
+        filter:
+            not: { kind: [rail] }
+        draw:
+            lines:
+                color: white
+                width: 12.
+                order: 'function() { return feature.sort_key + 5 || 0 }'
+        rounded:
+            filter: { $zoom: { min: 18 } }
+            draw:
+                lines:
+                    cap: round
+        routes:
+            filter: { $zoom: { max: 10 } }
+            draw:
+                lines:
+                    color: '#aaa'
+                    width: 2.
+        highway:
+            filter: { kind: highway }
+            draw:
+                lines:
+                    color: '#D16768'
+                    width: [[14, 2px], [15, 12]]
+                    outline:
+                        width: [[14, 0], [15, 2]]
+            link:
+                filter: { is_link: yes }
+                draw:
+                    lines:
+                        color: '#aaa'
+                        width: [[13, 1px], [14, 12]]
+        major_road:
+            filter: { kind: major_road, $zoom: { min: 10 } }
+            draw:
+                lines:
+                    color: '#aaaaa4'
+                    width: [[10, 1px], [13, 2px], [14, 2px], [16, 12]]
+                    outline:
+                        width: [[16, 0], [17, 1]]
+        minor_road:
+            filter: { kind: minor_road }
+            draw:
+                lines:
+                    color: '#bbbbb8'
+                    width: [[13, 1px], [14, 1px], [15, 8]]
+                    outline:
+                        width: [[17, 0], [18, 1]]
+        paths:
+            filter: { kind: path }
+            draw:
+                lines:
+                    color: '#fff'
+                    width: [[15, 1px], [17, 2px]]
+                    outline:
+                        width: 0
+        ferries:
+            filter: { kind: ferry }
+            draw:
+                lines:
+                    style: dashes
+        airports:
+            filter: { aeroway: true }
+            draw:
+                lines:
+                    color: '#f00'
+            taxiways:
+                filter: { aeroway: taxiway }
+                draw:
+                    lines:
+                        width: [[13, 1px], [14, 2.0], [17, 5.0]]
+            runways:
+                filter: { aeroway: runway }
+                draw:
+                    lines:
+                        color: [[13, '#FFE4B5'], [16, white]]
+                        width: [[11, 2.], [12, 3.], [13, 4.], [17, 8.]]
+                        order: 39
+                        cap: square
+                        outline:
+                            color: orange
+                            width: [[11, 0], [12, 1.], [17, 2.]]
+
+    buildings:
+        data: { source: osm }
+        filter: { $zoom: { min: 14 } }
+        draw:
+            polygons:
+                style: heightglow
+                order: global.default_order
+                color: [.65, .65, .63]
+        # turn interactive feature selection on for buildings with names
+        interactive:
+            filter: { name: true }
+            draw:
+                polygons:
+                    interactive: true
+        extruded:
+            filter: { $zoom: { min: 15 } }
+            draw:
+                polygons:
+                    extrude: true
+                lines:
+                    style: heightglowline
+                    width: 1.0
+                    color: [.75, .75, .73]
+                    order: function() { return feature.sort_key + 1 || 0; }
+                    extrude: true
+        high-line:
+            filter: {roof_material: grass}
+            draw:
+                polygons:
+                    style: polygons
+                    color: '#bddec5'
index c2d33c8..88e6344 100644 (file)
@@ -66,12 +66,15 @@ int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list
        const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback,
        void *user_data, int *request_id);
 
+int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation);
+
+/* ABOVE METHODS ARE THERE BUT RETURN  MAPS_ERROR_NOT_SUPPORTED */
+
 int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc);
 
 int maps_plugin_destroy_map_view(maps_view_h hView);
 
-int maps_plugin_render_map(maps_view_h hView,
-       const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle);
+int maps_plugin_render_map(maps_view_h hView, const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle);
 
 int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y);
 
@@ -79,10 +82,6 @@ int maps_plugin_set_scalebar(maps_view_h hView, bool enable);
 
 int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled);
 
-int maps_plugin_draw_map(maps_view_h hView, Evas* canvas, int x, int y, int w, int h);
-
-int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation);
-
 int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord);
 
 int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y);
@@ -93,8 +92,7 @@ int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level);
 
 int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center);
 
-/* ABOVE METHODS ARE THERE BUT RETURN  MAPS_ERROR_NOT_SUPPORTED */
-
+int maps_plugin_capture_snapshot(maps_view_h view, void **data, int *width, int *height, maps_view_colorspace_type_e *cs);
 
 int maps_plugin_init_module(maps_plugin_h *plugin, const char *module);
 
index cba92f3..c67e083 100644 (file)
@@ -67,6 +67,9 @@ rm -rf %{buildroot}
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 
+mkdir -p %{buildroot}/usr/share/config/%{name}
+cp -r config/* %{buildroot}/usr/share/config/%{name}/
+
 %post
 /sbin/ldconfig
 
@@ -80,6 +83,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name}
 %{_prefix}/lib/libtangram.so*
 %{_prefix}/lib/pkgconfig/maps-plugin-mapzen.pc
 /usr/share/license/maps-plugin-mapzen
+%{_prefix}/share/config/%{name}/*
 
 %package devel
 Summary:    Tizen Mapzen Maps Plug-in Library (Development)
index f780231..1fe706f 100644 (file)
@@ -231,3 +231,15 @@ int mapzen_get_center(maps_view_h hView, maps_coordinates_h *center)
        }
        return error;
 }
+
+int mapzen_capture_snapshot(maps_view_h hView, void **data, int *width, int *height, maps_view_colorspace_type_e *cs)
+{
+       TangramView* tv = nullptr;
+       int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv);
+       mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error);
+       if (error == MAPZEN_ERROR_NONE && tv) {
+               error = tv->captureSnapshot(hView, data, width, height, cs);
+       }
+       return error;
+}
+
index a73b94d..33f70b3 100644 (file)
@@ -94,6 +94,8 @@ int mapzen_get_max_zoom_level(maps_view_h hView, int *max_zoom_level);
 
 int mapzen_get_center(maps_view_h hView, maps_coordinates_h *center);
 
+int mapzen_capture_snapshot(maps_view_h hView, void **data, int *width, int *height, maps_view_colorspace_type_e *cs);
+
 #ifdef __cplusplus
 }
 #endif
index 31bbd72..012d770 100644 (file)
@@ -30,11 +30,11 @@ void calculate_point(gdouble Lat1, gdouble Lon1, int dBearing, gdouble dist, coo
 
        gdouble dLat = asin(sin(Lat1) * cos(dist / EARTH_RADIUS) + (cos(Lat1) * sin(dist / EARTH_RADIUS) * cos(dBearing)));
 
-       dLat = (180.0 * dLat) / PI;
+       dLat = radians_to_degrees(dLat);
 
        gdouble dLon = Lon1 + atan2(sin(dBearing) * sin(dist / EARTH_RADIUS) * cos(Lat1), cos(dist / EARTH_RADIUS) - sin(Lat1) * sin((dLat / 180.0) * PI));
 
-       dLon = (180.0 * dLon) / PI;
+       dLon = radians_to_degrees(dLon);
 
        if (*coord == NULL)
                *coord = (coords_s *)g_malloc0(sizeof(coords_s));
@@ -45,6 +45,28 @@ void calculate_point(gdouble Lat1, gdouble Lon1, int dBearing, gdouble dist, coo
        }
 }
 
+double wrap_longitude(double longitude)
+{
+       return fmod(longitude, 180.0);
+}
+
+double wrap_latitude(double latitude)
+{
+       return fmod(latitude, 90.0);
+}
+
+double degrees_to_radians(double degrees)
+{
+       static double deg_to_rad = PI / 180.0;
+       return degrees * deg_to_rad;
+}
+
+double radians_to_degrees(double radians)
+{
+       static double rad_to_deg = 180.0 / PI;
+       return radians * rad_to_deg;
+}
+
 int convert_maps_error_to_mapzen_error(int error)
 {
        switch (error) {
index bda7bd5..07784d4 100644 (file)
 
 void calculate_point(gdouble Lat1, gdouble Lon1, int dBearing, gdouble dist, coords_s **coord);
 
+// Return the longitude value wrapped to the range [-180, 180]
+double wrap_longitude(double longitude);
+
+// Return the latitude value wrapped to the range [-90, 90]
+double wrap_latitude(double latitude);
+
+double degrees_to_radians(double degrees);
+double radians_to_degrees(double radians);
+
 int convert_maps_error_to_mapzen_error(int error);
 int convert_mapzen_error_to_maps_error(int error);
 int convert_tangram_view_type_to_maps_view_type(int maps_view_type);
index 30d2d91..9f37b68 100644 (file)
@@ -87,9 +87,15 @@ void setTilt(float _radians, float _duration, EaseType _e = EaseType::quint);
 // Get the tilt angle of the view in radians; 0 corresponds to straight down
 float getTilt();
 
-// Transform coordinates in screen space (x right, y down) into their longitude
-// and latitude in the map view
-void screenToWorldCoordinates(double& _x, double& _y);
+// 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);
+
+// 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 ratio of hardware pixels to logical pixels (defaults to 1.0)
 void setPixelScale(float _pixelsPerPoint);
@@ -162,6 +168,22 @@ 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];
index 9dcadcd..28246e9 100644 (file)
@@ -23,6 +23,9 @@ extern "C" {
 #include "mapzen_plugin_internal.h"
 #include "tangram_view.hpp"
 #include "tangram/tangram.h"
+#include "tangram/platform_tizen.h"
+
+#define NORMAL_SCENE_FILE_PATH "/usr/share/config/maps-plugin-mapzen/scene/scene.yaml"
 
 TangramView::TangramView()
 {
@@ -47,7 +50,7 @@ mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_
        }
 
        maps_error = maps_view_get_screen_location(view, &m_x, &m_y, &m_w, &m_h);
-       if (maps_error == MAPS_ERROR_NONE) {
+       if (maps_error != MAPS_ERROR_NONE) {
                return (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error);
        }
 
@@ -89,11 +92,24 @@ mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_
                return error;
        }
 
+       setRenderCallbackFunction([=](){
+               ecore_main_loop_thread_safe_call_async(&renderingCb, m_image);
+       });
+
+       m_readyCb = callback;
+       setEvasGlAPI(m_api);
+
+       initUrlRequests();
+
        // Set up the tangram map.
-       // TODO: Decide where scene file will be stored and how it will be configurable.
-       Tangram::initialize("scene.yaml");
+       Tangram::initialize(NORMAL_SCENE_FILE_PATH);
+       Tangram::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);
+       readyMapCb((void*)view);
 
        m_isInitialized = true;
 
@@ -179,8 +195,56 @@ mapzen_error_e TangramView::destroy(maps_view_h view)
 
 mapzen_error_e TangramView::render(maps_view_h view, const maps_coordinates_h coord, double zoom, double angle)
 {
-       // TODO
-       return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       if (!view || !coord) {
+               MAPS_LOGE("Render requested with invalid 'view' or 'coord'.");
+               return MAPZEN_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!m_isInitialized) {
+               MAPS_LOGE("Render requested with view that is not initialized.");
+               return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+
+       setMapType(view);
+
+       int x = 0, y = 0, w = 0, h = 0;
+       maps_view_get_screen_location(view, &x, &y, &w, &h);
+       m_w = MAX(m_w, 1);
+       m_h = MAX(m_h, 1);
+
+       if (x != m_x || y != m_y || w != m_w || h != m_h) {
+               m_x = x;
+               m_y = y;
+               m_w = w;
+               m_h = h;
+               evas_gl_make_current(m_gl, m_surface, m_context);
+               Tangram::resize(m_w, m_h);
+               setupOpenGlSurface(view);
+       }
+
+       if (m_zoom != zoom) {
+               m_zoom = zoom;
+               Tangram::setZoom(zoom);
+       }
+
+       if (m_angle != angle) {
+               m_angle = angle;
+               Tangram::setRotation(degrees_to_radians(angle));
+       }
+
+       double lng = 0, lat = 0;
+       maps_coordinates_get_longitude(coord, &lng);
+       maps_coordinates_get_latitude(coord, &lat);
+
+       if (m_lng != lng || m_lat != lat) {
+               m_lng = lng;
+               m_lat = lat;
+               Tangram::setPosition(m_lng, m_lat);
+       }
+
+       requestRender();
+
+       return MAPZEN_ERROR_NONE;
 }
 
 mapzen_error_e TangramView::moveCenter(maps_view_h view, int delta_x, int delta_y)
@@ -201,9 +265,12 @@ mapzen_error_e TangramView::moveCenter(maps_view_h view, int delta_x, int delta_
        // longitude and latitude to set the new center position.
 
        double x = 0.5 * m_w + (double)delta_x;
-       double y = 0.5 * m_h + (double)delta_y; // TODO: Check whether sign of delta_y needs to be flipped.
-       Tangram::screenToWorldCoordinates(x, y);
-       Tangram::setPosition(x, y);
+       double y = 0.5 * m_h + (double)delta_y;
+       double lng, lat = 0.0;
+       Tangram::screenPositionToLngLat(x, y, &lng, &lat);
+       Tangram::setPosition(lng, lat);
+
+       MAPS_LOGD("Moved with delta x: %d, y: %d to coordinates lon: %f, lat: %f", delta_x, delta_y, lng, lat);
 
        return MAPZEN_ERROR_NONE;
 }
@@ -221,6 +288,8 @@ mapzen_error_e TangramView::getCenter(maps_view_h view, maps_coordinates_h *cent
        double longitude = 0, latitude = 0;
        Tangram::getPosition(longitude, latitude);
 
+       longitude = wrap_longitude(longitude);
+       latitude = wrap_latitude(latitude);
        if (*center == nullptr) {
                maps_coordinates_create(latitude, longitude, center);
        } else {
@@ -252,8 +321,10 @@ mapzen_error_e TangramView::convertScreenToGeolocation(maps_view_h view, int x,
        }
 
        double longitude = (double)x, latitude = (double)y;
-       Tangram::screenToWorldCoordinates(longitude, latitude);
+       Tangram::screenPositionToLngLat(x, y, &longitude, &latitude);
 
+       longitude = wrap_longitude(longitude);
+       latitude = wrap_latitude(latitude);
        if (*coord == nullptr) {
                maps_coordinates_create(latitude, longitude, coord);
        } else {
@@ -266,20 +337,39 @@ mapzen_error_e TangramView::convertScreenToGeolocation(maps_view_h view, int x,
 
 mapzen_error_e TangramView::convertGeolocationToScreen(maps_view_h view, const maps_coordinates_h coord, int *x, int *y)
 {
-       // TODO
-       return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       if (!view || !coord) {
+               return MAPZEN_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!m_isInitialized) {
+               return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+
+       double lng, lat;
+       maps_coordinates_get_latitude(coord, &lat);
+       maps_coordinates_get_longitude(coord, &lng);
+
+       double screenx, screeny;
+       Tangram::lngLatToScreenPosition(lng, lat, &screenx, &screeny);
+
+       *x = (int)screenx;
+       *y = (int)screeny;
+
+       return MAPZEN_ERROR_NONE;
 }
 
 mapzen_error_e TangramView::getMinZoomLevel(maps_view_h view, int *zoom)
 {
-       // TODO
-       return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       // TODO: Get the minimum zoom level from the tangram scene.
+       *zoom = 2;
+       return MAPZEN_ERROR_NONE;
 }
 
 mapzen_error_e TangramView::getMaxZoomLevel(maps_view_h view, int *zoom)
 {
-       // TODO
-       return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       // TODO: Get the maximum zoom level from the tangram scene.
+       *zoom = 18;
+       return MAPZEN_ERROR_NONE;
 }
 
 mapzen_error_e TangramView::onViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation)
@@ -288,33 +378,107 @@ mapzen_error_e TangramView::onViewObject(maps_view_h view, const maps_view_objec
        return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
 }
 
-void TangramView::setMapType(maps_view_h view)
+mapzen_error_e TangramView::captureSnapshot(maps_view_h view, void **data, int *width, int *height, maps_view_colorspace_type_e *cs)
 {
-       // TODO
-}
+       if (!view) {
+               return MAPZEN_ERROR_INVALID_PARAMETER;
+       }
 
-Eina_Bool TangramView::idlerCb(void *data)
-{
-       // TODO
-       return false;
+       if (!m_isInitialized) {
+               return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+
+       *data = (void*)malloc(m_w * m_h * sizeof(unsigned int));
+       if (!data) {
+               return MAPZEN_ERROR_OUT_OF_MEMORY;
+       }
+
+       pixelGetCb(view, nullptr);
+       unsigned int *pixels = (unsigned int*)malloc(m_w * m_h * sizeof(unsigned int));
+       Tangram::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);
+       }
+
+       *cs = MAPS_VIEW_COLORSPACE_RGBA8888;
+       *width = m_w;
+       *height = m_h;
+
+       return MAPZEN_ERROR_NONE;
 }
 
-void TangramView::readyMapCb(maps_view_h view)
+
+void TangramView::setMapType(maps_view_h view)
 {
-       // TODO
+       if (!view) {
+               return;
+       }
+
+       // Switches for buildings, traffic, and public transit are not currently implemented.
+
+       // bool buildings_enabled = false;
+       // maps_view_get_buildings_enabled(view, &buildings_enabled);
+
+       // bool traffic_enabled = false;
+       // maps_view_get_traffic_enabled(view, &traffic_enabled);
+
+       // bool public_transit_enabled = false;
+       // maps_view_get_public_transit_enabled(view, &public_transit_enabled);
+
+       maps_view_type_e map_type;
+       maps_view_get_type(view, &map_type);
+
+       tangram_view_type newViewType = (tangram_view_type)convert_maps_view_type_to_tangram_view_type(map_type);
+
+       // Loading a new tangram scene resets the map states/caches.
+       if (newViewType != m_viewType) {
+               const char* newSceneFile = NORMAL_SCENE_FILE_PATH;
+               switch(newViewType) {
+                       case TANGRAM_VIEW_TERRAIN:
+                               // TODO: newSceneFile = path_to_terrain_scene
+                               break;
+                       case TANGRAM_VIEW_NORMAL:
+                               // TODO: newSceneFile = path_to_normal_scene
+                               break;
+                       default:
+                               return;
+               }
+               m_viewType = newViewType;
+               Tangram::loadScene(newSceneFile);
+       }
 }
 
-void TangramView::renderingCb(void *data)
+void TangramView::readyMapCb(void *data)
 {
-       // TODO
+       TangramView *tv = nullptr;
+       int maps_error = maps_view_get_maps_plugin_view_handle((maps_view_h)data, (void**)&tv);
+       if (maps_error != MAPS_ERROR_NONE || !tv) return;
+
+       if (tv->m_readyCb) {
+               tv->m_readyCb(data);
+       }
 }
 
 void TangramView::pixelGetCb(void *data, Evas_Object *obj)
 {
-       // TODO
+       TangramView *tv = nullptr;
+       int maps_error = maps_view_get_maps_plugin_view_handle(data, (void**)&tv);
+       if (maps_error != MAPS_ERROR_NONE || !tv || !tv->m_gl || !tv->m_surface || !tv->m_context) {
+               return;
+       }
+
+       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();
+
+       MAPS_LOGD("pixelGetCb called on TangramView");
 }
 
-void TangramView::processViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation)
-{
-       // TODO
+void TangramView::renderingCb(void *data) {
+       if (!data) {
+               return;
+       }
+       evas_object_image_pixels_dirty_set((Evas_Object*)data, EINA_TRUE);
 }
index 7c50135..6cf5123 100644 (file)
@@ -43,15 +43,14 @@ public:
        mapzen_error_e getMinZoomLevel(maps_view_h view, int *zoom);
        mapzen_error_e getMaxZoomLevel(maps_view_h view, int *zoom);
        mapzen_error_e onViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation);
+       mapzen_error_e captureSnapshot(maps_view_h view, void **data, int *width, int *height, maps_view_colorspace_type_e *cs);
 
 private:
        mapzen_error_e setupOpenGlSurface(maps_view_h view);
        void setMapType(maps_view_h view);
-       static Eina_Bool idlerCb(void *data);
-       static void readyMapCb(maps_view_h view);
+       static void readyMapCb(void *view);
        static void renderingCb(void *data);
        static void pixelGetCb(void *data, Evas_Object *obj);
-       static void processViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation);
 
 private:
 
@@ -64,7 +63,7 @@ private:
 
        bool m_isInitialized = false;
 
-       int m_x = 0; 
+       int m_x = 0;
        int m_y = 0;
        int m_w = 0;
        int m_h = 0;
@@ -73,7 +72,6 @@ private:
        double m_zoom = 0.;
        double m_angle = 0.;
 
-       bool m_redraw = false;
-
        maps_plugin_map_view_ready_cb m_readyCb = nullptr;
+       tangram_view_type m_viewType = TANGRAM_VIEW_NORMAL;
 };
index 15517e1..799b0e1 100644 (file)
@@ -78,34 +78,90 @@ static maps_route_turn_type_e __convert_route_turn_type(int index)
        return type;
 }*/
 
-
-/*MASSIVE TODO:
- *
- * THE TIZEN API REQUIRES A BUNCH MORE FUNCTIONS A LOT OF WHICH HAVE TO DO WITH MAP RENDERING
- * TO BE ABLE TO LOAD THE LIBRARY IN A COMPATIBLE WAY. HERE WE STUB OUT THE METHODS BUT DO NO
- * IMPLEMENTING JUST SO WE CAN TEST THE STUFF WE HAVE DONE...
- */
-
 EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list,
        const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback,
-       void *user_data, int *request_id) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_destroy_map_view(maps_view_h hView) { return MAPS_ERROR_NOT_SUPPORTED; }
+       void *user_data, int *request_id)
+{
+       return  MAPS_ERROR_NOT_SUPPORTED ;
+
+}
+
+EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
+{
+       int ret = mapzen_create_map_view(hView, pCbFunc);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_destroy_map_view(maps_view_h hView)
+{
+       int ret = mapzen_destroy_map_view(hView);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
 EXPORT_API int maps_plugin_render_map(maps_view_h hView,
-       const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_set_scalebar(maps_view_h hView, bool enable) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_draw_map(maps_view_h hView, Evas *canvas, int x, int y, int w, int h) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int *x, int *y) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level) { return MAPS_ERROR_NOT_SUPPORTED; }
-EXPORT_API int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center) { return MAPS_ERROR_NOT_SUPPORTED; }
-
-/*END MASSIVE TODO:
- */
+       const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle)
+{
+       int ret = mapzen_render_map(hView, coordinates, zoom_factor, rotation_angle);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y)
+{
+       int ret = mapzen_move_center(hView, delta_x, delta_y);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_set_scalebar(maps_view_h hView, bool enable)
+{
+
+       return MAPS_ERROR_NOT_SUPPORTED;
+}
+
+EXPORT_API int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled)
+{
+       return MAPS_ERROR_NOT_SUPPORTED;
+}
+
+EXPORT_API int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation)
+{
+       return MAPS_ERROR_NOT_SUPPORTED;
+}
+
+EXPORT_API int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord)
+{
+       int ret = mapzen_screen_to_geography(hView, x, y, mapsCoord);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int *x, int *y)
+{
+       int ret = mapzen_geography_to_screen(hView, mapsCoord, x, y);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level)
+{
+       int ret = mapzen_get_min_zoom_level(hView, min_zoom_level);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level)
+{
+       int ret = mapzen_get_max_zoom_level(hView, max_zoom_level);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_get_center(maps_view_h view, maps_coordinates_h *center)
+{
+       int ret = mapzen_get_center(view, center);
+       return convert_mapzen_error_to_maps_error(ret);
+}
+
+EXPORT_API int maps_plugin_capture_snapshot(maps_view_h view, void **data, int *width, int *height, maps_view_colorspace_type_e *cs)
+{
+       int ret = mapzen_capture_snapshot(view, data, width, height, cs);
+       return convert_mapzen_error_to_maps_error(ret);
+}
 
 EXPORT_API int maps_plugin_init_module(maps_plugin_h *plugin, const char* module)
 {
@@ -165,6 +221,7 @@ EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, bool *su
        case MAPS_SERVICE_SEARCH_ROUTE:
        case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS:
        case MAPS_SERVICE_CANCEL_REQUEST:
+       case MAPS_SERVICE_VIEW:
                *supported = true;
                return MAPS_ERROR_NONE;
        default:
@@ -1044,7 +1101,7 @@ static void __mapzen_place_get_details_cb(mapzen_error_e result, int request_id,
 
        if (result != MAPZEN_ERROR_NONE || places == NULL) {
                MAPS_LOGD("Got places result from ENGINE...result is NULL");
-               calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, NULL, calldata_place->data);
+               calldata_place->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_place->reqID, NULL, calldata_place->data);
        } else {
                guint total_count = 0;
                total_count = g_list_length(places);
@@ -1126,12 +1183,12 @@ static void __mapzen_place_get_details_cb(mapzen_error_e result, int request_id,
                                /*maps_item_list_remove_all(image_list, maps_place_image_destroy); */
                                /*maps_item_list_destroy(image_list); */
 
-                               calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, place, calldata_place->data);
+                               calldata_place->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_place->reqID, place, calldata_place->data);
                                return;
                        }
                }
        }
-       calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, NULL, calldata_place->data);
+       calldata_place->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_place->reqID, NULL, calldata_place->data);
 }
 
 static void __maps_service_search_place_list_cb(mapzen_error_e result, int request_id, GList *places, void *user_data)
@@ -1142,7 +1199,7 @@ static void __maps_service_search_place_list_cb(mapzen_error_e result, int reque
 
        if (result != MAPZEN_ERROR_NONE || places == NULL) {
                MAPS_LOGD("Got places result from ENGINE...result is NULL");
-               calldata_place->callback((maps_error_e) __convert_to_maps_error(result), calldata_place->reqID, 0, NULL, calldata_place->data);
+               calldata_place->callback((maps_error_e) convert_mapzen_error_to_maps_error(result), calldata_place->reqID, 0, NULL, calldata_place->data);
        } else {
                guint total_count = 0;
                total_count = g_list_length(places);
@@ -1231,10 +1288,10 @@ static void __maps_service_search_place_list_cb(mapzen_error_e result, int reque
                                place = NULL;
                                temp_place = temp_place->next;
                        }
-                       calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, total_count, place_list, calldata_place->data);
+                       calldata_place->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_place->reqID, total_count, place_list, calldata_place->data);
 
                } else {
-                       calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, total_count, NULL, calldata_place->data);
+                       calldata_place->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_place->reqID, total_count, NULL, calldata_place->data);
                }
        }
 }
@@ -1527,7 +1584,7 @@ EXPORT_API int maps_plugin_search_place_list(const maps_area_h boundary, const m
 
        int ret = mapzen_search_place_list(place_req, __maps_service_search_place_list_cb, __request_id, (void *) calldata_place);
 
-       return __convert_to_maps_error(ret);
+       return convert_mapzen_error_to_maps_error(ret);
 }
 
 EXPORT_API int maps_plugin_get_place_details(const char *uri, maps_service_get_place_details_cb callback, void *user_data, int *request_id)
@@ -1557,7 +1614,7 @@ EXPORT_API int maps_plugin_get_place_details(const char *uri, maps_service_get_p
 
        int ret = mapzen_get_place_details(place_req, __mapzen_place_get_details_cb, __request_id, (void *) calldata_place);
 
-       return __convert_to_maps_error(ret);
+       return convert_mapzen_error_to_maps_error(ret);
 }
 
 EXPORT_API int maps_plugin_search_place_by_address(const char *address, const maps_area_h boundary, const maps_place_filter_h filter, const maps_preference_h preference, maps_service_search_place_cb callback, void *user_data, int *request_id)