Skip to content

Commit

Permalink
Add repeat property to po.url.
Browse files Browse the repository at this point in the history
True by default. Can be set to false to disable column wrap-around.
  • Loading branch information
mbostock committed Nov 26, 2010
1 parent 1e3ea23 commit 1754c96
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 69 deletions.
1 change: 1 addition & 0 deletions examples/cloudmade/pale-dawn.js
Expand Up @@ -9,6 +9,7 @@ map.add(po.image()
.url(po.url("http://{S}tile.cloudmade.com"
+ "/1a1b06b230af4efdbb989ea99e9841af" // http://cloudmade.com/register
+ "/998/256/{Z}/{X}/{Y}.png")
.repeat(false)
.hosts(["a.", "b.", "c.", ""])));

map.add(po.compass()
Expand Down
20 changes: 16 additions & 4 deletions polymaps.js
Expand Up @@ -2,7 +2,7 @@ if (!org) var org = {};
if (!org.polymaps) org.polymaps = {};
(function(po){

po.version = "2.3.0"; // semver.org
po.version = "2.3+1.0"; // not semver!

var zero = {x: 0, y: 0};
po.ns = {
Expand Down Expand Up @@ -182,12 +182,18 @@ po.cache = function(load, unload) {
return cache;
};
po.url = function(template) {
var hosts = [];
var hosts = [],
repeat = true;

function format(c) {
var max = c.zoom < 0 ? 1 : 1 << c.zoom,
column = c.column % max;
if (column < 0) column += max;
column = c.column;
if (repeat) {
column = c.column % max;
if (column < 0) column += max;
} else if ((column < 0) || (column >= max)) {
return "about:blank";
}
return template.replace(/{(.)}/g, function(s, v) {
switch (v) {
case "S": return hosts[(Math.abs(c.zoom) + c.row + column) % hosts.length];
Expand Down Expand Up @@ -220,6 +226,12 @@ po.url = function(template) {
return format;
};

format.repeat = function(x) {
if (!arguments.length) return repeat;
repeat = x;
return format;
};

return format;
};
po.dispatch = function(that) {
Expand Down

0 comments on commit 1754c96

Please sign in to comment.