Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[topo] do not fetch out of range tiles

  • Loading branch information...
commit 81b9006564d007bd6e815f47866ee0f0536fd6a3 1 parent 25a5597
@vicb authored
View
127 src/vgps3/plugins/topo/abstracttopo.js
@@ -0,0 +1,127 @@
+/**
+ * Copyright 2012 Victor Berchet
+ *
+ * This file is part of VisuGps3
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ */
+
+/**
+ * @fileoverview Base class for topo maps.
+ * @author Victor Berchet <victor@suumit.com>
+ */
+
+goog.provide('vgps3.topo.AbstractTopo');
+
+goog.require('goog.array');
+
+
+/**
+ * @constructor
+ * @extends {vgps3.PluginBase}
+ */
+vgps3.topo.AbstractTopo = function() {
+ goog.base(this);
+
+ /**
+ * @type {Array.<google.maps.LatLngBounds>} The visible areas
+ * @protected
+ */
+ this.bounds_;
+
+ /**
+ * @type {goog.debug.Logger}
+ * @private_
+ */
+ this.logger_ = goog.debug.Logger.getLogger('vgps3.topo.AbstractTopo');
+
+};
+goog.inherits(vgps3.topo.AbstractTopo, vgps3.PluginBase);
+
+/**
+ * Set the visible area
+ *
+ * @param {!Array.<Array.<number>>} latlngBounds format: [lat, lng, lat, lng]
+ * @protected
+ */
+vgps3.topo.AbstractTopo.prototype.setBounds_ = function(latlngBounds) {
+ var that = this;
+
+ this.bounds_ = [];
+ goog.array.forEach(latlngBounds || [], function(bounds) {
+ var lats = [bounds[0], bounds[2]],
+ lngs = [bounds[1], bounds[3]];
+
+ goog.array.sort(lats);
+ goog.array.sort(lngs);
+
+ that.bounds_.push(new google.maps.LatLngBounds(
+ new google.maps.LatLng(lats[0], lngs[0]),
+ new google.maps.LatLng(lats[1], lngs[1])
+ ));
+ });
+};
+
+
+/**
+ * Checks if the tile is provided by the map.
+ *
+ * @param {google.maps.Point} coord
+ * @param {number} zoom
+ * @protected
+ *
+ * @return {boolean} Whether the tile is provided by the current map
+ */
+vgps3.topo.AbstractTopo.prototype.isTileVisible_ = function(coord, zoom) {
+ var numTiles = Math.pow(2, zoom),
+ e = 256 * coord.x / numTiles,
+ w = 256 * (coord.x + 1) / numTiles,
+ s = 256 * (coord.y + 1) / numTiles,
+ n = 256 * coord.y / numTiles,
+ projection,
+ tileBounds,
+ visible;
+
+ projection = this.gMap_.getProjection();
+
+ tileBounds = new google.maps.LatLngBounds(
+ projection.fromPointToLatLng(new google.maps.Point(w, s)),
+ projection.fromPointToLatLng(new google.maps.Point(e, n))
+ );
+
+ goog.array.some(this.bounds_, function(bounds) {
+ visible = bounds.intersects(tileBounds);
+
+ if (visible) {
+ this.logger_.info("Tile visible in range: " + bounds.toString());
+ }
+
+ return visible;
+ },
+ this
+ );
+
+ return visible;
+}
+
+/**
+ * Returns the map type.
+ *
+ * @return {google.maps.ImageMapType} The map type.
+ *
+ * @protected
+ */
+vgps3.topo.AbstractTopo.prototype.getMapType_ = goog.abstractMethod;
+
+/**
+ * Returns the URL of a tile.
+ *
+ * @param {google.maps.Point} coord
+ * @param {number} zoom
+ * @return {?string}
+ *
+ * @protected
+ */
+vgps3.topo.AbstractTopo.prototype.getTileUrl_ = goog.abstractMethod;
View
33 src/vgps3/plugins/topo/ch.js
@@ -17,7 +17,7 @@ goog.provide('vgps3.topo.ch.Map');
goog.require('goog.math');
goog.require('vgps3.Map');
-goog.require('vgps3.PluginBase');
+goog.require('vgps3.topo.AbstractTopo');
goog.require('vgps3.proj.GProj');
goog.require('vgps3.proj.Swisstopo');
@@ -25,7 +25,7 @@ goog.require('vgps3.proj.Swisstopo');
/**
* @constructor Spain IGN map type for google maps.
- * @extends {vgps3.PluginBase}
+ * @extends {vgps3.topo.AbstractTopo}
*/
vgps3.topo.ch.Map = function() {
/**
@@ -54,17 +54,16 @@ vgps3.topo.ch.Map = function() {
goog.base(this);
};
-goog.inherits(vgps3.topo.ch.Map, vgps3.PluginBase);
+goog.inherits(vgps3.topo.ch.Map, vgps3.topo.AbstractTopo);
/**
- * Registers this map type in google maps.
- *
* @override
*/
vgps3.topo.ch.Map.prototype.init = function(vgps) {
var that = this;
goog.base(this, 'init', vgps);
+ this.setBounds_([[45.3981, 5.1402, 48.2306, 11.4774]]);
this.gMap_.mapTypes.set(vgps3.topo.ch.MapTypeId.TERRAIN, /** @type {?} */ (this.getMapType_()));
this.center_ = this.gMap_.getCenter();
this.previousZoom_ = this.gMap_.getZoom();
@@ -73,7 +72,6 @@ vgps3.topo.ch.Map.prototype.init = function(vgps) {
'maptypeid_changed',
goog.bind(this.mapTypeChangeHandler_, this)
);
-
// Capture the center value when the map becomes idle
// This is required to apply this value when the zoom level changes as consecutive zoom
// resolution ratio is not 2 as expected by the google maps API
@@ -106,10 +104,10 @@ vgps3.topo.ch.Map.prototype.enable_ = function() {
this.updateProjection_();
this.zoomListener_ = google.maps.event.addListener(
- this.gMap_,
- 'zoom_changed',
- goog.bind(this.updateProjection_, this)
- );
+ this.gMap_,
+ 'zoom_changed',
+ goog.bind(this.updateProjection_, this)
+ );
};
@@ -145,8 +143,7 @@ vgps3.topo.ch.Map.prototype.updateProjection_ = function() {
/**
- * @return {google.maps.ImageMapType} The map type.
- * @private
+ * @override
*/
vgps3.topo.ch.Map.prototype.getMapType_ = function() {
var mapType = new google.maps.ImageMapType({
@@ -166,18 +163,12 @@ vgps3.topo.ch.Map.prototype.getMapType_ = function() {
/**
- * Returns the URL of a tile.
- *
- * @param {google.maps.Point} coord
- * @param {number} zoom
- * @return {?string}
- *
- * @private
+ * @override
*/
vgps3.topo.ch.Map.prototype.getTileUrl_ = function(coord, zoom) {
- var numTiles = 1 << zoom;
+ var numTiles = Math.pow(2, zoom);
- if (coord.y < 0 || coord.y >= numTiles) {
+ if (!this.isTileVisible_(coord, zoom)) {
return null;
}
return vgps3.topo.ch.TILES_URL
View
52 src/vgps3/plugins/topo/es.js
@@ -17,7 +17,7 @@
goog.provide('vgps3.topo.es.Map');
goog.require('vgps3.Map');
-goog.require('vgps3.PluginBase');
+goog.require('vgps3.topo.AbstractTopo');
goog.require('vgps3.proj.GProj');
goog.require('vgps3.proj.Iberpix');
@@ -25,7 +25,7 @@ goog.require('vgps3.proj.Iberpix');
/**
* @constructor Spain IGN map type for google maps.
- * @extends {vgps3.PluginBase}
+ * @extends {vgps3.topo.AbstractTopo}
*/
vgps3.topo.es.Map = function() {
/**
@@ -54,16 +54,16 @@ vgps3.topo.es.Map = function() {
goog.base(this);
};
-goog.inherits(vgps3.topo.es.Map, vgps3.PluginBase);
+goog.inherits(vgps3.topo.es.Map, vgps3.topo.AbstractTopo);
/**
- * Registers this map type in google maps.
- *
* @override
*/
vgps3.topo.es.Map.prototype.init = function(vgps) {
goog.base(this, 'init', vgps);
+ // @see http://www.idee.es/wms/PNOA/PNOA?Request=GetCapabilities&Service=WMS
+ this.setBounds_([[44.0314, -21.3797, 27.1410, 5.0789]]);
this.gMap_.mapTypes.set(vgps3.topo.es.MapTypeId.TERRAIN, /** @type {?} */ (this.getMapType_()));
google.maps.event.addListener(
this.gMap_,
@@ -94,16 +94,16 @@ vgps3.topo.es.Map.prototype.enable_ = function() {
this.updateProjection_(true);
this.zoomListener_ = google.maps.event.addListener(
- this.gMap_,
- 'zoom_changed',
- goog.bind(this.updateProjection_, this)
- );
+ this.gMap_,
+ 'zoom_changed',
+ goog.bind(this.updateProjection_, this)
+ );
this.moveListener_ = google.maps.event.addListener(
- this.gMap_,
- 'center_changed',
- goog.bind(this.updateProjection_, this)
- );
+ this.gMap_,
+ 'center_changed',
+ goog.bind(this.updateProjection_, this)
+ );
};
@@ -151,14 +151,13 @@ vgps3.topo.es.Map.prototype.updateProjection_ = function(opt_force) {
/**
- * @return {google.maps.ImageMapType} The map type.
- * @private
+ * @override
*/
vgps3.topo.es.Map.prototype.getMapType_ = function() {
var mapType = new google.maps.ImageMapType({
getTileUrl: goog.bind(this.getTileUrl_, this),
tileSize: new google.maps.Size(256, 256),
- minZoom: 6,
+ minZoom: vgps3.topo.es.ZOOM_OFFSET,
maxZoom: 18,
name: 'TopoES',
alt: 'Cartes IGN Espagne'
@@ -171,28 +170,21 @@ vgps3.topo.es.Map.prototype.getMapType_ = function() {
/**
- * Returns the URL of a tile.
- *
- * @param {google.maps.Point} coord
- * @param {number} zoom
- * @return {?string}
- *
- * @private
+ * @override
*/
vgps3.topo.es.Map.prototype.getTileUrl_ = function(coord, zoom) {
- var numTiles = 1 << zoom,
- y = -coord.y - 1;
- if (y < 0 || y >= numTiles) {
+ var numTiles = Math.pow(2,zoom);
+
+ if (!this.isTileVisible_(coord, zoom)) {
return null;
}
return vgps3.topo.es.TILES_URL
.replace('{server}', (vgps3.topo.es.serverIndex_++ % 5).toString(10))
.replace('{layer}', this.getLayerName_(zoom))
.replace('{zone}', this.zone_.toString(10))
- .replace('{scale}', (2048 / Math.pow(2, zoom - 6) * 1000).toString(10))
+ .replace('{scale}', (2048 / Math.pow(2, zoom - vgps3.topo.es.ZOOM_OFFSET) * 1000).toString(10))
.replace('{x}', (((coord.x % numTiles) + numTiles) % numTiles).toString(10))
- .replace('{y}', y.toString(10));
-
+ .replace('{y}', (-coord.y - 1).toString(10));
};
@@ -240,7 +232,7 @@ vgps3.topo.es.LAYER_NAMES = ['mapa_millon', 'mapa_mtn200', 'mapa_mtn50', 'mapa_m
/**
* @const
- * @type {number}
+ * @type {number} 2^ZOOM_OFFSET should be >= number of tiles required to cover the whole world
*/
vgps3.topo.es.ZOOM_OFFSET = Math.round(Math.log(2 * Math.PI * 6378137 / (2048 * 256)) / Math.LN2);
View
48 src/vgps3/plugins/topo/fr.js
@@ -17,32 +17,50 @@
goog.provide('vgps3.topo.fr.Map');
goog.require('vgps3.Map');
-goog.require('vgps3.PluginBase');
+goog.require('vgps3.topo.AbstractTopo');
/**
* @constructor France IGN map type for google maps.
- * @extends {vgps3.PluginBase}
+ * @extends {vgps3.topo.AbstractTopo}
*/
vgps3.topo.fr.Map = function() {
goog.base(this);
/**
* @type {?string}
+ * @private
*/
this.tilesUrl_;
};
-goog.inherits(vgps3.topo.fr.Map, vgps3.PluginBase);
+goog.inherits(vgps3.topo.fr.Map, vgps3.topo.AbstractTopo);
/**
- * Registers this map type in google maps.
- *
* @override
*/
vgps3.topo.fr.Map.prototype.init = function(vgps) {
goog.base(this, 'init', vgps);
+ this.setBounds_([
+ [42.3058, -0.7618, 46.4181, 7.9109], // FXX
+ [11.7, -64, 18.18, -59], // ANF
+ [-40, 76, -36, 79], // ASP
+ [-68.62, 132.56, -64.03, 144.54], // ATF
+ [-48, 47, -44, 55], // CRZ
+ [15.75, -63.2, 17.5, -60], // GLP
+ [-4.3, -62.1, 11.5, -46], // GUF
+ [-53, 62, -45, 76], // KER
+ [11.7, -64, 15.7, -59], // MTQ
+ [-17.5, 40, 3, 56], //MYT
+ [-24.3, 160, -17.1, 170], // NCL
+ [-28.2, -160, 11, -108], // PYF
+ [-26.2, 37.5, -17.75, 60], // REU
+ [17.75, -63, 17.99, -62.7], // SBA
+ [18, -63.19, 18.18, -62.9], // SMA
+ [43.5, -60, 52, -50], // SPM
+ [-14.6, -178.5, -12.8, -175.8] // WLF
+ ]);
var key = vgps.getDomainKey(vgps3.topo.fr.API_KEYS);
this.tilesUrl_ = null == key ? null : vgps3.topo.fr.TILES_URL.replace('{API_KEY}', key);
this.gMap_.mapTypes.set(vgps3.topo.fr.MapTypeId.TERRAIN, /** @type {?} */ (this.getMapType_()));
@@ -50,8 +68,7 @@ vgps3.topo.fr.Map.prototype.init = function(vgps) {
/**
- * @return {google.maps.ImageMapType} The map type.
- * @private
+ * @override
*/
vgps3.topo.fr.Map.prototype.getMapType_ = function() {
return new google.maps.ImageMapType({
@@ -66,28 +83,19 @@ vgps3.topo.fr.Map.prototype.getMapType_ = function() {
/**
- * Returns the URL of a tile.
- *
- * @param {google.maps.Point} coord
- * @param {number} zoom
- * @return {?string}
- *
- * @private
+ * @override
*/
vgps3.topo.fr.Map.prototype.getTileUrl_ = function(coord, zoom) {
- var numTiles = 1 << zoom;
- if (!this.tilesUrl_) {
- return null;
- }
- if (coord.y < 0 || coord.y >= numTiles) {
+ var numTiles = Math.pow(2, zoom);
+ if (!this.tilesUrl_ || !this.isTileVisible_(coord, zoom)) {
return null;
}
+
return this.tilesUrl_
.replace('{zoom}', zoom.toString(10))
.replace('{x}', (((coord.x % numTiles) + numTiles) % numTiles).toString(10))
.replace('{y}', coord.y.toString(10))
.replace('{layer}', 'GEOGRAPHICALGRIDSYSTEMS.MAPS');
-
};
View
5 src/vgps3/proj/gproj.js
@@ -21,7 +21,7 @@ goog.require('vgps3.proj.IProj');
/**
* @param {vgps3.proj.IProj} projection
- * @param {number=} opt_scale0 The resolution at zoom level 0 (ie a single tile).
+ * @param {number=} opt_scale0 The resolution at zoom level 0 = world width in meters.
* @constructor
*/
vgps3.proj.GProj = function(projection, opt_scale0) {
@@ -32,7 +32,7 @@ vgps3.proj.GProj = function(projection, opt_scale0) {
this.projection_ = projection;
/**
- * @type {number}
+ * @type {number} The resolution at zoom level 0
* @private
*/
this.scale0_;
@@ -50,7 +50,6 @@ vgps3.proj.GProj = function(projection, opt_scale0) {
this.y0_ = projection.getOrigin().y;
this.setScale0(opt_scale0);
-
};
View
6 src/vgps3/viewer.js
@@ -176,6 +176,8 @@ vgps3.Viewer.prototype.array2LatLng_ = function(opt_latlng) {
goog.exportSymbol('vgps3.Viewer', vgps3.Viewer);
if (goog.DEBUG) {
- var console = new goog.debug.Console();
- console.setCapturing(true);
+ (function() {
+ var console = new goog.debug.Console();
+ console.setCapturing(true);
+ })();
}
View
10 todo.txt
@@ -3,15 +3,10 @@
- https://addons.mozilla.org/en-US/firefox/addon/leak-monitor/
- https://code.google.com/p/leak-finder-for-javascript/
-- Restrict topo map to their boundaries
-
- track plugin
- add a track
- - remove a track
- - load kml (!earth plugin)
-
-- gmaps
- - keys per domain,
+ - remove a track (no more track -> no more marker, ..., remove selected track)
+ - load kml (!earth plugin) -> chart should probably dispay h=f(dist)
- add layers:
- skyways (requires a "more" control)
@@ -29,4 +24,3 @@
- vs distance (in addition to vs time)
- allow to specify displayed charts
-- js loader: handler errors
Please sign in to comment.
Something went wrong with that request. Please try again.