123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- (function() {
- var providers = null;
- var modules = 'core';
- var scriptBase;
- var scripts = document.getElementsByTagName('script');
-
- for (var i = 0; i < scripts.length; i++) {
- var match = scripts[i].src.replace(/%20/g , '').match(/^(.*?)mxn\.js(\?\(\[?(.*?)\]?\))?$/);
- if (match != null) {
- scriptBase = match[1];
- if (match[3]) {
- var settings = match[3].split(',[');
- providers = settings[0].replace(']' , '');
- if (settings[1]) modules += ',' + settings[1];
- }
- break;
- }
- }
- if (providers == null || providers == 'none') return;
- providers = providers.replace(/ /g, '').split(',');
- modules = modules.replace(/ /g, '').split(',');
-
- for (i = 0; i < modules.length; i++) {
- document.write("<script type='text/javascript' src='" + scriptBase + 'mxn.' + modules[i] + '.js' + "'></script>");
- for (var j = 0; j < providers.length; j++) document.write("<script type='text/javascript' src='" + scriptBase + 'mxn.' + providers[j] + '.' + modules[i] + '.js' + "'></script>");
- }
- })();
- (function(){
- var apis = {};
- var invoke = function(sApiId, sObjName, sFnName, oScope, args){
- if(!hasImplementation(sApiId, sObjName, sFnName)) {
- throw 'Method ' + sFnName + ' of object ' + sObjName + ' is not supported by API ' + sApiId + '. Are you missing a script tag?';
- }
- return apis[sApiId][sObjName][sFnName].apply(oScope, args);
- };
- var hasImplementation = function(sApiId, sObjName, sFnName){
- if(typeof(apis[sApiId]) == 'undefined') {
- throw 'API ' + sApiId + ' not loaded. Are you missing a script tag?';
- }
- if(typeof(apis[sApiId][sObjName]) == 'undefined') {
- throw 'Object definition ' + sObjName + ' in API ' + sApiId + ' not loaded. Are you missing a script tag?';
- }
- return typeof(apis[sApiId][sObjName][sFnName]) == 'function';
- };
- var mxn = window.mxn = {
-
- register: function(sApiId, oApiImpl){
- if(!apis.hasOwnProperty(sApiId)){
- apis[sApiId] = {};
- }
- mxn.util.merge(apis[sApiId], oApiImpl);
- },
-
- addProxyMethods: function(func, aryMethods, bWithApiArg){
- for(var i = 0; i < aryMethods.length; i++) {
- var sMethodName = aryMethods[i];
- if(bWithApiArg){
- func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments, { overrideApi: true } );');
- }
- else {
- func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments);');
- }
- }
- },
-
-
- addEvents: function(oEvtSrc, aEvtNames){
- for(var i = 0; i < aEvtNames.length; i++){
- var sEvtName = aEvtNames[i];
- if(sEvtName in oEvtSrc){
- throw 'Event or method ' + sEvtName + ' already declared.';
- }
- oEvtSrc[sEvtName] = new mxn.Event(sEvtName, oEvtSrc);
- }
- }
- };
- mxn.Event = function(sEvtName, oEvtSource){
- var handlers = [];
- if(!sEvtName){
- throw 'Event name must be provided';
- }
-
- this.addHandler = function(fn, ctx){
- handlers.push({context: ctx, handler: fn});
- };
-
- this.removeHandler = function(fn, ctx){
- for(var i = 0; i < handlers.length; i++){
- if(handlers[i].handler == fn && handlers[i].context == ctx){
- handlers.splice(i, 1);
- }
- }
- };
-
- this.removeAllHandlers = function(){
- handlers = [];
- };
-
- this.fire = function(oEvtArgs){
- var args = [sEvtName, oEvtSource, oEvtArgs];
- for(var i = 0; i < handlers.length; i++){
- handlers[i].handler.apply(handlers[i].context, args);
- }
- };
- };
- mxn.Invoker = function(aobj, asClassName, afnApiIdGetter){
- var obj = aobj;
- var sClassName = asClassName;
- var fnApiIdGetter = afnApiIdGetter;
- var defOpts = {
- overrideApi: false,
- context: null,
- fallback: null
- };
-
- this.go = function(sMethodName, args, oOptions){
- if(typeof(oOptions) == 'undefined'){
- oOptions = defOpts;
- }
- var sApiId = oOptions.overrideApi ? args[0] : fnApiIdGetter.apply(obj);
- if(typeof(sApiId) != 'string'){
- throw 'API ID not available.';
- }
- if(typeof(oOptions.context) != 'undefined' && oOptions.context !== null){
-
- args = Array.prototype.slice.apply(args);
- args.push(oOptions.context);
- }
- if(typeof(oOptions.fallback) == 'function' && !hasImplementation(sApiId, sClassName, sMethodName)){
-
- return oOptions.fallback.apply(obj, args);
- }
- else {
- return invoke(sApiId, sClassName, sMethodName, obj, args);
- }
- };
- };
- mxn.util = {
-
- merge: function(oRecv, oGive){
- for (var sPropName in oGive){
- if (oGive.hasOwnProperty(sPropName)) {
- if(!oRecv.hasOwnProperty(sPropName)){
- oRecv[sPropName] = oGive[sPropName];
- }
- else {
- mxn.util.merge(oRecv[sPropName], oGive[sPropName]);
- }
- }
- }
- },
-
- $m: function() {
- var elements = [];
- for (var i = 0; i < arguments.length; i++) {
- var element = arguments[i];
- if (typeof(element) == 'string') {
- element = document.getElementById(element);
- }
- if (arguments.length == 1) {
- return element;
- }
- elements.push(element);
- }
- return elements;
- },
-
- loadScript: function(src, callback) {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = src;
- if (callback) {
- if(script.addEventListener){
- script.addEventListener('load', callback, true);
- }
- else if(script.attachEvent){
- var done = false;
- script.attachEvent("onreadystatechange",function(){
- if ( !done && document.readyState === "complete" ) {
- done = true;
- callback();
- }
- });
- }
- }
- var h = document.getElementsByTagName('head')[0];
- h.appendChild( script );
- return;
- },
-
- convertLatLonXY_Yahoo: function(point, level) {
- var size = 1 << (26 - level);
- var pixel_per_degree = size / 360.0;
- var pixel_per_radian = size / (2 * Math.PI);
- var origin = new YCoordPoint(size / 2 , size / 2);
- var answer = new YCoordPoint();
- answer.x = Math.floor(origin.x + point.lon * pixel_per_degree);
- var sin = Math.sin(point.lat * Math.PI / 180.0);
- answer.y = Math.floor(origin.y + 0.5 * Math.log((1 + sin) / (1 - sin)) * -pixel_per_radian);
- return answer;
- },
-
- loadStyle: function(href) {
- var link = document.createElement('link');
- link.type = 'text/css';
- link.rel = 'stylesheet';
- link.href = href;
- document.getElementsByTagName('head')[0].appendChild(link);
- return;
- },
-
- getStyle: function(el, prop) {
- var y;
- if (el.currentStyle) {
- y = el.currentStyle[prop];
- }
- else if (window.getComputedStyle) {
- y = window.getComputedStyle( el, '').getPropertyValue(prop);
- }
- return y;
- },
-
- lonToMetres: function(lon, lat) {
- return lon * (111200 * Math.cos(lat * (Math.PI / 180)));
- },
-
- metresToLon: function(m, lat) {
- return m / (111200 * Math.cos(lat * (Math.PI / 180)));
- },
-
- KMToMiles: function(km) {
- return km / 1.609344;
- },
-
- milesToKM: function(miles) {
- return miles * 1.609344;
- },
-
- logN: function(number, base) {
- return Math.log(number) / Math.log(base);
- },
-
- getAvailableProviders : function () {
- var providers = [];
- for (var propertyName in apis){
- if (apis.hasOwnProperty(propertyName)) {
- providers.push(propertyName);
- }
- }
- return providers;
- }
- };
- mxn.util.Color = function() {
- if(arguments.length == 3) {
- this.red = arguments[0];
- this.green = arguments[1];
- this.blue = arguments[2];
- }
- else if(arguments.length == 1) {
- this.setHexColor(arguments[0]);
- }
- };
- mxn.util.Color.prototype.reHex = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
- mxn.util.Color.prototype.setHexColor = function(strHexColor) {
- var match = strHexColor.match(this.reHex);
- if(match) {
- strHexColor = match[1];
- }
- else {
- throw 'Invalid HEX color format, expected #000, 000, #000000 or 000000';
- }
- if(strHexColor.length == 3) {
- strHexColor = strHexColor.replace(/\w/g, function(str){return str.concat(str);});
- }
- this.red = parseInt(strHexColor.substr(0,2), 16);
- this.green = parseInt(strHexColor.substr(2,2), 16);
- this.blue = parseInt(strHexColor.substr(4,2), 16);
- };
- mxn.util.Color.prototype.getHexColor = function() {
- var vals = [this.red.toString(16), this.green.toString(16), this.blue.toString(16)];
- for(var i = 0; i < vals.length; i++) {
- vals[i] = (vals[i].length == 1) ? '0' + vals[i] : vals[i];
- vals[i] = vals[i].toUpperCase();
- }
- return vals.join('');
- };
- })();
|