2 * Copyright (c) 2011 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.
18 #include "RouteSegment.h"
19 #include "JSRouteSegment.h"
20 #include "JSSimpleCoordinates.h"
22 #include <CommonsJavaScript/Converter.h>
25 using namespace WrtDeviceApis::CommonsJavaScript;
31 RouteSegment::~RouteSegment()
33 std::vector<RouteStep*>::iterator pos;
34 for( pos = steps.begin() ; pos != steps.end() ; ++pos)
38 JSObjectRef RouteSegment::toJSObject(JSContextRef ctx){
39 Converter convert(ctx);
40 JSObjectRef obj = JSObjectMake(ctx, JSRouteSegment::getClassRef(), NULL);
42 JSObjectRef originObj = JSObjectMake(ctx, Tizen::JSSimpleCoordinates::getClassRef(), NULL);
43 LBSUtil::setProperty(ctx, originObj, "latitude", originLatitude, kJSPropertyAttributeNone);
44 LBSUtil::setProperty(ctx, originObj, "longitude", orginLogitude, kJSPropertyAttributeNone);
45 LBSUtil::setProperty(ctx, obj, "origin", originObj, kJSPropertyAttributeNone);
47 JSObjectRef destObj = JSObjectMake(ctx, Tizen::JSSimpleCoordinates::getClassRef(), NULL);
48 LBSUtil::setProperty(ctx, destObj, "latitude", destLatitude, kJSPropertyAttributeNone);
49 LBSUtil::setProperty(ctx, destObj, "longitude", destLogitude, kJSPropertyAttributeNone);
50 LBSUtil::setProperty(ctx, obj, "destination", destObj, kJSPropertyAttributeNone);
52 LBSUtil::setProperty(ctx, obj, "distance", totalDistance.toJSObject(ctx), kJSPropertyAttributeNone);
53 LBSUtil::setProperty(ctx, obj, "duration", totalDuration.toJSObject(ctx), kJSPropertyAttributeNone);
55 int length = steps.size();
56 JSValueRef* stepsArray = NULL;
57 stepsArray = new JSValueRef[length];
59 for(int i = 0; i < length ; i++){
60 stepsArray[i] = (*(steps[i])).toJSObject(ctx);
62 JSObjectRef stepsObj = JSObjectMakeArray(ctx, length, stepsArray, NULL);
63 LBSUtil::setProperty(ctx, obj, "steps", stepsObj , kJSPropertyAttributeReadOnly);