/**
* @fileoverview bu.street.ImagesManager is an abstract class for ImagesManagers
* that show street 360 panoramas and data.
* Created 23/03/2017.
* @author josea.hernandez@blom.no (Jose Antonio Hernandez)
* @author rafael.delaviuda@blom.no (Rafael de la Viuda)
* @author raul.sangil@blom.no (Raul Sangil)
* @copyright Blom Data S.L. 2017
*/
goog.provide('bu.street.ImagesManager');
goog.require('ol');
goog.require('ol.Object');
/**
* Constructor for bu.street.ImagesManager class
* @typedef bu.street.ImagesManagerOptions;
*/
/**
* @classdesc
* This class is required to store metadata ImagesManager for BlomStreet panoramas
*
* @constructor
* @extends {bu.Object}
* @param {bu.street.ImagesManagerOptions} ImagesManager options
* @api
*/
bu.street.ImagesManager = function(options) {
ol.Object.call(this);
this.images_ = [];
};
ol.inherits(bu.street.ImagesManager, ol.Object);
/**
* Adds an image to the ImagesManager collection. If an image with same ID exists
* then it is replaced by the new one.
* @param {bu.street.Image} image The image to add.
* @api
*/
bu.street.ImagesManager.prototype.addImage = function(image){
if (image != null && image.id != null) {
var index = this.findImageById(image.id);
if (index != -1) {
this.images_.splice(index, 1);
}
this.images_.push(image);
}
}
/**
* Return the {@link bu.Coordinate} center of an image. This center
* is the point where the 360 image is shot. Coordinates are always in WGS84
* latlon, first value in the coordinate is longitude and second latitude.
* @param {string} imageId The ID of the image to search the center for.
* @return {bu.Coordinate|undefined} The image center. If no image is found
* undefined is returned.
* @api
*/
bu.street.ImagesManager.prototype.getImageCenter = function(imageId){
var actual = this.findImageById(imageId);
if (actual != -1) {
var center = [this.images_[actual].xcp, this.images_[actual].ycp];
return center;
} else {
return undefined;
}
}
/**
* Search images in local array. True == image is present
* @param {string} imageId The imageId of the image to search for.
* @return {number} Returns the index of the image in the images array or -1 if
* image is not stored in the images manager.
* @api
*/
bu.street.ImagesManager.prototype.findImageById = function(imageId){
var index;
var limit = this.images_.length;
for(index=0; index<limit; index++){
if (this.images_[index].id === imageId){
return index;
}
}
return -1;
}
/**
* If present, returns image object
* @param {string} imageId Image id of the image we want to get.
* @return {bu.street.image}
* @api
*/
bu.street.ImagesManager.prototype.getImageById = function(imageId){
var index;
var limit = this.images_.length;
for(index=0; index<limit; index++){
if (this.images_[index].id === imageId){
return this.images_[index];
}
}
return null;
}