/**
* @classdesc A vector source in one of the supported formats, using a custom function to read in the data from a remote server.
* @constructor
* @extends {ol.source.Vector}
* @param {cercaliax.tile.ServerVectorOptions} options Options.
*/
cercalia.tile.ServerVector = function(options) {
// Call parent constructor
var parentOptions = {
attributions: options.attributions,
logo: options.logo,
projection: options.projection
};
ol.source.Vector.call(this, parentOptions);
/* OPTIONS */
/**
* Tiles download strategy.
* @private
* @type {Function}
*/
this.strategy_ = options.strategy ? options.strategy : ol.loadingstrategy.bbox;
/**
* Upload features function.
* @private
* @type {Function}
*/
this.loader_ = options.loader ? options.loader : null;
/**
* Tiles grid.
* @private
* @type {ol.tilegrid.XYZ}
*/
this.tileGrid_ = options.tileGrid ? options.tileGrid : null;
/* VARIABLES PRIVADAS */
/**
* Hash (key => ZXY) with uploaded tiles.
* @private
* @type {Object}
*/
this.tileLoadedHash_ = {};
};
ol.inherits(cercalia.tile.ServerVector, ol.source.Vector);
/**
* Not implemented yet.
*/
/*cercalia.tile.ServerVector.prototype.addFeaturesInternal = function(features) {
console.log("addFeaturesInternal");
};*/
/**
* Clean the hash indicating which tiles have been downloaded.
* @param {number|undefined} zoomLevel Zoom level to delete, if not specified deletes all.
*/
cercalia.tile.ServerVector.prototype.clear = function(zoomLevel) {
if(zoomLevel) this.tileLoadedHash_[zoomLevel] = {};
else this.tileLoadedHash_ = {};
};
/**
* Loads features according to bounds and resolution.
* @param {ol.Extent} extent Map bounds.
* @param {number} resolution Map resolution.
* @param {string} projection Map projection.
*/
cercalia.tile.ServerVector.prototype.loadFeatures = function(extent, resolution, projection) {
//console.log("loadFeatures: ", extent, resolution, projection);
// Obtenemos extension con nuestra strategia.
var extentsToLoad = this.strategy_(extent, resolution);
// Por todas las tiles no cargadas antes llamamos al loader.
for ( var index in extentsToLoad) {
var extentToLoad = extentsToLoad[index].extent;
var tileCoord = extentsToLoad[index].tileId;
/*var tileCoord = this.tileGrid_.getTileRangeForExtentAndResolution(extentToLoad, resolution);
tileCoord = [this.tileGrid_.getZForResolution(resolution), tileCoord.minX, tileCoord.minY];*/
// Creamos el objeto en la hash si no lo esta.
if(!this.tileLoadedHash_[tileCoord[0]]) this.tileLoadedHash_[tileCoord[0]] = {};
if(!this.tileLoadedHash_[tileCoord[0]][tileCoord[1]]) this.tileLoadedHash_[tileCoord[0]][tileCoord[1]] = {};
if(!this.tileLoadedHash_[tileCoord[0]][tileCoord[1]][tileCoord[2]]) {
this.tileLoadedHash_[tileCoord[0]][tileCoord[1]][tileCoord[2]] = true; // Tile cargada!
// console.log("Tile " + tileCoord[0] + ", " + tileCoord[1] + ", " + tileCoord[2] + " loaded: " + extentToLoad.join(", "));
if(this.loader_) this.loader_(extentToLoad, resolution, projection, tileCoord);
} else {
// console.log("Tile " + tileCoord[0] + ", " + tileCoord[1] + ", " + tileCoord[2] + ": ja pintada.");
}
}
};
/**
* Checks whether the zoom is like the map
* @param {Object} tileId Id de la tile ZXY
*/
cercalia.tile.ServerVector.prototype.setLoadedTile = function(tileId, loaded) {
if(this.tileLoadedHash_[tileId[0]] && this.tileLoadedHash_[tileId[0]][tileId[1]] && this.tileLoadedHash_[tileId[0]][tileId[1]][tileId[2]]) {
this.tileLoadedHash_[tileId[0]][tileId[1]][tileId[2]] = loaded;
// console.log("tile: " + tileId[0] + ", " + tileId[1] + ", " + tileId[2] + " -> " + loaded);
}
};
//cercalia.tile.ServerVector.prototype.readFeatures;