apply new tangram
[platform/core/location/maps-plugin-mapzen.git] / src / mapzen / tangram_view.hpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <maps_plugin.h>
20 #include <maps_service.h>
21 #include <maps_view.h>
22 #include <maps_view_plugin.h>
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25 #include <Evas_GL.h>
26 #include <map>
27 #include <mutex>
28
29 #include "mapzen_types.h"
30 #include "tangram/util/types.h"
31
32 namespace Tangram {
33         class Map;
34 }
35
36 typedef std::map<maps_view_object_h, Tangram::MarkerID> MapViewObjects;
37
38 class TangramView {
39
40 public:
41         TangramView();
42         ~TangramView();
43
44         mapzen_error_e create(maps_view_h view, maps_plugin_map_view_ready_cb callback, const char* providerKey);
45         mapzen_error_e destroy(maps_view_h view);
46         mapzen_error_e render(maps_view_h view, const maps_coordinates_h coord, double zoom, double angle);
47         mapzen_error_e moveCenter(maps_view_h view, int delta_x, int delta_y);
48         mapzen_error_e getCenter(maps_view_h view, maps_coordinates_h *center);
49         mapzen_error_e setScalebarEnabled(maps_view_h view, bool enable);
50         mapzen_error_e getScalebarEnabled(maps_view_h view, bool *enabled);
51         mapzen_error_e convertScreenToGeolocation(maps_view_h view, int x, int y, maps_coordinates_h *coord);
52         mapzen_error_e convertGeolocationToScreen(maps_view_h view, const maps_coordinates_h coord, int *x, int *y);
53         mapzen_error_e getMinZoomLevel(maps_view_h view, int *zoom);
54         mapzen_error_e getMaxZoomLevel(maps_view_h view, int *zoom);
55         mapzen_error_e onViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation);
56         mapzen_error_e captureSnapshot(maps_view_h view, void **data, int *width, int *height, maps_view_colorspace_type_e *cs);
57
58         int getWidth() { return m_w; }
59         int getHeight() { return m_h; }
60
61         void setSceneLoaded(bool sceneLoaded) { m_sceneLoaded = sceneLoaded; }
62         bool isSceneLoaded() { return m_sceneLoaded; }
63
64 private:
65         mapzen_error_e setupOpenGlSurface(maps_view_h view);
66         void setMapType(maps_view_h view);
67
68         mapzen_error_e addObject(maps_view_object_h object);
69         mapzen_error_e setObjectVisible(maps_view_object_h object, Tangram::MarkerID tvMarker);
70         mapzen_error_e getBitmapMarkerImage(maps_view_object_h object, unsigned char *&imgData, int &imgWidth, int &imgHeight);
71         mapzen_error_e updateObject(maps_view_object_h object, Tangram::MarkerID tvMarker);
72         mapzen_error_e updateMarker(maps_view_object_h object, Tangram::MarkerID tvMarker);
73         mapzen_error_e updatePolyline(maps_view_object_h object, Tangram::MarkerID tvMarker);
74         mapzen_error_e updatePolygon(maps_view_object_h object, Tangram::MarkerID tvMarker);
75         mapzen_error_e removeObject(maps_view_object_h object);
76         MapViewObjects& mapViewObjects() { return m_mapViewObjs; }
77         std::mutex& viewObjectMutex() { return m_viewObjectMutex; }
78         void removeAllObjects();
79
80         static void sceneLoadedCb(void *data);
81         static void readyMapCb(void *view);
82         static void renderingCb(void *data);
83         static void pixelGetCb(void *data, Evas_Object *obj);
84         // Emplaces the lng/lat from `coordinate` to `user_data` (Tangram::Coordinates)
85         static bool emplaceCoord(int index, maps_coordinates_h coordinate, void *user_data);
86
87         Tangram::Map *m_map = nullptr;
88         Evas_Object *m_image = nullptr;
89         Evas_GL_Context *m_context = nullptr;
90         Evas_GL_Surface *m_surface = nullptr;
91         Evas_GL_Config *m_config = nullptr;
92         Evas_GL *m_gl = nullptr;
93         Evas_GL_API *m_api = nullptr;
94
95         bool m_isInitialized = false;
96         bool m_publicTransitEnabled = false;
97         bool m_buildingsEnabled = true;
98         bool m_sceneLoaded = false;
99         std::string m_language = "en";
100         std::string m_providerKey = "";
101         bool m_isProviderKeySet = false;
102
103         int m_x = 0;
104         int m_y = 0;
105         int m_w = 0;
106         int m_h = 0;
107         double m_lat = 0.;
108         double m_lng = 0.;
109         double m_zoom = 0.;
110         double m_angle = 0.;
111
112         std::mutex m_viewObjectMutex;
113
114         maps_plugin_map_view_ready_cb m_readyCb = nullptr;
115         tangram_view_type m_viewType = TANGRAM_VIEW_NONE;
116
117         MapViewObjects m_mapViewObjs; //current set of map objects
118 };