codesite-noreply at google.com
2009-Dec-13 19:43 UTC
[Mapstraction] [mapstraction] r64 committed - GeoCommons provider working with deferred calls
Revision: 64 Author: ajturner Date: Sun Dec 13 11:10:00 2009 Log: GeoCommons provider working with deferred calls http://code.google.com/p/mapstraction/source/detail?r=64 Modified: /trunk/source/mxn.core.js /trunk/source/mxn.geocommons.core.js /trunk/source/mxn.js /trunk/tests/index.htm ======================================--- /trunk/source/mxn.core.js Sun Dec 13 11:09:52 2009 +++ /trunk/source/mxn.core.js Sun Dec 13 11:10:00 2009 @@ -39,6 +39,9 @@ this.controls = []; this.loaded = {}; this.onload = {}; + this.loaded[api] = true; + this.onload[api] = []; + this.element = element; // option defaults @@ -398,6 +401,26 @@ return this.debug; }; +/** + * Set the api call deferment on or off - When it''s on, mxn.invoke will queue up provider API calls until + * runDeferred is called, at which time everything in the queue will be run in the order it was added. + * @param {Boolean} set deferred to true to turn on deferment + */ +Mapstraction.prototype.setDefer = function(deferred){ + this.loaded[this.api] = !deferred +} + +/** + * Run any queued provider API calls for the methods defined in the provider''s implementation. + * For example, if defferable in mxn.[provider].core.js is set to {getCenter: true, setCenter: true} + * then any calls to map.setCenter or map.getCenter will be queued up in this.onload. When the provider''s + * implementation loads the map, it calls this.runDeferred and any queued calls will be run. + */ +Mapstraction.prototype.runDeferred = function(){ + while(this.onload[this.api].length > 0) { + this.onload[this.api].shift().apply(this) //run deferred calls + } +}, ///////////////////////// // ======================================--- /trunk/source/mxn.geocommons.core.js Sun Dec 13 11:09:56 2009 +++ /trunk/source/mxn.geocommons.core.js Sun Dec 13 11:10:00 2009 @@ -2,6 +2,32 @@ Mapstraction: { + // These methods can be called anytime but will only execute + // once the map has loaded. + deferrable: { + applyOptions: true, + resizeTo: true, + addControls: true, + addSmallControls: true, + addLargeControls: true, + addMapTypeControls: true, + dragging: true, + setCenterAndZoom: true, + getCenter: true, + setCenter: true, + setZoom: true, + getZoom: true, + getZoomLevelForBoundingBox: true, + setMapType: true, + getMapType: true, + getBounds: true, + setBounds: true, + addTileLayer: true, + toggleTileLayer: true, + getPixelRatio: true, + mousePosition: true + }, + init: function(element, api) { var me = this; this.element = element; @@ -11,16 +37,17 @@ F1.Maker.maker_host=''http://localhost:4002''; F1.Maker.finder_host=''http://localhost:4001''; F1.Maker.core_host=''http://localhost:4000''; - url = 7566; + this.loaded[this.api] = false; // Loading will take a little bit. + + url = "1"; new F1.Maker.Map({map_id:url, dom_id:this.element.id, + flashvars: {"map_id":url}, onload: function(map){ me.maps[me.api] = map; - me.loaded[me.api] = true; - console.log("Map loaded, calling methods for " + me.api); - + // f1_swfobject21.getObjectById(this.element.id); + me.loaded[me.api] = true; for (var i = 0; i < me.onload[me.api].length; i++) { - console.log("calling method: " + i); me.onload[me.api][i](); } }}); @@ -81,7 +108,7 @@ getCenter: function() { var map = this.maps[this.api]; var point = map.getCenterZoom()[0]; - return mxn.LatLonPoint(point.lat,point.lon); + return new mxn.LatLonPoint(point.lat,point.lon); }, setCenter: function(point, options) { ======================================--- /trunk/source/mxn.js Sun Dec 13 11:09:56 2009 +++ /trunk/source/mxn.js Sun Dec 13 11:10:00 2009 @@ -59,13 +59,21 @@ // Our special private methods /** * Calls the API specific implementation of a particular method. + * Deferrable: If the API implmentation includes a deferable hash such as { getCenter: true, setCenter: true}, + * then the methods calls mentioned with in it will be queued until runDeferred is called. + * * @private */ 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); + if(typeof(apis[sApiId][sObjName].deferrable) != ''undefined'' && apis[sApiId][sObjName].deferrable[sFnName] === true) { + return mxn.deferUntilLoaded.call(oScope, function(){return apis[sApiId][sObjName][sFnName].apply(oScope, args);} ) + } + else { + return apis[sApiId][sObjName][sFnName].apply(oScope, args); + } }; /** @@ -130,7 +138,14 @@ } return false; }, - + deferUntilLoaded: function(fnCall) { + if(this.loaded[this.api] === false) { + var scope = this; + this.onload[this.api].push( fnCall ) + } else { + return fnCall.call(this) + } + }, /** * Bulk add some named events to an object. * @function ======================================--- /trunk/tests/index.htm Sun Dec 13 11:09:56 2009 +++ /trunk/tests/index.htm Sun Dec 13 11:10:00 2009 @@ -43,12 +43,7 @@ var infoElm = document.getElementById(''info''); var eventsElm = document.getElementById(''events''); -<<<<<<< HEAD:tests/index.htm - m = new mxn.Mapstraction(''map'', ''google''); -======- var m = new mxn.Mapstraction(''map'', ''geocommons''); - m.addOverlay(7566); ->>>>>>> Working on updating GeoCommons provider:tests/index.htm + m = new mxn.Mapstraction(''map'', ''geocommons''); m.endPan.addHandler(function(sEvtName, oEvtSource, oEvtArgs){ var center = oEvtSource.getCenter(); @@ -214,7 +209,7 @@ e.moveNext(); } } - intervalID = setInterval(doNextAction, 2000); + // intervalID = setInterval(doNextAction, 2000); } //]]> @@ -241,7 +236,7 @@ </style> </head> <body> - <div style="margin: 20px;"> + <div style="height: 400px; width: 800px; margin: 20px;"> <div id="map" style="position: relative; width: 500px; height: 300px;"></div> <div style="margin-top: 20px;">