From 0b61c86b6b21e2a454ad70e7a7f4a8a9b4f1fcb1 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 11 Apr 2011 17:43:23 -0400 Subject: [PATCH] Building out WaxProvider to take multiple domain names and zoom restrictions. --- build/wax.mm.js | 37 ++++++++++++++++++++------------ build/wax.mm.min.js | 2 +- connectors/mm/waxprovider.js | 37 ++++++++++++++++++++------------ manual/index.html | 41 ++++++++++++++++++------------------ 4 files changed, 70 insertions(+), 47 deletions(-) diff --git a/build/wax.mm.js b/build/wax.mm.js index 3a275a18..4ffb67e7 100644 --- a/build/wax.mm.js +++ b/build/wax.mm.js @@ -1732,32 +1732,43 @@ if (!com) { // A layer connector for Modest Maps // -// Takes a `base_url` first argument that can be a string for a single +// ### Required arguments +// +// * `base_url` first argument that can be a string for a single // server or an array to hit multiple servers or CNAMEs. +// * `layername` // -// Also takes a `layername` argument. +// ### Optional arguments // -// Also takes a `filetype` argument. -com.modestmaps.WaxProvider = function(base_url, layername, filetype) { - this.layername = layername; - this.base_urls = (typeof(base_url) == 'string') ? [base_url] : base_url; - this.n_urls = this.base_urls.length; - this.filetype = filetype || '.png'; +// * `filetype`: like `.jpeg` (default `.png`) +// * `zoomrange`: like [0, 10] (default [0, 18]) +// +com.modestmaps.WaxProvider = function(options) { + this.layerName = options.layerName; + this.baseUrls = (typeof(options.baseUrl) == 'string') ? + [options.baseUrl] : options.baseUrl; + this.n_urls = this.baseUrls.length; + this.filetype = options.filetype || '.png'; + this.zoomRange = options.zoomRange || [0, 18]; }; com.modestmaps.WaxProvider.prototype = { - key: null, - style: null, + outerLimits: function() { + return [ + new com.modestmaps.Coordinate(0,0,0).zoomTo(this.zoomRange[0]), + new com.modestmaps.Coordinate(1,1,0).zoomTo(this.zoomRange[1]) + ]; + }, getTileUrl: function(coord) { coord = this.sourceCoordinate(coord); var worldSize = Math.pow(2, coord.zoom); coord.row = Math.pow(2, coord.zoom) - coord.row - 1; if (this.n_urls === 1) { - var server = this.base_urls[0]; + var server = this.baseUrls[0]; } else { - var server = this.base_urls[parseInt(worldSize * coord.row + coord.column) % this.n_urls]; + var server = this.baseUrls[parseInt(worldSize * coord.row + coord.column) % this.n_urls]; } - var imgPath = new Array('1.0.0', this.layername, coord.zoom, coord.column, coord.row).join('/'); + var imgPath = ['1.0.0', this.layerName, coord.zoom, coord.column, coord.row].join('/'); return server + imgPath + this.filetype; } }; diff --git a/build/wax.mm.min.js b/build/wax.mm.min.js index 5554302e..c33e1e50 100644 --- a/build/wax.mm.min.js +++ b/build/wax.mm.min.js @@ -7,4 +7,4 @@ * * This document is licensed as free software under the terms of the * MIT License: http://www.opensource.org/licenses/mit-license.php - */(function(a,b){function B(m){function P(a){!(M++)&&b(function(){N(),G&&a!=u&&(x[I]=a),f(m.error,m,[m,a]),f(B,m,[m,a])},0)}function O(a){!(M++)&&b(function(){N(),G&&(x[I]={s:[a]}),C&&(a=C.apply(m,[a])),f(m.success,m,[a,t]),f(B,m,[m,t])},0)}m=a.extend({},A,m);var B=m.complete,C=m.dataFilter,D=m.callbackParameter,E=m.callback,F=m.cache,G=m.pageCache,H=m.charset,I=m.url,J=m.data,K=m.timeout,L,M=0,N=c;m.abort=function(){!(M++)&&N()};if(f(m.beforeSend,m,[m])===!1||M)return m;I=I||j,J=J?typeof J=="string"?J:a.param(J,m.traditional):j,I+=J?g(I)+J:j,D&&(I+=g(I)+encodeURIComponent(D)+"=?"),!F&&!G&&(I+=g(I)+"_"+(new Date).getTime()+"="),I=I.replace(/=\?(&|$)/,"="+E+"$1"),G&&(L=x[I])?L.s?O(L.s[0]):P(L):b(function(f,g,j){if(!M){j=K>0&&b(function(){P(u)},K),N=function(){j&&clearTimeout(j),f[q]=f[n]=f[p]=f[o]=null,w[r](f),g&&w[r](g)},window[E]=d,f=a(s)[0],f.id=l+y++,H&&(f[i]=H);function m(a){(f[n]||c)(),a=z,z=undefined,a?O(a[0]):P(k)}v.msie?(f.event=n,f.htmlFor=f.id,f[q]=function(){/loaded|complete/.test(f.readyState)&&m()}):(f[o]=f[p]=m,v.opera?(g=a(s)[0]).text="jQuery('#"+f.id+"')[0]."+o+"()":f[h]=h),f.src=I,e(f),g&&e(g)}},0);return m}function g(a){return/\?/.test(a)?"&":"?"}function f(a,b,c){return a&&a.apply(b.context||b,c)}function e(a){w.insertBefore(a,w.firstChild)}function d(a){z=[a]}function c(){}var h="async",i="charset",j="",k="error",l="_jqjsp",m="on",n=m+"click",o=m+k,p=m+"load",q=m+"readystatechange",r="removeChild",s="