2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "here_view.h"
18 #include <Elementary.h>
20 using namespace HERE_PLUGIN_NAMESPACE_PREFIX;
22 static const char SIG_LOADED[] = "loaded";
25 HERE_PLUGIN_BEGIN_NAMESPACE
38 __isInitialized = false;
59 here_error_e HereView::init(maps_view_h view, maps_plugin_map_view_ready_cb callback)
62 return HERE_ERROR_INVALID_PARAMETER;
64 __idler = ecore_idler_add(__idlerCb, (void*)view);
66 here_error_e error = HERE_ERROR_NONE;
67 int error2 = MAPS_ERROR_NONE;
70 error2 = maps_view_get_viewport(view, &__img);
71 if (error2 != MAPS_ERROR_NONE) break;
73 error2 = maps_view_get_screen_location(view, &__x, &__y, &__w, &__h);
74 if (error2 != MAPS_ERROR_NONE) break;
77 if (error != HERE_ERROR_NONE) break;
79 error = initOpenGLSurface(view);
80 if (error != HERE_ERROR_NONE) break;
82 error = initMap(view, callback);
85 if (error == HERE_ERROR_NONE && error2 != MAPS_ERROR_NONE)
86 error = (here_error_e)ConvertToHereError(error2);
91 here_error_e HereView::initOpenGL()
93 __cfg = evas_gl_config_new();
95 MAPS_LOGE("evas_gl_config_new() failed");
96 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
99 __cfg->color_format = EVAS_GL_RGBA_8888; // Surface Color Format
100 __cfg->depth_bits = EVAS_GL_DEPTH_NONE; // Surface Depth Format
101 __cfg->stencil_bits = EVAS_GL_STENCIL_NONE; // Surface Stencil Format
102 __cfg->options_bits = EVAS_GL_OPTIONS_DIRECT; // Configuration options (here, no extra options)
104 __gl = evas_gl_new(evas_object_evas_get(__img));
106 MAPS_LOGE("evas_gl_new() failed");
107 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
110 __api = evas_gl_api_get(__gl);
112 MAPS_LOGE("evas_gl_api_get() failed");
113 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
116 __ctx = evas_gl_context_create(__gl, NULL);
118 MAPS_LOGE("evas_gl_context_create() failed");
119 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
122 return HERE_ERROR_NONE;
125 here_error_e HereView::initOpenGLSurface(maps_view_h view)
127 if (!view || !__gl || !__cfg || !__img || !__ctx)
128 return HERE_ERROR_INVALID_PARAMETER;
130 evas_object_image_pixels_get_callback_set(__img, NULL, NULL);
133 evas_object_image_native_surface_set(__img, NULL);
134 evas_gl_surface_destroy(__gl, __sfc);
140 evas_object_image_size_set(__img, __w, __h);
142 Evas_Native_Surface ns;
143 __sfc = evas_gl_surface_create(__gl, __cfg, __w, __h);
145 MAPS_LOGE("evas_gl_surface_create() failed");
146 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
149 if (!evas_gl_native_surface_get(__gl, __sfc, &ns)) {
150 evas_gl_make_current(__gl, NULL, NULL);
151 evas_gl_surface_destroy(__gl, __sfc);
153 MAPS_LOGE("evas_gl_native_surface_get() faile");
154 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
157 evas_object_image_native_surface_set(__img, &ns);
158 evas_object_image_pixels_get_callback_set(__img, __pixelGetCb, view);
159 __isInitialized = true;
161 return HERE_ERROR_NONE;
164 here_error_e HereView::initMap(maps_view_h view, maps_plugin_map_view_ready_cb callback)
167 return HERE_ERROR_INVALID_PARAMETER;
169 __map = new (std::nothrow) GeoTiledMap();
171 return HERE_ERROR_OUT_OF_MEMORY;
173 __readyCb = callback;
175 __map->SetReadyMapSignal((GeoTiledMap::ReadyMapSignalFunctor)__readyMapCb, (void *)view);
176 __map->SetEvasGlApi(__api);
177 __map->SetMapSize(Dimension(__w, __h));
179 __visualObjects.set(__map, evas_object_evas_get(__img));
181 return HERE_ERROR_NONE;
184 here_error_e HereView::close(maps_view_h view)
187 return HERE_ERROR_INVALID_PARAMETER;
189 __isInitialized = false;
191 __visualObjects.set(NULL, NULL);
194 evas_object_image_pixels_get_callback_set(__img, NULL, NULL);
197 ecore_idler_del(__idler);
200 __map->SetUpdateMapSignal(NULL);
207 evas_gl_make_current(__gl, __sfc, __ctx);
210 evas_object_image_native_surface_set(__img, NULL);
211 evas_gl_surface_destroy(__gl, __sfc);
214 evas_gl_context_destroy(__gl, __ctx);
221 evas_gl_config_free(__cfg);
223 return HERE_ERROR_NONE;
226 void HereView::__readyMapCb(void *data)
229 int maps_error = maps_view_get_maps_plugin_view_handle((maps_view_h)data, (void**)&hv);
230 if (maps_error != MAPS_ERROR_NONE || !hv) return;
236 void HereView::__pixelGetCb(void *data, Evas_Object *obj)
239 int maps_error = maps_view_get_maps_plugin_view_handle(data, (void**)&hv);
240 if (maps_error != MAPS_ERROR_NONE || !hv ||
241 !hv->__map || !hv->__gl || !hv->__sfc || !hv->__ctx) return;
243 evas_gl_make_current(hv->__gl, hv->__sfc, hv->__ctx);
244 hv->__map->PaintMap(hv->__w, hv->__h);
247 void HereView::__renderingCb(void *data)
250 evas_object_image_pixels_dirty_set((Evas_Object*)data, EINA_TRUE);
253 void HereView::setMapType(maps_view_h view)
258 /* When the theme is changed, clear cache */
259 maps_view_type_e map_type;
260 maps_view_get_type(view, &map_type);
262 bool buildings_enabled = false;
263 maps_view_get_buildings_enabled(view, &buildings_enabled);
265 bool traffic_enabled = false;
266 maps_view_get_traffic_enabled(view, &traffic_enabled);
268 bool public_transit_enabled = false;
269 maps_view_get_public_transit_enabled(view, &public_transit_enabled);
271 GeoTiledMap::MapType hereMapType = HereUtils::Convert(map_type, buildings_enabled,
272 traffic_enabled, public_transit_enabled);
274 if (hereMapType != __map->GetMapType())
276 MAPS_LOGD("Clear cache, because map type is changed.");
278 #ifdef TIZEN_SUPPORT_TILE_FILE_CACHE
279 __map->ClearTileFileCache();
281 __map->SetMapType(hereMapType);
285 here_error_e HereView::renderMap(maps_view_h view, const maps_coordinates_h coord, double zoom, double angle)
288 return HERE_ERROR_INVALID_PARAMETER;
290 if (!__isInitialized || !__map || !__api)
291 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
298 maps_view_get_screen_location(view, &x, &y, &w, &h);
302 if (x != __x || y != __y || w != __w || h != __h) {
308 __api->glViewport(0, 0, __w, __h);
309 __map->SetMapSize(Dimension(__w, __h));
310 initOpenGLSurface(view);
314 GeoTiledMap::UpdateMapSignalFunctor callback = std::tr1::bind(&__renderingCb, __img);
315 __map->SetUpdateMapSignal(callback);
318 if (__map->GetZoomLevel() != zoom) {
320 __map->SetZoomLevel(zoom, false);
324 if (__angle != angle) {
326 __map->SetAngle(angle);
331 maps_coordinates_get_latitude(coord, &lat);
332 maps_coordinates_get_longitude(coord, &lng);
334 GeoCoordinates geoCoord(lat, lng);
337 __map->SetCenter(geoCoord);
339 return HERE_ERROR_NONE;
342 here_error_e HereView::moveCenter(maps_view_h view, int delta_x, int delta_y)
345 return HERE_ERROR_INVALID_PARAMETER;
347 if (!__isInitialized || !__map)
348 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
350 if (delta_x == 0 && delta_y == 0)
351 return HERE_ERROR_NONE;
353 __map->Pan(delta_x, delta_y);
355 return HERE_ERROR_NONE;
358 here_error_e HereView::getCenter(maps_view_h view, maps_coordinates_h *center)
360 if (!view || !center)
361 return HERE_ERROR_INVALID_PARAMETER;
363 if (!__isInitialized || !__map)
364 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
366 GeoCoordinates geoCoord = __map->GetCenter();
367 if (*center == NULL) {
368 maps_coordinates_create(geoCoord.GetLatitude(), geoCoord.GetLongitude(), center);
370 maps_coordinates_set_latitude(*center, geoCoord.GetLatitude());
371 maps_coordinates_set_longitude(*center, geoCoord.GetLongitude());
374 return HERE_ERROR_NONE;
377 here_error_e HereView::setScalebarEnabled(maps_view_h view, bool enable)
380 return HERE_ERROR_INVALID_PARAMETER;
382 if (!__isInitialized || !__map)
383 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
385 __map->SetScalebar(enable);
387 return HERE_ERROR_NONE;
390 here_error_e HereView::getScalebarEnabled(maps_view_h view, bool *enabled)
392 if (!view || !enabled)
393 return HERE_ERROR_INVALID_PARAMETER;
395 if (!__isInitialized || !__map)
396 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
398 *enabled = __map->GetScalebar();
399 return HERE_ERROR_NONE;
402 here_error_e HereView::convertScreenToGeolocation(maps_view_h view, int x, int y, maps_coordinates_h *coord)
405 return HERE_ERROR_INVALID_PARAMETER;
407 if (!__isInitialized || !__map)
408 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
410 Tizen::Maps::Point point(x, y);
411 GeoCoordinates geoCoord = __map->ScreenPositionToCoordinate(point);
412 double lat = geoCoord.GetLatitude();
413 double lng = geoCoord.GetLongitude();
415 int error = maps_coordinates_create(lat, lng, coord);
416 if (error != MAPS_ERROR_NONE)
417 return (here_error_e)ConvertToHereError(error);
419 return HERE_ERROR_NONE;
422 here_error_e HereView::convertGeolocationToScreen(maps_view_h view, const maps_coordinates_h coord, int *x, int *y)
424 if (!view || !x || !y)
425 return HERE_ERROR_INVALID_PARAMETER;
427 if (!__isInitialized || !__map)
428 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
431 maps_coordinates_get_latitude(coord, &lat);
432 maps_coordinates_get_longitude(coord, &lng);
433 GeoCoordinates geoCoord(lat, lng);
434 Tizen::Maps::Point point = __map->CoordinateToScreenPosition(geoCoord);
439 return HERE_ERROR_NONE;
442 here_error_e HereView::getMinZoomLevel(maps_view_h view, int *zoom)
445 return HERE_ERROR_INVALID_PARAMETER;
447 if (!__isInitialized || !__map)
448 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
450 *zoom = (int)__map->GetMinimumZoomLevel();
452 return HERE_ERROR_NONE;
455 here_error_e HereView::getMaxZoomLevel(maps_view_h view, int *zoom)
458 return HERE_ERROR_INVALID_PARAMETER;
460 if (!__isInitialized || !__map)
461 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
463 *zoom = (int)__map->GetMaximumZoomLevel();
465 return HERE_ERROR_NONE;
468 here_error_e HereView::onViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation)
470 if (!view || !object ||
471 operation < MAPS_VIEW_OBJECT_ADD || operation > MAPS_VIEW_OBJECT_REMOVE)
472 return HERE_ERROR_INVALID_PARAMETER;
474 if (!__isInitialized || !__map)
475 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
477 if (__map->GetRootPixmap())
478 __processViewObject(view, object, operation);
480 __pendingObjects.push_back(std::make_pair(object, operation));
482 return HERE_ERROR_NONE;
485 Eina_Bool HereView::__idlerCb(void *data)
488 int maps_error = maps_view_get_maps_plugin_view_handle(data, (void**)&hv);
489 if (maps_error != MAPS_ERROR_NONE || !hv) return true;
490 if (!hv->__map || !hv->__map->GetRootPixmap()) return true;
492 while (hv->__pendingObjects.size()) {
493 PendingObject pending = hv->__pendingObjects.front();
494 hv->__pendingObjects.pop_front();
495 maps_view_object_h object = pending.first;
496 maps_view_object_operation_e operation = pending.second;
498 __processViewObject(data, object, operation);
503 void HereView::__processViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation)
506 int maps_error = maps_view_get_maps_plugin_view_handle(view, (void**)&hv);
507 if (maps_error != MAPS_ERROR_NONE || !hv) return;
509 maps_view_object_type_e type;
510 maps_view_object_get_type(object, &type);
512 if (type < MAPS_VIEW_OBJECT_POLYLINE || type > MAPS_VIEW_OBJECT_MARKER) return;
513 if (operation < MAPS_VIEW_OBJECT_ADD || operation > MAPS_VIEW_OBJECT_REMOVE) return;
515 const char *oper_str[20] = { "ADD", "SET_VISIBLE", "MOVE", "CHANGE", "REMOVE"};
516 const char *type_str[20] = { "POLYLINE", "POLYGON", "MARKER", "ROUTE", "UNKNOWN"};
518 MAPS_LOGD("type=%s, operation=%s, object=%p",
519 (type >= MAPS_VIEW_OBJECT_POLYLINE && type <= MAPS_VIEW_OBJECT_MARKER) ? type_str[type] : "?",
520 (operation >= MAPS_VIEW_OBJECT_ADD && operation <= MAPS_VIEW_OBJECT_REMOVE) ? oper_str[operation] : "?",
525 case MAPS_VIEW_OBJECT_ADD: hv->__visualObjects.add(object); break;
526 case MAPS_VIEW_OBJECT_SET_VISIBLE: hv->__visualObjects.setVisible(object); break;
527 case MAPS_VIEW_OBJECT_CHANGE: hv->__visualObjects.update(object); break;
528 case MAPS_VIEW_OBJECT_REMOVE: hv->__visualObjects.remove(object); break;
533 HERE_PLUGIN_END_NAMESPACE