//
// カスタム図法を作る
//
function CustomeProjection() {
  GMercatorProjection.apply(this, arguments);
}

CustomeProjection.prototype = new GMercatorProjection();

// 北端と南端を繋げる
CustomeProjection.prototype.nsloop = false;

// 東端と西端を繋げる
CustomeProjection.prototype.ewloop = false;

// 東端と西端を繋げる
CustomeProjection.prototype.tileCheckRange = function(tile, zoom, tilesize) {
  var mapsize = 256 * Math.pow(2,zoom);
  var tilenum = Math.floor(mapsize / tilesize);
  
  if (this.nsloop) {
    if (tile.y < 0 || tile.y * tilesize >= mapsize) {
      tile.y = tile.y % tilenum;
      if (tile.y < 0) {
        tile.y += tilenum;
      }
    }
  } else {
    if (tile.y < 0 || tile.y * tilesize >= mapsize) {
      return false;
    }
  }
  
  if (this.ewloop) {
    if (tile.x < 0 || tile.x * tilesize >= mapsize) {
      tile.x = tile.x % tilenum;
      if (tile.x < 0) {
        tile.x += tilenum;
      }
    }
  } else {
    if (tile.x < 0 || tile.x * tilesize >= mapsize) {
      return false;
    }
  }
  
  return true;
}

