This repository was archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathwikitudePlugin.js
More file actions
151 lines (122 loc) · 4.55 KB
/
wikitudePlugin.js
File metadata and controls
151 lines (122 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Created by yailanderson on 10/06/16.
*/
'use strict';
// install : cordova plugin add https://github.com/Wikitude/wikitude-cordova-plugin.git
(function (angular) {
angular.module('ngCordova.plugins.wikitudePlugin', [])
.factory('$wikitudePlugin', ['$q', '$window', '$exceptionHandler', function ($q, $window, $exceptionHandler) {
return {
/**
* internal listeners for success and error, they are invoked in cordova.exec() function
*/
setInternalListeners: function () {
$window.plugins.wikitudePlugin.prototype.onWikitudeOK = function () {
//success callback
};
$window.plugins.wikitudePlugin.prototype.onWikitudeError = function (error) {
// error callback
throw (error);
};
},
/**
* array of requiredFeatures for instance [ "2d_tracking", "geo" ]
* if no argument is passed the default value is 2d tracking
* @param requiredFeatures
* @returns {*}
*/
isDeviceSupported: function (requiredFeatures) {
// set the internal listeners for success and error
this.setInternalListeners();
var self = this;
var q = $q.defer();
// store features in the $wikitudePlugin for accessing it in all methods
self.features = requiredFeatures || [ '2d_tracking' ];
$window.plugins.wikitudePlugin.isDeviceSupported(function () {
//device supported
q.resolve(self);
}, function () {
//device not supported
q.reject('device not supported!');
}, self.features);
return q.promise;
},
/**
*
* @param worldPath
* @param startupConfiguration
*/
loadARchitectWorld: function (worldPath, startupConfiguration) {
var q = $q.defer();
// startup configuration converted to json
var config = JSON.stringify( startupConfiguration || { 'camera_position': 'back' } );
if (typeof worldPath === 'string') {
$window.plugins.wikitudePlugin.loadARchitectWorld(function (loadedURL) {
// loadedSuccessful
q.resolve(loadedURL);
}, function (errorMessage) {
// error local path is wrong or the remote url returned an error code
q.reject(errorMessage);
},worldPath, this.features, config);
}
return q.promise;
},
/**
* inject a location into the Wikitude SDK
* @param latitude
* @param longitude
* @param altitude
* @param accuracy
*/
setLocation: function (latitude, longitude, altitude, accuracy) {
try {
//inject a location into the Wikitude SDK
$window.plugins.wikitudePlugin.setLocation(latitude, longitude, altitude, accuracy);
} catch (e) {
// handle execption
$exceptionHandler(e.message);
}
},
/**
* The first argument Indicates if the ARchitect
* web view should be included in the generated screenshot or not.
* If a file path or file name is given in the second argument,
* the generated screenshot will be saved in the application bundle.
* Passing null will save the photo in the device photo library
* @param includeWebView
* @param imagePath
* @returns {*}
*/
captureScreen: function (includeWebView, imagePath) {
var q = $q.defer();
$window.plugins.wikitudePlugin.captureScreen(includeWebView, imagePath, function (bundlePath) {
//success
q.resolve(bundlePath);
}, function (error) {
//error
q.reject(error);
});
return q.promise;
},
callJavaScript: function (js) {
try {
$window.plugins.wikitudePlugin.callJavaScript(js);
} catch (e) {
$exceptionHandler(e);
}
},
setOnUrlInvokeCallback: function (onUrlInvokeCallback) {
$window.plugins.wikitudePlugin.setOnUrlInvokeCallback(onUrlInvokeCallback);
},
close: function () {
$window.plugins.wikitudePlugin.close();
},
show: function () {
$window.plugins.wikitudePlugin.show();
},
hide: function () {
$window.plugins.wikitudePlugin.hide();
}
};// end of wikitudePlugin factory
}]);
})(window.angular);