codesite-noreply at google.com
2009-May-31 18:14 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
Author: robert.moran Date: Sun May 31 11:13:23 2009 New Revision: 11 Modified: trunk/source/mxn.core.js trunk/source/mxn.js trunk/source/mxn.yahoo.core.js trunk/tests/index.htm Log: Added functionality to automatically load scripts needed. Allowed mapstraction default constructor to have provider omitted (will use first loaded provider). Minor change to yahoo implementation - syntax/spelling error. Modified: trunk/source/mxn.core.js =============================================================================--- trunk/source/mxn.core.js (original) +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 @@ -14,11 +14,12 @@ /** * Mapstraction instantiates a map with some API choice into the HTML element given * @param {String} element The HTML element to replace with a map - * @param {String} api The API to use, one of ''google'', ''yahoo'', ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' + * @param {String} api The API to use, one of ''google'', ''yahoo'', ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. If omitted, first loaded provider implementation is used. * @param {Bool} debug optional parameter to turn on debug support - this uses alert panels for unsupported actions * @constructor */ var Mapstraction = mxn.Mapstraction = function(element, api, debug) { + if (!api) api = mxn.util.getAvailableProviders()[0]; this.api = api; this.maps = {}; this.currentElement = $m(element); Modified: trunk/source/mxn.js =============================================================================--- trunk/source/mxn.js (original) +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 @@ -3,8 +3,56 @@ // holds all our implementing functions var apis = {}; + // ''Constructor'' + (function() { + // Defaults + var providers = ''google,yahoo,microsoft''; + 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; + } + } + providers = providers.replace(/ /g, '''').split('',''); + modules = modules.replace(/ /g, '''').split('',''); + for (var i = 0; i < modules.length; i++) { + loadScript(scriptBase + ''mxn.'' + modules[i] + ''.js''); + for (var j = 0; j < providers.length; j++) loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); + } + })(); + // Our special private methods /** + * loadScript is a JSON data fetcher + * @param {String} src URL to JSON file + * @param {Function} callback Callback function + */ + function loadScript(src, callback) { + var script = document.createElement(''script''); + script.type = ''text/javascript''; + script.src = src; + if (callback) { + var evl = {}; + evl.handleEvent = function(e) { + callback(); + }; + script.addEventListener(''load'' ,evl ,true); + } + document.getElementsByTagName(''head'')[0].appendChild(script); + return; + }; + + /** * Calls the API specific implementation of a particular method. */ var invoke = function(sApiId, sObjName, sFnName, oScope, args){ @@ -29,14 +77,14 @@ }; return { - + /** * Registers a set of provider specific implementation functions. */ register: function(sApiId, oApiImpl){ if(!apis.hasOwnProperty(sApiId)) apis[sApiId] = {}; mxn.util.merge(apis[sApiId], oApiImpl); - }, + }, /** * Adds a list of named proxy methods to the prototype of a @@ -202,21 +250,8 @@ * @param {String} src URL to JSON file * @param {Function} callback Callback function */ - loadScript: function(src, callback) { - var script = document.createElement(''script''); - script.type = ''text/javascript''; - script.src = src; - if (callback) { - var evl = {}; - evl.handleEvent = function(e) { - callback(); - }; - script.addEventListener(''load'' ,evl ,true); - } - document.getElementsByTagName(''head'')[0].appendChild(script); - return; - }, - + loadScript: loadScript, + /** * * @param {Object} point @@ -334,6 +369,16 @@ logN: function(number, base) { return Math.log(number) / Math.log(base); }, + + /** + * returns array of loaded provider apis + * @returns {Array} providers + */ + getAvailableProviders : function () { + var providers = []; + for (var propertyName in apis) providers.push(propertyName); + return providers; + }, dummy: 0 @@ -341,4 +386,5 @@ dummy: 0 }; + })(); Modified: trunk/source/mxn.yahoo.core.js =============================================================================--- trunk/source/mxn.yahoo.core.js (original) +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 @@ -1,5 +1,4 @@ -mxn.register('' -oo'', { +mxn.register(''yahoo'', { Mapstraction: { Modified: trunk/tests/index.htm =============================================================================--- trunk/tests/index.htm (original) +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 @@ -7,11 +7,7 @@ <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> <script src="domReady.js" type="text/javascript"></script> - <script src="../source/mxn.js" type="text/javascript"></script> - <script src="../source/mxn.core.js" type="text/javascript"></script> - <script src="../source/mxn.google.core.js" type="text/javascript"></script> - <script src="../source/mxn.yahoo.core.js" type="text/javascript"></script> - <script src="../source/mxn.microsoft.core.js" type="text/javascript"></script> + <script src="../source/mxn.js?(google, yahoo, microsoft)" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ @@ -40,7 +36,7 @@ var infoElm = document.getElementById(''info''); var eventsElm = document.getElementById(''events''); - var m = new mxn.Mapstraction(''map'', ''microsoft''); + var m = new mxn.Mapstraction(''map''); m.endPan.addHandler(function(sEvtName, oEvtSource, oEvtArgs){ var center = oEvtSource.getCenter(); @@ -136,7 +132,7 @@ { desc: ''Swap API'', action: function(){ - m.swap(''map'', ''google''); + m.swap(''map'', ''microsoft''); } },
Rob
2009-May-31 18:45 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
FYI, these changes allow the following: Declaring a mapstraction object without a provider: *var m = new mxn.Mapstraction(''map'');* will make the system default to the first loaded provider. Have also implemented the preloading javascript functionality, so only a single script reference is now required: <script src="../source/mxn.js?(google)" type="text/javascript"></script> -or- <script src="../source/mxn.js?(google, yahoo, microsoft)" type="text/javascript"></script> Cheers, Rob 2009/5/31 <codesite-noreply at google.com>> Author: robert.moran > Date: Sun May 31 11:13:23 2009 > New Revision: 11 > > Modified: > trunk/source/mxn.core.js > trunk/source/mxn.js > trunk/source/mxn.yahoo.core.js > trunk/tests/index.htm > > Log: > Added functionality to automatically load scripts needed. > Allowed mapstraction default constructor to have provider omitted (will use > first loaded provider). > Minor change to yahoo implementation - syntax/spelling error. > > > Modified: trunk/source/mxn.core.js > > =============================================================================> --- trunk/source/mxn.core.js (original) > +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 > @@ -14,11 +14,12 @@ > /** > * Mapstraction instantiates a map with some API choice into the HTML > element given > * @param {String} element The HTML element to replace with a map > - * @param {String} api The API to use, one of ''google'', ''yahoo'', > ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' > + * @param {String} api The API to use, one of ''google'', ''yahoo'', > ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. > If omitted, first loaded provider implementation is used. > * @param {Bool} debug optional parameter to turn on debug support - this > uses alert panels for unsupported actions > * @constructor > */ > var Mapstraction = mxn.Mapstraction = function(element, api, debug) { > + if (!api) api = mxn.util.getAvailableProviders()[0]; > this.api = api; > this.maps = {}; > this.currentElement = $m(element); > > Modified: trunk/source/mxn.js > > =============================================================================> --- trunk/source/mxn.js (original) > +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 > @@ -3,8 +3,56 @@ > // holds all our implementing functions > var apis = {}; > > + // ''Constructor'' > + (function() { > + // Defaults > + var providers = ''google,yahoo,microsoft''; > + 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; > + } > + } > + providers = providers.replace(/ /g, '''').split('',''); > + modules = modules.replace(/ /g, '''').split('',''); > + for (var i = 0; i < modules.length; i++) { > + loadScript(scriptBase + ''mxn.'' + modules[i] + > ''.js''); > + for (var j = 0; j < providers.length; j++) > loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); > + } > + })(); > + > // Our special private methods > /** > + * loadScript is a JSON data fetcher > + * @param {String} src URL to JSON file > + * @param {Function} callback Callback function > + */ > + function loadScript(src, callback) { > + var script = document.createElement(''script''); > + script.type = ''text/javascript''; > + script.src = src; > + if (callback) { > + var evl = {}; > + evl.handleEvent = function(e) { > + callback(); > + }; > + script.addEventListener(''load'' ,evl ,true); > + } > + > document.getElementsByTagName(''head'')[0].appendChild(script); > + return; > + }; > + > + /** > * Calls the API specific implementation of a particular method. > */ > var invoke = function(sApiId, sObjName, sFnName, oScope, args){ > @@ -29,14 +77,14 @@ > }; > > return { > - > + > /** > * Registers a set of provider specific implementation > functions. > */ > register: function(sApiId, oApiImpl){ > if(!apis.hasOwnProperty(sApiId)) apis[sApiId] = {}; > mxn.util.merge(apis[sApiId], oApiImpl); > - }, > + }, > > /** > * Adds a list of named proxy methods to the prototype of a > @@ -202,21 +250,8 @@ > * @param {String} src URL to JSON file > * @param {Function} callback Callback function > */ > - loadScript: function(src, callback) { > - var script > document.createElement(''script''); > - script.type = ''text/javascript''; > - script.src = src; > - if (callback) { > - var evl = {}; > - evl.handleEvent = function(e) { > - callback(); > - }; > - script.addEventListener(''load'' ,evl > ,true); > - } > - > document.getElementsByTagName(''head'')[0].appendChild(script); > - return; > - }, > - > + loadScript: loadScript, > + > /** > * > * @param {Object} point > @@ -334,6 +369,16 @@ > logN: function(number, base) { > return Math.log(number) / Math.log(base); > }, > + > + /** > + * returns array of loaded provider apis > + * @returns {Array} providers > + */ > + getAvailableProviders : function () { > + var providers = []; > + for (var propertyName in apis) > providers.push(propertyName); > + return providers; > + }, > > dummy: 0 > > @@ -341,4 +386,5 @@ > > dummy: 0 > }; > + > })(); > > Modified: trunk/source/mxn.yahoo.core.js > > =============================================================================> --- trunk/source/mxn.yahoo.core.js (original) > +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 > @@ -1,5 +1,4 @@ > -mxn.register('' > -oo'', { > +mxn.register(''yahoo'', { > > Mapstraction: { > > > Modified: trunk/tests/index.htm > > =============================================================================> --- trunk/tests/index.htm (original) > +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 > @@ -7,11 +7,7 @@ > <script type="text/javascript" src=" > http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> > > <script charset="UTF-8" type="text/javascript" src=" > http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2 > "></script> > <script src="domReady.js" type="text/javascript"></script> > - <script src="../source/mxn.js" type="text/javascript"></script> > - <script src="../source/mxn.core.js" > type="text/javascript"></script> > - <script src="../source/mxn.google.core.js" > type="text/javascript"></script> > - <script src="../source/mxn.yahoo.core.js" > type="text/javascript"></script> > - <script src="../source/mxn.microsoft.core.js" > type="text/javascript"></script> > + <script src="../source/mxn.js?(google, yahoo, microsoft)" > type="text/javascript"></script> > > <script type="text/javascript"> > //<![CDATA[ > @@ -40,7 +36,7 @@ > var infoElm = document.getElementById(''info''); > var eventsElm = document.getElementById(''events''); > > - var m = new mxn.Mapstraction(''map'', ''microsoft''); > + var m = new mxn.Mapstraction(''map''); > > m.endPan.addHandler(function(sEvtName, oEvtSource, > oEvtArgs){ > var center = oEvtSource.getCenter(); > @@ -136,7 +132,7 @@ > { > desc: ''Swap API'', > action: function(){ > - m.swap(''map'', ''google''); > + m.swap(''map'', ''microsoft''); > } > }, > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090531/1e564da3/attachment-0001.htm>
Andrew Turner
2009-May-31 22:36 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
Rob wrote:> FYI, these changes allow the following: > > Declaring a mapstraction object without a provider: > > *var m = new mxn.Mapstraction(''map'');* > > will make the system default to the first loaded provider. > > > > Have also implemented the preloading javascript functionality, so only > a single script reference is now required: > > <script src="../source/mxn.js?(google)" type="text/javascript"></script> > -or- > <script src="../source/mxn.js?(google, yahoo, microsoft)" > type="text/javascript"></script>Spiffy - this is a nice feature. How would this work if someone wanted to build a Minified version that compressed the JS they were using (mxn.js, core, g,y,m) into a single JS file for speed/# of downloads? Also, what about the additional option to include Provider specific JS either on this initial load - or on first time a provider is used? This way the first map would load quickly and additional providers only loaded on demand as an option. Andrew> > > Cheers, > Rob > > > 2009/5/31 <codesite-noreply at google.com > <mailto:codesite-noreply at google.com>> > > Author: robert.moran > Date: Sun May 31 11:13:23 2009 > New Revision: 11 > > Modified: > trunk/source/mxn.core.js > trunk/source/mxn.js > trunk/source/mxn.yahoo.core.js > trunk/tests/index.htm > > Log: > Added functionality to automatically load scripts needed. > Allowed mapstraction default constructor to have provider omitted > (will use first loaded provider). > Minor change to yahoo implementation - syntax/spelling error. > > > Modified: trunk/source/mxn.core.js > =============================================================================> --- trunk/source/mxn.core.js (original) > +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 > @@ -14,11 +14,12 @@ > /** > * Mapstraction instantiates a map with some API choice into the > HTML element given > * @param {String} element The HTML element to replace with a map > - * @param {String} api The API to use, one of ''google'', ''yahoo'', > ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', > ''mapquest'' > + * @param {String} api The API to use, one of ''google'', ''yahoo'', > ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', > ''mapquest''. If omitted, first loaded provider implementation is used. > * @param {Bool} debug optional parameter to turn on debug support > - this uses alert panels for unsupported actions > * @constructor > */ > var Mapstraction = mxn.Mapstraction = function(element, api, debug) { > + if (!api) api = mxn.util.getAvailableProviders()[0]; > this.api = api; > this.maps = {}; > this.currentElement = $m(element); > > Modified: trunk/source/mxn.js > =============================================================================> --- trunk/source/mxn.js (original) > +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 > @@ -3,8 +3,56 @@ > // holds all our implementing functions > var apis = {}; > > + // ''Constructor'' > + (function() { > + // Defaults > + var providers = ''google,yahoo,microsoft''; > + 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; > + } > + } > + providers = providers.replace(/ /g, '''').split('',''); > + modules = modules.replace(/ /g, '''').split('',''); > + for (var i = 0; i < modules.length; i++) { > + loadScript(scriptBase + ''mxn.'' + > modules[i] + ''.js''); > + for (var j = 0; j < providers.length; j++) > loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + > ''.js''); > + } > + })(); > + > // Our special private methods > /** > + * loadScript is a JSON data fetcher > + * @param {String} src URL to JSON file > + * @param {Function} callback Callback function > + */ > + function loadScript(src, callback) { > + var script = document.createElement(''script''); > + script.type = ''text/javascript''; > + script.src = src; > + if (callback) { > + var evl = {}; > + evl.handleEvent = function(e) { > + callback(); > + }; > + script.addEventListener(''load'' ,evl ,true); > + } > + > document.getElementsByTagName(''head'')[0].appendChild(script); > + return; > + }; > + > + /** > * Calls the API specific implementation of a particular > method. > */ > var invoke = function(sApiId, sObjName, sFnName, oScope, args){ > @@ -29,14 +77,14 @@ > }; > > return { > - > + > /** > * Registers a set of provider specific > implementation functions. > */ > register: function(sApiId, oApiImpl){ > if(!apis.hasOwnProperty(sApiId)) > apis[sApiId] = {}; > mxn.util.merge(apis[sApiId], oApiImpl); > - }, > + }, > > /** > * Adds a list of named proxy methods to the > prototype of a > @@ -202,21 +250,8 @@ > * @param {String} src URL to JSON file > * @param {Function} callback Callback function > */ > - loadScript: function(src, callback) { > - var script > document.createElement(''script''); > - script.type = ''text/javascript''; > - script.src = src; > - if (callback) { > - var evl = {}; > - evl.handleEvent > function(e) { > - callback(); > - }; > - > script.addEventListener(''load'' ,evl ,true); > - } > - > document.getElementsByTagName(''head'')[0].appendChild(script); > - return; > - }, > - > + loadScript: loadScript, > + > /** > * > * @param {Object} point > @@ -334,6 +369,16 @@ > logN: function(number, base) { > return Math.log(number) / > Math.log(base); > }, > + > + /** > + * returns array of loaded provider apis > + * @returns {Array} providers > + */ > + getAvailableProviders : function () { > + var providers = []; > + for (var propertyName in apis) > providers.push(propertyName); > + return providers; > + }, > > dummy: 0 > > @@ -341,4 +386,5 @@ > > dummy: 0 > }; > + > })(); > > Modified: trunk/source/mxn.yahoo.core.js > =============================================================================> --- trunk/source/mxn.yahoo.core.js (original) > +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 > @@ -1,5 +1,4 @@ > -mxn.register('' > -oo'', { > +mxn.register(''yahoo'', { > > Mapstraction: { > > > Modified: trunk/tests/index.htm > =============================================================================> --- trunk/tests/index.htm (original) > +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 > @@ -7,11 +7,7 @@ > <script type="text/javascript" > src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky > <http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky>"></script> > > <script charset="UTF-8" type="text/javascript" > src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> > <script src="domReady.js" type="text/javascript"></script> > - <script src="../source/mxn.js" type="text/javascript"></script> > - <script src="../source/mxn.core.js" type="text/javascript"></script> > - <script src="../source/mxn.google.core.js" > type="text/javascript"></script> > - <script src="../source/mxn.yahoo.core.js" > type="text/javascript"></script> > - <script src="../source/mxn.microsoft.core.js" > type="text/javascript"></script> > + <script src="../source/mxn.js?(google, yahoo, microsoft)" > type="text/javascript"></script> > > <script type="text/javascript"> > //<![CDATA[ > @@ -40,7 +36,7 @@ > var infoElm = document.getElementById(''info''); > var eventsElm = document.getElementById(''events''); > > - var m = new mxn.Mapstraction(''map'', ''microsoft''); > + var m = new mxn.Mapstraction(''map''); > > m.endPan.addHandler(function(sEvtName, oEvtSource, > oEvtArgs){ > var center = oEvtSource.getCenter(); > @@ -136,7 +132,7 @@ > { > desc: ''Swap API'', > action: function(){ > - m.swap(''map'', ''google''); > + m.swap(''map'', ''microsoft''); > } > }, > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > <mailto:Mapstraction at lists.mapstraction.com> > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >-- Andrew Turner m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner b: http://highearthorbit.com w: http://geocommons.com Introduction to Neogeography - http://oreilly.com/catalog/neogeography -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090531/ee8384f4/attachment-0001.htm>
Rob
2009-Jun-01 08:33 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
I haven''t considered a minified version sticking the files back together again :) It would just need this functionality removed. Provider-specific loading on demand is something I spent a lot of time looking into a few Months back and found it to be pretty much impossible without making user''s code quite complicated. It boiled down to script running ahead in user code before everything is properly loaded and return values being missed. See demo 02 I put up here: http://www.thegecko.org/mapstractionv2/ It would be great if anyone has any ideas as to how it can be fixed :) Rob 2009/5/31 Andrew Turner <ajturner at highearthorbit.com>> Rob wrote: > > FYI, these changes allow the following: > > Declaring a mapstraction object without a provider: > > *var m = new mxn.Mapstraction(''map'');* > > will make the system default to the first loaded provider. > > > > Have also implemented the preloading javascript functionality, so only a > single script reference is now required: > > <script src="../source/mxn.js?(google)" type="text/javascript"></script> > -or- > <script src="../source/mxn.js?(google, yahoo, microsoft)" > type="text/javascript"></script> > > Spiffy - this is a nice feature. How would this work if someone wanted to > build a Minified version that compressed the JS they were using (mxn.js, > core, g,y,m) into a single JS file for speed/# of downloads? > > Also, what about the additional option to include Provider specific JS > either on this initial load - or on first time a provider is used? This way > the first map would load quickly and additional providers only loaded on > demand as an option. > > Andrew > > > > Cheers, > Rob > > > 2009/5/31 <codesite-noreply at google.com> > >> Author: robert.moran >> Date: Sun May 31 11:13:23 2009 >> New Revision: 11 >> >> Modified: >> trunk/source/mxn.core.js >> trunk/source/mxn.js >> trunk/source/mxn.yahoo.core.js >> trunk/tests/index.htm >> >> Log: >> Added functionality to automatically load scripts needed. >> Allowed mapstraction default constructor to have provider omitted (will >> use first loaded provider). >> Minor change to yahoo implementation - syntax/spelling error. >> >> >> Modified: trunk/source/mxn.core.js >> >> =============================================================================>> --- trunk/source/mxn.core.js (original) >> +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 >> @@ -14,11 +14,12 @@ >> /** >> * Mapstraction instantiates a map with some API choice into the HTML >> element given >> * @param {String} element The HTML element to replace with a map >> - * @param {String} api The API to use, one of ''google'', ''yahoo'', >> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' >> + * @param {String} api The API to use, one of ''google'', ''yahoo'', >> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. >> If omitted, first loaded provider implementation is used. >> * @param {Bool} debug optional parameter to turn on debug support - this >> uses alert panels for unsupported actions >> * @constructor >> */ >> var Mapstraction = mxn.Mapstraction = function(element, api, debug) { >> + if (!api) api = mxn.util.getAvailableProviders()[0]; >> this.api = api; >> this.maps = {}; >> this.currentElement = $m(element); >> >> Modified: trunk/source/mxn.js >> >> =============================================================================>> --- trunk/source/mxn.js (original) >> +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 >> @@ -3,8 +3,56 @@ >> // holds all our implementing functions >> var apis = {}; >> >> + // ''Constructor'' >> + (function() { >> + // Defaults >> + var providers = ''google,yahoo,microsoft''; >> + 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; >> + } >> + } >> + providers = providers.replace(/ /g, '''').split('',''); >> + modules = modules.replace(/ /g, '''').split('',''); >> + for (var i = 0; i < modules.length; i++) { >> + loadScript(scriptBase + ''mxn.'' + modules[i] + >> ''.js''); >> + for (var j = 0; j < providers.length; j++) >> loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); >> + } >> + })(); >> + >> // Our special private methods >> /** >> + * loadScript is a JSON data fetcher >> + * @param {String} src URL to JSON file >> + * @param {Function} callback Callback function >> + */ >> + function loadScript(src, callback) { >> + var script = document.createElement(''script''); >> + script.type = ''text/javascript''; >> + script.src = src; >> + if (callback) { >> + var evl = {}; >> + evl.handleEvent = function(e) { >> + callback(); >> + }; >> + script.addEventListener(''load'' ,evl ,true); >> + } >> + >> document.getElementsByTagName(''head'')[0].appendChild(script); >> + return; >> + }; >> + >> + /** >> * Calls the API specific implementation of a particular method. >> */ >> var invoke = function(sApiId, sObjName, sFnName, oScope, args){ >> @@ -29,14 +77,14 @@ >> }; >> >> return { >> - >> + >> /** >> * Registers a set of provider specific implementation >> functions. >> */ >> register: function(sApiId, oApiImpl){ >> if(!apis.hasOwnProperty(sApiId)) apis[sApiId] = {}; >> mxn.util.merge(apis[sApiId], oApiImpl); >> - }, >> + }, >> >> /** >> * Adds a list of named proxy methods to the prototype of a >> @@ -202,21 +250,8 @@ >> * @param {String} src URL to JSON file >> * @param {Function} callback Callback function >> */ >> - loadScript: function(src, callback) { >> - var script >> document.createElement(''script''); >> - script.type = ''text/javascript''; >> - script.src = src; >> - if (callback) { >> - var evl = {}; >> - evl.handleEvent = function(e) { >> - callback(); >> - }; >> - script.addEventListener(''load'' >> ,evl ,true); >> - } >> - >> document.getElementsByTagName(''head'')[0].appendChild(script); >> - return; >> - }, >> - >> + loadScript: loadScript, >> + >> /** >> * >> * @param {Object} point >> @@ -334,6 +369,16 @@ >> logN: function(number, base) { >> return Math.log(number) / Math.log(base); >> }, >> + >> + /** >> + * returns array of loaded provider apis >> + * @returns {Array} providers >> + */ >> + getAvailableProviders : function () { >> + var providers = []; >> + for (var propertyName in apis) >> providers.push(propertyName); >> + return providers; >> + }, >> >> dummy: 0 >> >> @@ -341,4 +386,5 @@ >> >> dummy: 0 >> }; >> + >> })(); >> >> Modified: trunk/source/mxn.yahoo.core.js >> >> =============================================================================>> --- trunk/source/mxn.yahoo.core.js (original) >> +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 >> @@ -1,5 +1,4 @@ >> -mxn.register('' >> -oo'', { >> +mxn.register(''yahoo'', { >> >> Mapstraction: { >> >> >> Modified: trunk/tests/index.htm >> >> =============================================================================>> --- trunk/tests/index.htm (original) >> +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 >> @@ -7,11 +7,7 @@ >> <script type="text/javascript" src=" >> http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> >> >> <script charset="UTF-8" type="text/javascript" src=" >> http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2 >> "></script> >> <script src="domReady.js" type="text/javascript"></script> >> - <script src="../source/mxn.js" type="text/javascript"></script> >> - <script src="../source/mxn.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.google.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.yahoo.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.microsoft.core.js" >> type="text/javascript"></script> >> + <script src="../source/mxn.js?(google, yahoo, microsoft)" >> type="text/javascript"></script> >> >> <script type="text/javascript"> >> //<![CDATA[ >> @@ -40,7 +36,7 @@ >> var infoElm = document.getElementById(''info''); >> var eventsElm = document.getElementById(''events''); >> >> - var m = new mxn.Mapstraction(''map'', ''microsoft''); >> + var m = new mxn.Mapstraction(''map''); >> >> m.endPan.addHandler(function(sEvtName, oEvtSource, >> oEvtArgs){ >> var center = oEvtSource.getCenter(); >> @@ -136,7 +132,7 @@ >> { >> desc: ''Swap API'', >> action: function(){ >> - m.swap(''map'', ''google''); >> + m.swap(''map'', ''microsoft''); >> } >> }, >> >> _______________________________________________ >> Mapstraction mailing list >> Mapstraction at lists.mapstraction.com >> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > > > ------------------------------ > > _______________________________________________ > Mapstraction mailing listMapstraction at lists.mapstraction.comhttp://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > > > > -- > Andrew Turner > m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner > b: http://highearthorbit.com w: http://geocommons.com > Introduction to Neogeography - http://oreilly.com/catalog/neogeography > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090601/7cc7ea9b/attachment-0001.htm>
Derek Fowler
2009-Jun-01 11:49 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
I think we''d just need a nice way of halting the execution in the Mapstraction constructor while the provider loads. I''ve actually stripped all the "if provider isn''t loaded add this call to the on load instead" code out of v2. Initially because I was going to replace it with the new one-liner but it was working fine without it in so I didn''t bother putting it back. As you say Rob that method isn''t viable when you have functions that need to return something anyway so I think we need to come up with something new. I also noticed the auto-loading doesn''t work in Chrome, it stalls whilst injecting the script tags. I suspect it''s to do with the domReady script i''m using on that test page however but if it ends up that it doesn''t work with a standard domReady function like the jquery one we''ll have to have a look at that too. Derek On Mon, Jun 1, 2009 at 9:33 AM, Rob <mapstraction at thegecko.org> wrote:> I haven''t considered a minified version sticking the files back together > again :) > It would just need this functionality removed. > > Provider-specific loading on demand is something I spent a lot of time > looking into a few Months back and found it to be pretty much impossible > without making user''s code quite complicated. It boiled down to script > running ahead in user code before everything is properly loaded and return > values being missed. > > See demo 02 I put up here: > > http://www.thegecko.org/mapstractionv2/ > > It would be great if anyone has any ideas as to how it can be fixed :) > > Rob > > 2009/5/31 Andrew Turner <ajturner at highearthorbit.com> > > Rob wrote: >> >> FYI, these changes allow the following: >> >> Declaring a mapstraction object without a provider: >> >> *var m = new mxn.Mapstraction(''map'');* >> >> will make the system default to the first loaded provider. >> >> >> >> Have also implemented the preloading javascript functionality, so only a >> single script reference is now required: >> >> <script src="../source/mxn.js?(google)" type="text/javascript"></script> >> -or- >> <script src="../source/mxn.js?(google, yahoo, microsoft)" >> type="text/javascript"></script> >> >> Spiffy - this is a nice feature. How would this work if someone wanted to >> build a Minified version that compressed the JS they were using (mxn.js, >> core, g,y,m) into a single JS file for speed/# of downloads? >> >> Also, what about the additional option to include Provider specific JS >> either on this initial load - or on first time a provider is used? This way >> the first map would load quickly and additional providers only loaded on >> demand as an option. >> >> Andrew >> >> >> >> Cheers, >> Rob >> >> >> 2009/5/31 <codesite-noreply at google.com> >> >>> Author: robert.moran >>> Date: Sun May 31 11:13:23 2009 >>> New Revision: 11 >>> >>> Modified: >>> trunk/source/mxn.core.js >>> trunk/source/mxn.js >>> trunk/source/mxn.yahoo.core.js >>> trunk/tests/index.htm >>> >>> Log: >>> Added functionality to automatically load scripts needed. >>> Allowed mapstraction default constructor to have provider omitted (will >>> use first loaded provider). >>> Minor change to yahoo implementation - syntax/spelling error. >>> >>> >>> Modified: trunk/source/mxn.core.js >>> >>> =============================================================================>>> --- trunk/source/mxn.core.js (original) >>> +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 >>> @@ -14,11 +14,12 @@ >>> /** >>> * Mapstraction instantiates a map with some API choice into the HTML >>> element given >>> * @param {String} element The HTML element to replace with a map >>> - * @param {String} api The API to use, one of ''google'', ''yahoo'', >>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' >>> + * @param {String} api The API to use, one of ''google'', ''yahoo'', >>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. >>> If omitted, first loaded provider implementation is used. >>> * @param {Bool} debug optional parameter to turn on debug support - this >>> uses alert panels for unsupported actions >>> * @constructor >>> */ >>> var Mapstraction = mxn.Mapstraction = function(element, api, debug) { >>> + if (!api) api = mxn.util.getAvailableProviders()[0]; >>> this.api = api; >>> this.maps = {}; >>> this.currentElement = $m(element); >>> >>> Modified: trunk/source/mxn.js >>> >>> =============================================================================>>> --- trunk/source/mxn.js (original) >>> +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 >>> @@ -3,8 +3,56 @@ >>> // holds all our implementing functions >>> var apis = {}; >>> >>> + // ''Constructor'' >>> + (function() { >>> + // Defaults >>> + var providers = ''google,yahoo,microsoft''; >>> + 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; >>> + } >>> + } >>> + providers = providers.replace(/ /g, '''').split('',''); >>> + modules = modules.replace(/ /g, '''').split('',''); >>> + for (var i = 0; i < modules.length; i++) { >>> + loadScript(scriptBase + ''mxn.'' + modules[i] + >>> ''.js''); >>> + for (var j = 0; j < providers.length; j++) >>> loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); >>> + } >>> + })(); >>> + >>> // Our special private methods >>> /** >>> + * loadScript is a JSON data fetcher >>> + * @param {String} src URL to JSON file >>> + * @param {Function} callback Callback function >>> + */ >>> + function loadScript(src, callback) { >>> + var script = document.createElement(''script''); >>> + script.type = ''text/javascript''; >>> + script.src = src; >>> + if (callback) { >>> + var evl = {}; >>> + evl.handleEvent = function(e) { >>> + callback(); >>> + }; >>> + script.addEventListener(''load'' ,evl ,true); >>> + } >>> + >>> document.getElementsByTagName(''head'')[0].appendChild(script); >>> + return; >>> + }; >>> + >>> + /** >>> * Calls the API specific implementation of a particular method. >>> */ >>> var invoke = function(sApiId, sObjName, sFnName, oScope, args){ >>> @@ -29,14 +77,14 @@ >>> }; >>> >>> return { >>> - >>> + >>> /** >>> * Registers a set of provider specific implementation >>> functions. >>> */ >>> register: function(sApiId, oApiImpl){ >>> if(!apis.hasOwnProperty(sApiId)) apis[sApiId] >>> {}; >>> mxn.util.merge(apis[sApiId], oApiImpl); >>> - }, >>> + }, >>> >>> /** >>> * Adds a list of named proxy methods to the prototype of >>> a >>> @@ -202,21 +250,8 @@ >>> * @param {String} src URL to JSON file >>> * @param {Function} callback Callback function >>> */ >>> - loadScript: function(src, callback) { >>> - var script >>> document.createElement(''script''); >>> - script.type = ''text/javascript''; >>> - script.src = src; >>> - if (callback) { >>> - var evl = {}; >>> - evl.handleEvent = function(e) { >>> - callback(); >>> - }; >>> - script.addEventListener(''load'' >>> ,evl ,true); >>> - } >>> - >>> document.getElementsByTagName(''head'')[0].appendChild(script); >>> - return; >>> - }, >>> - >>> + loadScript: loadScript, >>> + >>> /** >>> * >>> * @param {Object} point >>> @@ -334,6 +369,16 @@ >>> logN: function(number, base) { >>> return Math.log(number) / Math.log(base); >>> }, >>> + >>> + /** >>> + * returns array of loaded provider apis >>> + * @returns {Array} providers >>> + */ >>> + getAvailableProviders : function () { >>> + var providers = []; >>> + for (var propertyName in apis) >>> providers.push(propertyName); >>> + return providers; >>> + }, >>> >>> dummy: 0 >>> >>> @@ -341,4 +386,5 @@ >>> >>> dummy: 0 >>> }; >>> + >>> })(); >>> >>> Modified: trunk/source/mxn.yahoo.core.js >>> >>> =============================================================================>>> --- trunk/source/mxn.yahoo.core.js (original) >>> +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 >>> @@ -1,5 +1,4 @@ >>> -mxn.register('' >>> -oo'', { >>> +mxn.register(''yahoo'', { >>> >>> Mapstraction: { >>> >>> >>> Modified: trunk/tests/index.htm >>> >>> =============================================================================>>> --- trunk/tests/index.htm (original) >>> +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 >>> @@ -7,11 +7,7 @@ >>> <script type="text/javascript" src=" >>> http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> >>> >>> <script charset="UTF-8" type="text/javascript" src=" >>> http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2 >>> "></script> >>> <script src="domReady.js" type="text/javascript"></script> >>> - <script src="../source/mxn.js" type="text/javascript"></script> >>> - <script src="../source/mxn.core.js" >>> type="text/javascript"></script> >>> - <script src="../source/mxn.google.core.js" >>> type="text/javascript"></script> >>> - <script src="../source/mxn.yahoo.core.js" >>> type="text/javascript"></script> >>> - <script src="../source/mxn.microsoft.core.js" >>> type="text/javascript"></script> >>> + <script src="../source/mxn.js?(google, yahoo, microsoft)" >>> type="text/javascript"></script> >>> >>> <script type="text/javascript"> >>> //<![CDATA[ >>> @@ -40,7 +36,7 @@ >>> var infoElm = document.getElementById(''info''); >>> var eventsElm = document.getElementById(''events''); >>> >>> - var m = new mxn.Mapstraction(''map'', ''microsoft''); >>> + var m = new mxn.Mapstraction(''map''); >>> >>> m.endPan.addHandler(function(sEvtName, oEvtSource, >>> oEvtArgs){ >>> var center = oEvtSource.getCenter(); >>> @@ -136,7 +132,7 @@ >>> { >>> desc: ''Swap API'', >>> action: function(){ >>> - m.swap(''map'', ''google''); >>> + m.swap(''map'', ''microsoft''); >>> } >>> }, >>> >>> _______________________________________________ >>> Mapstraction mailing list >>> Mapstraction at lists.mapstraction.com >>> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> >> >> ------------------------------ >> >> _______________________________________________ >> Mapstraction mailing listMapstraction at lists.mapstraction.comhttp://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> >> >> >> -- >> Andrew Turner >> m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner >> b: http://highearthorbit.com w: http://geocommons.com >> Introduction to Neogeography - http://oreilly.com/catalog/neogeography >> >> > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > >-- Derek Fowler m. +44 (0) 7966 512 369 e. dezfowler at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090601/796dfbde/attachment-0001.htm>
Rob
2009-Jun-01 14:43 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
Any ideas on how auto-loading could work without impacting user code? I''m all out of ideas :) Perhaps its a low priority for now. Auto-loading not working is strange. I have the current release test page working fine locally in Firefox, IE6, IE7 and Chrome. Rob 2009/6/1 Derek Fowler <dezfowler at gmail.com>> I think we''d just need a nice way of halting the execution in the > Mapstraction constructor while the provider loads. I''ve actually stripped > all the "if provider isn''t loaded add this call to the on load instead" code > out of v2. Initially because I was going to replace it with the new > one-liner but it was working fine without it in so I didn''t bother putting > it back. As you say Rob that method isn''t viable when you have functions > that need to return something anyway so I think we need to come up with > something new. > > I also noticed the auto-loading doesn''t work in Chrome, it stalls whilst > injecting the script tags. I suspect it''s to do with the domReady script i''m > using on that test page however but if it ends up that it doesn''t work with > a standard domReady function like the jquery one we''ll have to have a look > at that too. > > Derek > > > On Mon, Jun 1, 2009 at 9:33 AM, Rob <mapstraction at thegecko.org> wrote: > >> I haven''t considered a minified version sticking the files back together >> again :) >> It would just need this functionality removed. >> >> Provider-specific loading on demand is something I spent a lot of time >> looking into a few Months back and found it to be pretty much impossible >> without making user''s code quite complicated. It boiled down to script >> running ahead in user code before everything is properly loaded and return >> values being missed. >> >> See demo 02 I put up here: >> >> http://www.thegecko.org/mapstractionv2/ >> >> It would be great if anyone has any ideas as to how it can be fixed :) >> >> Rob >> >> 2009/5/31 Andrew Turner <ajturner at highearthorbit.com> >> >> Rob wrote: >>> >>> FYI, these changes allow the following: >>> >>> Declaring a mapstraction object without a provider: >>> >>> *var m = new mxn.Mapstraction(''map'');* >>> >>> will make the system default to the first loaded provider. >>> >>> >>> >>> Have also implemented the preloading javascript functionality, so only a >>> single script reference is now required: >>> >>> <script src="../source/mxn.js?(google)" type="text/javascript"></script> >>> -or- >>> <script src="../source/mxn.js?(google, yahoo, microsoft)" >>> type="text/javascript"></script> >>> >>> Spiffy - this is a nice feature. How would this work if someone wanted to >>> build a Minified version that compressed the JS they were using (mxn.js, >>> core, g,y,m) into a single JS file for speed/# of downloads? >>> >>> Also, what about the additional option to include Provider specific JS >>> either on this initial load - or on first time a provider is used? This way >>> the first map would load quickly and additional providers only loaded on >>> demand as an option. >>> >>> Andrew >>> >>> >>> >>> Cheers, >>> Rob >>> >>> >>> 2009/5/31 <codesite-noreply at google.com> >>> >>>> Author: robert.moran >>>> Date: Sun May 31 11:13:23 2009 >>>> New Revision: 11 >>>> >>>> Modified: >>>> trunk/source/mxn.core.js >>>> trunk/source/mxn.js >>>> trunk/source/mxn.yahoo.core.js >>>> trunk/tests/index.htm >>>> >>>> Log: >>>> Added functionality to automatically load scripts needed. >>>> Allowed mapstraction default constructor to have provider omitted (will >>>> use first loaded provider). >>>> Minor change to yahoo implementation - syntax/spelling error. >>>> >>>> >>>> Modified: trunk/source/mxn.core.js >>>> >>>> =============================================================================>>>> --- trunk/source/mxn.core.js (original) >>>> +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 >>>> @@ -14,11 +14,12 @@ >>>> /** >>>> * Mapstraction instantiates a map with some API choice into the HTML >>>> element given >>>> * @param {String} element The HTML element to replace with a map >>>> - * @param {String} api The API to use, one of ''google'', ''yahoo'', >>>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' >>>> + * @param {String} api The API to use, one of ''google'', ''yahoo'', >>>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. >>>> If omitted, first loaded provider implementation is used. >>>> * @param {Bool} debug optional parameter to turn on debug support - >>>> this uses alert panels for unsupported actions >>>> * @constructor >>>> */ >>>> var Mapstraction = mxn.Mapstraction = function(element, api, debug) { >>>> + if (!api) api = mxn.util.getAvailableProviders()[0]; >>>> this.api = api; >>>> this.maps = {}; >>>> this.currentElement = $m(element); >>>> >>>> Modified: trunk/source/mxn.js >>>> >>>> =============================================================================>>>> --- trunk/source/mxn.js (original) >>>> +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 >>>> @@ -3,8 +3,56 @@ >>>> // holds all our implementing functions >>>> var apis = {}; >>>> >>>> + // ''Constructor'' >>>> + (function() { >>>> + // Defaults >>>> + var providers = ''google,yahoo,microsoft''; >>>> + 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; >>>> + } >>>> + } >>>> + providers = providers.replace(/ /g, '''').split('',''); >>>> + modules = modules.replace(/ /g, '''').split('',''); >>>> + for (var i = 0; i < modules.length; i++) { >>>> + loadScript(scriptBase + ''mxn.'' + modules[i] + >>>> ''.js''); >>>> + for (var j = 0; j < providers.length; j++) >>>> loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); >>>> + } >>>> + })(); >>>> + >>>> // Our special private methods >>>> /** >>>> + * loadScript is a JSON data fetcher >>>> + * @param {String} src URL to JSON file >>>> + * @param {Function} callback Callback function >>>> + */ >>>> + function loadScript(src, callback) { >>>> + var script = document.createElement(''script''); >>>> + script.type = ''text/javascript''; >>>> + script.src = src; >>>> + if (callback) { >>>> + var evl = {}; >>>> + evl.handleEvent = function(e) { >>>> + callback(); >>>> + }; >>>> + script.addEventListener(''load'' ,evl ,true); >>>> + } >>>> + >>>> document.getElementsByTagName(''head'')[0].appendChild(script); >>>> + return; >>>> + }; >>>> + >>>> + /** >>>> * Calls the API specific implementation of a particular method. >>>> */ >>>> var invoke = function(sApiId, sObjName, sFnName, oScope, args){ >>>> @@ -29,14 +77,14 @@ >>>> }; >>>> >>>> return { >>>> - >>>> + >>>> /** >>>> * Registers a set of provider specific implementation >>>> functions. >>>> */ >>>> register: function(sApiId, oApiImpl){ >>>> if(!apis.hasOwnProperty(sApiId)) apis[sApiId] >>>> {}; >>>> mxn.util.merge(apis[sApiId], oApiImpl); >>>> - }, >>>> + }, >>>> >>>> /** >>>> * Adds a list of named proxy methods to the prototype of >>>> a >>>> @@ -202,21 +250,8 @@ >>>> * @param {String} src URL to JSON file >>>> * @param {Function} callback Callback function >>>> */ >>>> - loadScript: function(src, callback) { >>>> - var script >>>> document.createElement(''script''); >>>> - script.type = ''text/javascript''; >>>> - script.src = src; >>>> - if (callback) { >>>> - var evl = {}; >>>> - evl.handleEvent = function(e) { >>>> - callback(); >>>> - }; >>>> - script.addEventListener(''load'' >>>> ,evl ,true); >>>> - } >>>> - >>>> document.getElementsByTagName(''head'')[0].appendChild(script); >>>> - return; >>>> - }, >>>> - >>>> + loadScript: loadScript, >>>> + >>>> /** >>>> * >>>> * @param {Object} point >>>> @@ -334,6 +369,16 @@ >>>> logN: function(number, base) { >>>> return Math.log(number) / Math.log(base); >>>> }, >>>> + >>>> + /** >>>> + * returns array of loaded provider apis >>>> + * @returns {Array} providers >>>> + */ >>>> + getAvailableProviders : function () { >>>> + var providers = []; >>>> + for (var propertyName in apis) >>>> providers.push(propertyName); >>>> + return providers; >>>> + }, >>>> >>>> dummy: 0 >>>> >>>> @@ -341,4 +386,5 @@ >>>> >>>> dummy: 0 >>>> }; >>>> + >>>> })(); >>>> >>>> Modified: trunk/source/mxn.yahoo.core.js >>>> >>>> =============================================================================>>>> --- trunk/source/mxn.yahoo.core.js (original) >>>> +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 >>>> @@ -1,5 +1,4 @@ >>>> -mxn.register('' >>>> -oo'', { >>>> +mxn.register(''yahoo'', { >>>> >>>> Mapstraction: { >>>> >>>> >>>> Modified: trunk/tests/index.htm >>>> >>>> =============================================================================>>>> --- trunk/tests/index.htm (original) >>>> +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 >>>> @@ -7,11 +7,7 @@ >>>> <script type="text/javascript" src=" >>>> http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> >>>> >>>> <script charset="UTF-8" type="text/javascript" src=" >>>> http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2 >>>> "></script> >>>> <script src="domReady.js" type="text/javascript"></script> >>>> - <script src="../source/mxn.js" type="text/javascript"></script> >>>> - <script src="../source/mxn.core.js" >>>> type="text/javascript"></script> >>>> - <script src="../source/mxn.google.core.js" >>>> type="text/javascript"></script> >>>> - <script src="../source/mxn.yahoo.core.js" >>>> type="text/javascript"></script> >>>> - <script src="../source/mxn.microsoft.core.js" >>>> type="text/javascript"></script> >>>> + <script src="../source/mxn.js?(google, yahoo, microsoft)" >>>> type="text/javascript"></script> >>>> >>>> <script type="text/javascript"> >>>> //<![CDATA[ >>>> @@ -40,7 +36,7 @@ >>>> var infoElm = document.getElementById(''info''); >>>> var eventsElm = document.getElementById(''events''); >>>> >>>> - var m = new mxn.Mapstraction(''map'', ''microsoft''); >>>> + var m = new mxn.Mapstraction(''map''); >>>> >>>> m.endPan.addHandler(function(sEvtName, oEvtSource, >>>> oEvtArgs){ >>>> var center = oEvtSource.getCenter(); >>>> @@ -136,7 +132,7 @@ >>>> { >>>> desc: ''Swap API'', >>>> action: function(){ >>>> - m.swap(''map'', ''google''); >>>> + m.swap(''map'', ''microsoft''); >>>> } >>>> }, >>>> >>>> _______________________________________________ >>>> Mapstraction mailing list >>>> Mapstraction at lists.mapstraction.com >>>> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >>> >>> >>> ------------------------------ >>> >>> _______________________________________________ >>> Mapstraction mailing listMapstraction at lists.mapstraction.comhttp://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >>> >>> >>> >>> -- >>> Andrew Turner >>> m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner >>> b: http://highearthorbit.com w: http://geocommons.com >>> Introduction to Neogeography - http://oreilly.com/catalog/neogeography >>> >>> >> >> _______________________________________________ >> Mapstraction mailing list >> Mapstraction at lists.mapstraction.com >> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> >> > > > -- > Derek Fowler > m. +44 (0) 7966 512 369 > e. dezfowler at gmail.com >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090601/98498ffe/attachment-0001.htm>
Andrew Turner
2009-Jun-01 14:51 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
Rob wrote:> Any ideas on how auto-loading could work without impacting user code? > I''m all out of ideas :) > Perhaps its a low priority for now. >We are (meaning Matt Constantine, cc''d) adding "if provider isn''t loaded.." back into v2 for GeoCommons support (flash can take a bit). Thinking about on-demand script includes, isn''t it as simple as maintaining a list of already loaded providers - when a new map is created/switched, check if it''s been included. If it hasn''t then do writeInclude tags, and queue up any subsequent calls to this map. The biggest issue I see would be race conditions if a map was quickly switched back and forth before it was finished loading and the queued methods are applied based on the wrong provider type. Perhaps you''re right that this on-demand is too complicated at the moment and something that can be added later without breaking current functionality. Andrew> Auto-loading not working is strange. I have the current release test > page working fine locally in Firefox, IE6, IE7 and Chrome. > > Rob > > 2009/6/1 Derek Fowler <dezfowler at gmail.com <mailto:dezfowler at gmail.com>> > > I think we''d just need a nice way of halting the execution in the > Mapstraction constructor while the provider loads. I''ve actually > stripped all the "if provider isn''t loaded add this call to the on > load instead" code out of v2. Initially because I was going to > replace it with the new one-liner but it was working fine without > it in so I didn''t bother putting it back. As you say Rob that > method isn''t viable when you have functions that need to return > something anyway so I think we need to come up with something new. > > I also noticed the auto-loading doesn''t work in Chrome, it stalls > whilst injecting the script tags. I suspect it''s to do with the > domReady script i''m using on that test page however but if it ends > up that it doesn''t work with a standard domReady function like the > jquery one we''ll have to have a look at that too. > > Derek > > > On Mon, Jun 1, 2009 at 9:33 AM, Rob <mapstraction at thegecko.org > <mailto:mapstraction at thegecko.org>> wrote: > > I haven''t considered a minified version sticking the files > back together again :) > It would just need this functionality removed. > > Provider-specific loading on demand is something I spent a lot > of time looking into a few Months back and found it to be > pretty much impossible without making user''s code quite > complicated. It boiled down to script running ahead in user > code before everything is properly loaded and return values > being missed. > > See demo 02 I put up here: > > http://www.thegecko.org/mapstractionv2/ > > It would be great if anyone has any ideas as to how it can be > fixed :) > > Rob > > 2009/5/31 Andrew Turner <ajturner at highearthorbit.com > <mailto:ajturner at highearthorbit.com>> > > Rob wrote: >> FYI, these changes allow the following: >> >> Declaring a mapstraction object without a provider: >> >> *var m = new mxn.Mapstraction(''map'');* >> >> will make the system default to the first loaded provider. >> >> >> >> Have also implemented the preloading javascript >> functionality, so only a single script reference is now >> required: >> >> <script src="../source/mxn.js?(google)" >> type="text/javascript"></script> >> -or- >> <script src="../source/mxn.js?(google, yahoo, microsoft)" >> type="text/javascript"></script> > Spiffy - this is a nice feature. How would this work if > someone wanted to build a Minified version that compressed > the JS they were using (mxn.js, core, g,y,m) into a single > JS file for speed/# of downloads? > > Also, what about the additional option to include Provider > specific JS either on this initial load - or on first time > a provider is used? This way the first map would load > quickly and additional providers only loaded on demand as > an option. > > Andrew >> >> >> Cheers, >> Rob >> >> >> 2009/5/31 <codesite-noreply at google.com >> <mailto:codesite-noreply at google.com>> >> >> Author: robert.moran >> Date: Sun May 31 11:13:23 2009 >> New Revision: 11 >> >> Modified: >> trunk/source/mxn.core.js >> trunk/source/mxn.js >> trunk/source/mxn.yahoo.core.js >> trunk/tests/index.htm >> >> Log: >> Added functionality to automatically load scripts needed. >> Allowed mapstraction default constructor to have >> provider omitted (will use first loaded provider). >> Minor change to yahoo implementation - >> syntax/spelling error. >> >> >> Modified: trunk/source/mxn.core.js >> =============================================================================>> --- trunk/source/mxn.core.js (original) >> +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 >> @@ -14,11 +14,12 @@ >> /** >> * Mapstraction instantiates a map with some API >> choice into the HTML element given >> * @param {String} element The HTML element to >> replace with a map >> - * @param {String} api The API to use, one of >> ''google'', ''yahoo'', ''microsoft'', ''openstreetmap'', >> ''multimap'', ''map24'', ''openlayers'', ''mapquest'' >> + * @param {String} api The API to use, one of >> ''google'', ''yahoo'', ''microsoft'', ''openstreetmap'', >> ''multimap'', ''map24'', ''openlayers'', ''mapquest''. If >> omitted, first loaded provider implementation is used. >> * @param {Bool} debug optional parameter to turn on >> debug support - this uses alert panels for >> unsupported actions >> * @constructor >> */ >> var Mapstraction = mxn.Mapstraction >> function(element, api, debug) { >> + if (!api) api = mxn.util.getAvailableProviders()[0]; >> this.api = api; >> this.maps = {}; >> this.currentElement = $m(element); >> >> Modified: trunk/source/mxn.js >> =============================================================================>> --- trunk/source/mxn.js (original) >> +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 >> @@ -3,8 +3,56 @@ >> // holds all our implementing functions >> var apis = {}; >> >> + // ''Constructor'' >> + (function() { >> + // Defaults >> + var providers >> ''google,yahoo,microsoft''; >> + 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; >> + } >> + } >> + providers = providers.replace(/ /g, >> '''').split('',''); >> + modules = modules.replace(/ /g, >> '''').split('',''); >> + for (var i = 0; i < modules.length; >> i++) { >> + loadScript(scriptBase + >> ''mxn.'' + modules[i] + ''.js''); >> + for (var j = 0; j < >> providers.length; j++) loadScript(scriptBase + ''mxn.'' >> + providers[j] + ''.'' + modules[i] + ''.js''); >> + } >> + })(); >> + >> // Our special private methods >> /** >> + * loadScript is a JSON data fetcher >> + * @param {String} src URL to JSON file >> + * @param {Function} callback Callback function >> + */ >> + function loadScript(src, callback) { >> + var script >> document.createElement(''script''); >> + script.type = ''text/javascript''; >> + script.src = src; >> + if (callback) { >> + var evl = {}; >> + evl.handleEvent = function(e) { >> + callback(); >> + }; >> + >> script.addEventListener(''load'' ,evl ,true); >> + } >> + >> document.getElementsByTagName(''head'')[0].appendChild(script); >> + return; >> + }; >> + >> + /** >> * Calls the API specific implementation of a >> particular method. >> */ >> var invoke = function(sApiId, sObjName, >> sFnName, oScope, args){ >> @@ -29,14 +77,14 @@ >> }; >> >> return { >> - >> + >> /** >> * Registers a set of provider >> specific implementation functions. >> */ >> register: function(sApiId, oApiImpl){ >> >> if(!apis.hasOwnProperty(sApiId)) apis[sApiId] = {}; >> mxn.util.merge(apis[sApiId], >> oApiImpl); >> - }, >> + }, >> >> /** >> * Adds a list of named proxy methods >> to the prototype of a >> @@ -202,21 +250,8 @@ >> * @param {String} src URL to >> JSON file >> * @param {Function} callback >> Callback function >> */ >> - loadScript: function(src, >> callback) { >> - var script >> document.createElement(''script''); >> - script.type >> ''text/javascript''; >> - script.src = src; >> - if (callback) { >> - var evl = {}; >> - >> evl.handleEvent = function(e) { >> - >> callback(); >> - }; >> - >> script.addEventListener(''load'' ,evl ,true); >> - } >> - >> document.getElementsByTagName(''head'')[0].appendChild(script); >> - return; >> - }, >> - >> + loadScript: loadScript, >> + >> /** >> * >> * @param {Object} point >> @@ -334,6 +369,16 @@ >> logN: function(number, base) { >> return >> Math.log(number) / Math.log(base); >> }, >> + >> + /** >> + * returns array of loaded >> provider apis >> + * @returns {Array} providers >> + */ >> + getAvailableProviders : >> function () { >> + var providers = []; >> + for (var propertyName >> in apis) providers.push(propertyName); >> + return providers; >> + }, >> >> dummy: 0 >> >> @@ -341,4 +386,5 @@ >> >> dummy: 0 >> }; >> + >> })(); >> >> Modified: trunk/source/mxn.yahoo.core.js >> =============================================================================>> --- trunk/source/mxn.yahoo.core.js (original) >> +++ trunk/source/mxn.yahoo.core.js Sun May 31 >> 11:13:23 2009 >> @@ -1,5 +1,4 @@ >> -mxn.register('' >> -oo'', { >> +mxn.register(''yahoo'', { >> >> Mapstraction: { >> >> >> Modified: trunk/tests/index.htm >> =============================================================================>> --- trunk/tests/index.htm (original) >> +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 >> @@ -7,11 +7,7 @@ >> <script type="text/javascript" >> src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky >> <http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky>"></script> >> >> <script charset="UTF-8" type="text/javascript" >> src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> >> <script src="domReady.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.google.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.yahoo.core.js" >> type="text/javascript"></script> >> - <script src="../source/mxn.microsoft.core.js" >> type="text/javascript"></script> >> + <script src="../source/mxn.js?(google, yahoo, >> microsoft)" type="text/javascript"></script> >> >> <script type="text/javascript"> >> //<![CDATA[ >> @@ -40,7 +36,7 @@ >> var infoElm >> document.getElementById(''info''); >> var eventsElm >> document.getElementById(''events''); >> >> - var m = new mxn.Mapstraction(''map'', >> ''microsoft''); >> + var m = new mxn.Mapstraction(''map''); >> >> m.endPan.addHandler(function(sEvtName, >> oEvtSource, oEvtArgs){ >> var center >> oEvtSource.getCenter(); >> @@ -136,7 +132,7 @@ >> { >> desc: ''Swap API'', >> action: function(){ >> - m.swap(''map'', >> ''google''); >> + m.swap(''map'', >> ''microsoft''); >> } >> }, >> >> _______________________________________________ >> Mapstraction mailing list >> Mapstraction at lists.mapstraction.com >> <mailto:Mapstraction at lists.mapstraction.com> >> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> >> >> ------------------------------------------------------------------------ >> _______________________________________________ >> Mapstraction mailing list >> Mapstraction at lists.mapstraction.com >> <mailto:Mapstraction at lists.mapstraction.com> >> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> > > > -- > Andrew Turner > m: 248.982.3609 e: andrew at highearthorbit.com > <mailto:andrew at highearthorbit.com> t: @ajturner > b: http://highearthorbit.com w: http://geocommons.com > Introduction to Neogeography - > http://oreilly.com/catalog/neogeography > > > > _______________________________________________ > Mapstraction mailing list > Mapstraction at lists.mapstraction.com > <mailto:Mapstraction at lists.mapstraction.com> > http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com > > > > > -- > Derek Fowler > m. +44 (0) 7966 512 369 > e. dezfowler at gmail.com <mailto:dezfowler at gmail.com> >-- Andrew Turner m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner b: http://highearthorbit.com w: http://geocommons.com Introduction to Neogeography - http://oreilly.com/catalog/neogeography -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090601/2578d4d1/attachment-0001.htm>
Derek Fowler
2009-Jun-01 19:01 UTC
[Mapstraction] [mapstraction commit] r11 - Added functionality to automatically load scripts needed.
Auto-loading is still broken for me in Chrome 2.0.172.30 (Windows). If you haven''t SVN Updated in a while then maybe it''s something I''ve broken, I''ll have a look. Regarding the "if provider isn''t loaded..." it''d be nice to come up with a better solution because the old method only works provided the user doesn''t call any functions that have a return value. If they do they''ll end up with code that inexplicably doesn''t work. I''ll see what I can come up with. Derek On Mon, Jun 1, 2009 at 3:51 PM, Andrew Turner <ajturner at highearthorbit.com>wrote:> Rob wrote: > > Any ideas on how auto-loading could work without impacting user code? I''m > all out of ideas :) > Perhaps its a low priority for now. > > We are (meaning Matt Constantine, cc''d) adding "if provider isn''t > loaded.." back into v2 for GeoCommons support (flash can take a bit). > > Thinking about on-demand script includes, isn''t it as simple as maintaining > a list of already loaded providers - when a new map is created/switched, > check if it''s been included. If it hasn''t then do writeInclude tags, and > queue up any subsequent calls to this map. > > The biggest issue I see would be race conditions if a map was quickly > switched back and forth before it was finished loading and the queued > methods are applied based on the wrong provider type. > > Perhaps you''re right that this on-demand is too complicated at the moment > and something that can be added later without breaking current > functionality. > > Andrew > > Auto-loading not working is strange. I have the current release test page > working fine locally in Firefox, IE6, IE7 and Chrome. > > Rob > > 2009/6/1 Derek Fowler <dezfowler at gmail.com> > >> I think we''d just need a nice way of halting the execution in the >> Mapstraction constructor while the provider loads. I''ve actually stripped >> all the "if provider isn''t loaded add this call to the on load instead" code >> out of v2. Initially because I was going to replace it with the new >> one-liner but it was working fine without it in so I didn''t bother putting >> it back. As you say Rob that method isn''t viable when you have functions >> that need to return something anyway so I think we need to come up with >> something new. >> >> I also noticed the auto-loading doesn''t work in Chrome, it stalls whilst >> injecting the script tags. I suspect it''s to do with the domReady script i''m >> using on that test page however but if it ends up that it doesn''t work with >> a standard domReady function like the jquery one we''ll have to have a look >> at that too. >> >> Derek >> >> On Mon, Jun 1, 2009 at 9:33 AM, Rob <mapstraction at thegecko.org> wrote: >> >>> I haven''t considered a minified version sticking the files back together >>> again :) >>> It would just need this functionality removed. >>> >>> Provider-specific loading on demand is something I spent a lot of time >>> looking into a few Months back and found it to be pretty much impossible >>> without making user''s code quite complicated. It boiled down to script >>> running ahead in user code before everything is properly loaded and return >>> values being missed. >>> >>> See demo 02 I put up here: >>> >>> http://www.thegecko.org/mapstractionv2/ >>> >>> It would be great if anyone has any ideas as to how it can be fixed :) >>> >>> Rob >>> >>> 2009/5/31 Andrew Turner <ajturner at highearthorbit.com> >>> >>>> Rob wrote: >>>> >>>> FYI, these changes allow the following: >>>> >>>> Declaring a mapstraction object without a provider: >>>> >>>> *var m = new mxn.Mapstraction(''map'');* >>>> >>>> will make the system default to the first loaded provider. >>>> >>>> >>>> >>>> Have also implemented the preloading javascript functionality, so only a >>>> single script reference is now required: >>>> >>>> <script src="../source/mxn.js?(google)" type="text/javascript"></script> >>>> -or- >>>> <script src="../source/mxn.js?(google, yahoo, microsoft)" >>>> type="text/javascript"></script> >>>> >>>> Spiffy - this is a nice feature. How would this work if someone wanted >>>> to build a Minified version that compressed the JS they were using (mxn.js, >>>> core, g,y,m) into a single JS file for speed/# of downloads? >>>> >>>> Also, what about the additional option to include Provider specific JS >>>> either on this initial load - or on first time a provider is used? This way >>>> the first map would load quickly and additional providers only loaded on >>>> demand as an option. >>>> >>>> Andrew >>>> >>>> >>>> >>>> Cheers, >>>> Rob >>>> >>>> >>>> 2009/5/31 <codesite-noreply at google.com> >>>> >>>>> Author: robert.moran >>>>> Date: Sun May 31 11:13:23 2009 >>>>> New Revision: 11 >>>>> >>>>> Modified: >>>>> trunk/source/mxn.core.js >>>>> trunk/source/mxn.js >>>>> trunk/source/mxn.yahoo.core.js >>>>> trunk/tests/index.htm >>>>> >>>>> Log: >>>>> Added functionality to automatically load scripts needed. >>>>> Allowed mapstraction default constructor to have provider omitted (will >>>>> use first loaded provider). >>>>> Minor change to yahoo implementation - syntax/spelling error. >>>>> >>>>> >>>>> Modified: trunk/source/mxn.core.js >>>>> >>>>> =============================================================================>>>>> --- trunk/source/mxn.core.js (original) >>>>> +++ trunk/source/mxn.core.js Sun May 31 11:13:23 2009 >>>>> @@ -14,11 +14,12 @@ >>>>> /** >>>>> * Mapstraction instantiates a map with some API choice into the HTML >>>>> element given >>>>> * @param {String} element The HTML element to replace with a map >>>>> - * @param {String} api The API to use, one of ''google'', ''yahoo'', >>>>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest'' >>>>> + * @param {String} api The API to use, one of ''google'', ''yahoo'', >>>>> ''microsoft'', ''openstreetmap'', ''multimap'', ''map24'', ''openlayers'', ''mapquest''. >>>>> If omitted, first loaded provider implementation is used. >>>>> * @param {Bool} debug optional parameter to turn on debug support - >>>>> this uses alert panels for unsupported actions >>>>> * @constructor >>>>> */ >>>>> var Mapstraction = mxn.Mapstraction = function(element, api, debug) { >>>>> + if (!api) api = mxn.util.getAvailableProviders()[0]; >>>>> this.api = api; >>>>> this.maps = {}; >>>>> this.currentElement = $m(element); >>>>> >>>>> Modified: trunk/source/mxn.js >>>>> >>>>> =============================================================================>>>>> --- trunk/source/mxn.js (original) >>>>> +++ trunk/source/mxn.js Sun May 31 11:13:23 2009 >>>>> @@ -3,8 +3,56 @@ >>>>> // holds all our implementing functions >>>>> var apis = {}; >>>>> >>>>> + // ''Constructor'' >>>>> + (function() { >>>>> + // Defaults >>>>> + var providers = ''google,yahoo,microsoft''; >>>>> + 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; >>>>> + } >>>>> + } >>>>> + providers = providers.replace(/ /g, '''').split('',''); >>>>> + modules = modules.replace(/ /g, '''').split('',''); >>>>> + for (var i = 0; i < modules.length; i++) { >>>>> + loadScript(scriptBase + ''mxn.'' + modules[i] + >>>>> ''.js''); >>>>> + for (var j = 0; j < providers.length; j++) >>>>> loadScript(scriptBase + ''mxn.'' + providers[j] + ''.'' + modules[i] + ''.js''); >>>>> + } >>>>> + })(); >>>>> + >>>>> // Our special private methods >>>>> /** >>>>> + * loadScript is a JSON data fetcher >>>>> + * @param {String} src URL to JSON file >>>>> + * @param {Function} callback Callback function >>>>> + */ >>>>> + function loadScript(src, callback) { >>>>> + var script = document.createElement(''script''); >>>>> + script.type = ''text/javascript''; >>>>> + script.src = src; >>>>> + if (callback) { >>>>> + var evl = {}; >>>>> + evl.handleEvent = function(e) { >>>>> + callback(); >>>>> + }; >>>>> + script.addEventListener(''load'' ,evl ,true); >>>>> + } >>>>> + >>>>> document.getElementsByTagName(''head'')[0].appendChild(script); >>>>> + return; >>>>> + }; >>>>> + >>>>> + /** >>>>> * Calls the API specific implementation of a particular method. >>>>> */ >>>>> var invoke = function(sApiId, sObjName, sFnName, oScope, args){ >>>>> @@ -29,14 +77,14 @@ >>>>> }; >>>>> >>>>> return { >>>>> - >>>>> + >>>>> /** >>>>> * Registers a set of provider specific implementation >>>>> functions. >>>>> */ >>>>> register: function(sApiId, oApiImpl){ >>>>> if(!apis.hasOwnProperty(sApiId)) apis[sApiId] >>>>> {}; >>>>> mxn.util.merge(apis[sApiId], oApiImpl); >>>>> - }, >>>>> + }, >>>>> >>>>> /** >>>>> * Adds a list of named proxy methods to the prototype >>>>> of a >>>>> @@ -202,21 +250,8 @@ >>>>> * @param {String} src URL to JSON file >>>>> * @param {Function} callback Callback function >>>>> */ >>>>> - loadScript: function(src, callback) { >>>>> - var script >>>>> document.createElement(''script''); >>>>> - script.type = ''text/javascript''; >>>>> - script.src = src; >>>>> - if (callback) { >>>>> - var evl = {}; >>>>> - evl.handleEvent = function(e) { >>>>> - callback(); >>>>> - }; >>>>> - script.addEventListener(''load'' >>>>> ,evl ,true); >>>>> - } >>>>> - >>>>> document.getElementsByTagName(''head'')[0].appendChild(script); >>>>> - return; >>>>> - }, >>>>> - >>>>> + loadScript: loadScript, >>>>> + >>>>> /** >>>>> * >>>>> * @param {Object} point >>>>> @@ -334,6 +369,16 @@ >>>>> logN: function(number, base) { >>>>> return Math.log(number) / >>>>> Math.log(base); >>>>> }, >>>>> + >>>>> + /** >>>>> + * returns array of loaded provider apis >>>>> + * @returns {Array} providers >>>>> + */ >>>>> + getAvailableProviders : function () { >>>>> + var providers = []; >>>>> + for (var propertyName in apis) >>>>> providers.push(propertyName); >>>>> + return providers; >>>>> + }, >>>>> >>>>> dummy: 0 >>>>> >>>>> @@ -341,4 +386,5 @@ >>>>> >>>>> dummy: 0 >>>>> }; >>>>> + >>>>> })(); >>>>> >>>>> Modified: trunk/source/mxn.yahoo.core.js >>>>> >>>>> =============================================================================>>>>> --- trunk/source/mxn.yahoo.core.js (original) >>>>> +++ trunk/source/mxn.yahoo.core.js Sun May 31 11:13:23 2009 >>>>> @@ -1,5 +1,4 @@ >>>>> -mxn.register('' >>>>> -oo'', { >>>>> +mxn.register(''yahoo'', { >>>>> >>>>> Mapstraction: { >>>>> >>>>> >>>>> Modified: trunk/tests/index.htm >>>>> >>>>> =============================================================================>>>>> --- trunk/tests/index.htm (original) >>>>> +++ trunk/tests/index.htm Sun May 31 11:13:23 2009 >>>>> @@ -7,11 +7,7 @@ >>>>> <script type="text/javascript" src=" >>>>> http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=5wTxDW_V34GQjK.7glLG6OnJSRxCvfLj7ktMsuOoR42Gkm16vDVEjjw6FGWJ1Gky"></script> >>>>> >>>>> <script charset="UTF-8" type="text/javascript" src=" >>>>> http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2 >>>>> "></script> >>>>> <script src="domReady.js" type="text/javascript"></script> >>>>> - <script src="../source/mxn.js" type="text/javascript"></script> >>>>> - <script src="../source/mxn.core.js" >>>>> type="text/javascript"></script> >>>>> - <script src="../source/mxn.google.core.js" >>>>> type="text/javascript"></script> >>>>> - <script src="../source/mxn.yahoo.core.js" >>>>> type="text/javascript"></script> >>>>> - <script src="../source/mxn.microsoft.core.js" >>>>> type="text/javascript"></script> >>>>> + <script src="../source/mxn.js?(google, yahoo, microsoft)" >>>>> type="text/javascript"></script> >>>>> >>>>> <script type="text/javascript"> >>>>> //<![CDATA[ >>>>> @@ -40,7 +36,7 @@ >>>>> var infoElm = document.getElementById(''info''); >>>>> var eventsElm = document.getElementById(''events''); >>>>> >>>>> - var m = new mxn.Mapstraction(''map'', ''microsoft''); >>>>> + var m = new mxn.Mapstraction(''map''); >>>>> >>>>> m.endPan.addHandler(function(sEvtName, oEvtSource, >>>>> oEvtArgs){ >>>>> var center = oEvtSource.getCenter(); >>>>> @@ -136,7 +132,7 @@ >>>>> { >>>>> desc: ''Swap API'', >>>>> action: function(){ >>>>> - m.swap(''map'', ''google''); >>>>> + m.swap(''map'', ''microsoft''); >>>>> } >>>>> }, >>>>> >>>>> _______________________________________________ >>>>> Mapstraction mailing list >>>>> Mapstraction at lists.mapstraction.com >>>>> >>>>> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >>>> >>>> >>>> ------------------------------ >>>> >>>> _______________________________________________ >>>> Mapstraction mailing listMapstraction at lists.mapstraction.comhttp://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >>>> >>>> >>>> >>>> -- >>>> Andrew Turner >>>> m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner >>>> b: http://highearthorbit.com w: http://geocommons.com >>>> Introduction to Neogeography - http://oreilly.com/catalog/neogeography >>>> >>>> >>> >>> _______________________________________________ >>> Mapstraction mailing list >>> Mapstraction at lists.mapstraction.com >>> http://lists.mapstraction.com/listinfo.cgi/mapstraction-mapstraction.com >> >> >> >> >> -- >> Derek Fowler >> m. +44 (0) 7966 512 369 >> e. dezfowler at gmail.com >> > > > -- > Andrew Turner > m: 248.982.3609 e: andrew at highearthorbit.com t: @ajturner > b: http://highearthorbit.com w: http://geocommons.com > Introduction to Neogeography - http://oreilly.com/catalog/neogeography > >-- Derek Fowler m. +44 (0) 7966 512 369 e. dezfowler at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20090601/a3665422/attachment-0001.htm>