forked from mapsplugin/ionic-googlemaps-quickdemo-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
15,867 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
docs/plugins/cordova-plugin-device/src/browser/DeviceProxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
cordova.define("cordova-plugin-device.DeviceProxy", function(require, exports, module) { /* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var browser = require('cordova/platform'); | ||
|
||
function getPlatform () { | ||
return 'browser'; | ||
} | ||
|
||
function getModel () { | ||
return getBrowserInfo(true); | ||
} | ||
|
||
function getVersion () { | ||
return getBrowserInfo(false); | ||
} | ||
|
||
function getBrowserInfo (getModel) { | ||
var userAgent = navigator.userAgent; | ||
var returnVal = ''; | ||
var offset; | ||
|
||
if ((offset = userAgent.indexOf('Edge')) !== -1) { | ||
returnVal = (getModel) ? 'Edge' : userAgent.substring(offset + 5); | ||
} else if ((offset = userAgent.indexOf('Chrome')) !== -1) { | ||
returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7); | ||
} else if ((offset = userAgent.indexOf('Safari')) !== -1) { | ||
if (getModel) { | ||
returnVal = 'Safari'; | ||
} else { | ||
returnVal = userAgent.substring(offset + 7); | ||
|
||
if ((offset = userAgent.indexOf('Version')) !== -1) { | ||
returnVal = userAgent.substring(offset + 8); | ||
} | ||
} | ||
} else if ((offset = userAgent.indexOf('Firefox')) !== -1) { | ||
returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8); | ||
} else if ((offset = userAgent.indexOf('MSIE')) !== -1) { | ||
returnVal = (getModel) ? 'MSIE' : userAgent.substring(offset + 5); | ||
} else if ((offset = userAgent.indexOf('Trident')) !== -1) { | ||
returnVal = (getModel) ? 'MSIE' : '11'; | ||
} | ||
|
||
if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) { | ||
returnVal = returnVal.substring(0, offset); | ||
} | ||
|
||
return returnVal; | ||
} | ||
|
||
module.exports = { | ||
getDeviceInfo: function (success, error) { | ||
setTimeout(function () { | ||
success({ | ||
cordova: browser.cordovaVersion, | ||
platform: getPlatform(), | ||
model: getModel(), | ||
version: getVersion(), | ||
uuid: null, | ||
isVirtual: false | ||
}); | ||
}, 0); | ||
} | ||
}; | ||
|
||
require('cordova/exec/proxy').add('Device', module.exports); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
cordova.define("cordova-plugin-device.device", function(require, exports, module) { /* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
|
||
var argscheck = require('cordova/argscheck'); | ||
var channel = require('cordova/channel'); | ||
var utils = require('cordova/utils'); | ||
var exec = require('cordova/exec'); | ||
var cordova = require('cordova'); | ||
|
||
channel.createSticky('onCordovaInfoReady'); | ||
// Tell cordova channel to wait on the CordovaInfoReady event | ||
channel.waitForInitialization('onCordovaInfoReady'); | ||
|
||
/** | ||
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the | ||
* phone, etc. | ||
* @constructor | ||
*/ | ||
function Device () { | ||
this.available = false; | ||
this.platform = null; | ||
this.version = null; | ||
this.uuid = null; | ||
this.cordova = null; | ||
this.model = null; | ||
this.manufacturer = null; | ||
this.isVirtual = null; | ||
this.serial = null; | ||
|
||
var me = this; | ||
|
||
channel.onCordovaReady.subscribe(function () { | ||
me.getInfo(function (info) { | ||
// ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js | ||
// TODO: CB-5105 native implementations should not return info.cordova | ||
var buildLabel = cordova.version; | ||
me.available = true; | ||
me.platform = info.platform; | ||
me.version = info.version; | ||
me.uuid = info.uuid; | ||
me.cordova = buildLabel; | ||
me.model = info.model; | ||
me.isVirtual = info.isVirtual; | ||
me.manufacturer = info.manufacturer || 'unknown'; | ||
me.serial = info.serial || 'unknown'; | ||
channel.onCordovaInfoReady.fire(); | ||
}, function (e) { | ||
me.available = false; | ||
utils.alert('[ERROR] Error initializing Cordova: ' + e); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Get device info | ||
* | ||
* @param {Function} successCallback The function to call when the heading data is available | ||
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) | ||
*/ | ||
Device.prototype.getInfo = function (successCallback, errorCallback) { | ||
argscheck.checkArgs('fF', 'Device.getInfo', arguments); | ||
exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []); | ||
}; | ||
|
||
module.exports = new Device(); | ||
|
||
}); |
183 changes: 183 additions & 0 deletions
183
docs/plugins/cordova-plugin-googlemaps/src/browser/CordovaGoogleMaps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
cordova.define("cordova-plugin-googlemaps.CordovaGoogleMaps", function(require, exports, module) { | ||
|
||
|
||
var PluginMap = require('cordova-plugin-googlemaps.PluginMap'), | ||
PluginStreetViewPanorama = require('cordova-plugin-googlemaps.PluginStreetViewPanorama'), | ||
event = require('cordova-plugin-googlemaps.event'), | ||
Environment = require('cordova-plugin-googlemaps.PluginEnvironment'); | ||
|
||
var MAPS = {}; | ||
|
||
var API_LOADED_STATUS = 0; // 0: not loaded, 1: loading, 2: completed | ||
|
||
document.addEventListener('load_googlemaps', function() { | ||
var envOptions = Environment._getEnv(); | ||
var API_KEY_FOR_BROWSER; | ||
if (envOptions) { | ||
if (location.protocol === 'https:') { | ||
API_KEY_FOR_BROWSER = envOptions.API_KEY_FOR_BROWSER_RELEASE; | ||
} else { | ||
API_KEY_FOR_BROWSER = envOptions.API_KEY_FOR_BROWSER_DEBUG; | ||
} | ||
} | ||
API_LOADED_STATUS = 1; | ||
|
||
var secureStripeScript = document.createElement('script'); | ||
if (API_KEY_FOR_BROWSER) { | ||
secureStripeScript.setAttribute('src','https://maps.googleapis.com/maps/api/js?key=' + API_KEY_FOR_BROWSER); | ||
} else { | ||
// for development only | ||
secureStripeScript.setAttribute('src','https://maps.googleapis.com/maps/api/js'); | ||
} | ||
secureStripeScript.addEventListener('load', function() { | ||
API_LOADED_STATUS = 2; | ||
|
||
var mKeys = Object.keys(MAPS); | ||
mKeys.forEach(function(mkey) { | ||
var map = MAPS[mkey]; | ||
if (!map.get('isGoogleReady')) { | ||
map.trigger('googleready'); | ||
} | ||
}); | ||
}); | ||
|
||
secureStripeScript.addEventListener('error', function(error) { | ||
console.log('Can not load the Google Maps JavaScript API v3'); | ||
console.log(error); | ||
|
||
var mKeys = Object.keys(MAPS); | ||
mKeys.forEach(function(mkey) { | ||
var map = MAPS[mkey]; | ||
if (map) { | ||
map.trigger('load_error'); | ||
} | ||
}); | ||
}); | ||
|
||
document.getElementsByTagName('head')[0].appendChild(secureStripeScript); | ||
|
||
}, { | ||
once: true | ||
}); | ||
|
||
var stub = function(onSuccess) { | ||
onSuccess(); | ||
}; | ||
|
||
var CordovaGoogleMaps = { | ||
resume: stub, | ||
pause: stub, | ||
getMap: function(onSuccess, onError, args) { | ||
// memory cleanup | ||
var mapIDs = Object.keys(MAPS); | ||
mapIDs.forEach(function(mapId) { | ||
var mapDivId = document.querySelector('[__pluginmapid=\'' + mapId + '\']'); | ||
if (!mapDivId) { | ||
if (MAPS[mapDivId]) { | ||
MAPS[mapDivId].destroy(); | ||
} | ||
MAPS[mapDivId] = undefined; | ||
delete MAPS[mapDivId]; | ||
} | ||
}); | ||
|
||
var meta = args[0], | ||
mapId = meta.__pgmId; | ||
args[0] = mapId; | ||
args.unshift(this); | ||
|
||
var pluginMap = new (PluginMap.bind.apply(PluginMap, args)); | ||
MAPS[mapId] = pluginMap; | ||
var dummyObj = {}; | ||
var keys = Object.getOwnPropertyNames(PluginMap.prototype).filter(function (p) { | ||
return typeof PluginMap.prototype[p] === 'function'; | ||
}); | ||
keys.forEach(function(key) { | ||
dummyObj[key] = pluginMap[key].bind(pluginMap); | ||
}); | ||
require('cordova/exec/proxy').add(mapId, dummyObj); | ||
|
||
pluginMap.one(event.MAP_READY, onSuccess); | ||
pluginMap.one('load_error', onError); | ||
|
||
// Does this app already load the google maps library? | ||
API_LOADED_STATUS = (window.google && window.google.maps) ? 2 : API_LOADED_STATUS; | ||
|
||
switch(API_LOADED_STATUS) { | ||
case 0: | ||
cordova.fireDocumentEvent('load_googlemaps', []); | ||
break; | ||
case 2: | ||
pluginMap.trigger('googleready'); | ||
break; | ||
} | ||
}, | ||
removeMap: function(onSuccess, onError, args) { | ||
var mapId = args[0]; | ||
var pluginMap = MAPS[mapId]; | ||
if (pluginMap) { | ||
var map = pluginMap.get('map'); | ||
google.maps.event.clearInstanceListeners(map); | ||
var mapDiv = map.getDiv(); | ||
if (mapDiv) { | ||
mapDiv.parentNode.removeChild(mapDiv); | ||
pluginMap.set('map', undefined); | ||
} | ||
} | ||
pluginMap.destroy(); | ||
pluginMap = null; | ||
MAPS[mapId] = undefined; | ||
delete MAPS[mapId]; | ||
onSuccess(); | ||
}, | ||
|
||
getPanorama: function(onSuccess, onError, args) { | ||
// memory cleanup | ||
var mapIDs = Object.keys(MAPS); | ||
mapIDs.forEach(function(mapId) { | ||
var mapDivId = document.querySelector('[__pluginmapid=\'' + mapId + '\']'); | ||
if (!mapDivId) { | ||
if (MAPS[mapDivId]) { | ||
MAPS[mapDivId].destroy(); | ||
} | ||
MAPS[mapDivId] = undefined; | ||
delete MAPS[mapDivId]; | ||
} | ||
}); | ||
|
||
var meta = args[0], | ||
mapId = meta.__pgmId; | ||
args[0] = mapId; | ||
args.unshift(this); | ||
|
||
var pluginStreetView = new (PluginStreetViewPanorama.bind.apply(PluginStreetViewPanorama, args)); | ||
MAPS[mapId] = pluginStreetView; | ||
var dummyObj = {}; | ||
var keys = Object.getOwnPropertyNames(PluginStreetViewPanorama.prototype).filter(function (p) { | ||
return typeof PluginStreetViewPanorama.prototype[p] === 'function'; | ||
}); | ||
keys.forEach(function(key) { | ||
dummyObj[key] = pluginStreetView[key].bind(pluginStreetView); | ||
}); | ||
require('cordova/exec/proxy').add(mapId, dummyObj); | ||
|
||
pluginStreetView.one(event.PANORAMA_READY, onSuccess); | ||
pluginStreetView.one('load_error', onError); | ||
|
||
// Does this app already load the google maps library? | ||
API_LOADED_STATUS = (window.google && window.google.maps) ? 2 : API_LOADED_STATUS; | ||
|
||
switch(API_LOADED_STATUS) { | ||
case 0: | ||
cordova.fireDocumentEvent('load_googlemaps', []); | ||
break; | ||
case 2: | ||
pluginStreetView.trigger('googleready'); | ||
break; | ||
} | ||
}, | ||
}; | ||
|
||
require('cordova/exec/proxy').add('CordovaGoogleMaps', CordovaGoogleMaps); | ||
|
||
}); |
Oops, something went wrong.