/**
* POIs overlay widget constructor
* @class
* @constructor
* @param {cercaliax.widget.PoiMapOptions} options PoiMap options
*/
cercalia.widget.PoiMap = function (options) {
/**
* Class name
* @private
* @type {string}
*/
this.CLASS_NAME_ = "cercalia.widget.PoiMap";
/* OPTIONS */
/**
* Container DIV Id.
* @private
* @type {string}
*/
this.divId_ = options.div ? options.div : null;
/**
* Menu options.
* @private
* @type {cercaliax.widget.PoiListOptions}
*/
this.poiListOptions_ = options.poiListOptions ? options.poiListOptions : {};
/* VARIABLES PRIVADAS */
/**
* Map.
* @private
* @type {cercalia.map}
*/
this.map_ = null;
/* SERVICIOS Y WIDGETS DE CERCALIA */
/**
* Categories menu
* @private
* @type {cercalia.widget.PoiList}
*/
this.poiListWidget_ = null;
/**
* Get POIs service
* @private
* @type {cercalia.service.Pois}
*/
/*this.servicePois_ = new cercalia.service.Pois({
searchByScale : true
});*/
/**
* Get POIs service
* @private
* @type {cercalia.TilePoiMap}
*/
this.tilePoiMap_ = null
// Inicializamos
this.initialize_();
};
/**
* Initializes element.
* @private
*/
cercalia.widget.PoiMap.prototype.initialize_ = function () {
var self = this;
if( ! this.divId_ ) {
cercalia.Exception(cercalia.i18n._('WIDGET_ERR_NO_DIV "%"', this.CLASS_NAME_));
} else {
var element = cercalia.jQuery("#" + this.divId_).addClass("cercalia-widget cercalia-widget-poimap");
var self = this;
var divMenu = cercalia.jQuery("<div />").attr("id", this.divId_ + "_menu").appendTo(element);
this.poiListOptions_.div = divMenu.attr("id");
var timmerNoElements = null;
this.poiListOptions_.clickElementList = function () {
if(this.tilePoiMap_ !== null) {
// Esperamos 1/2 segundo antes de lanzar la peticion por si clikan mas elementos.
if(timmerNoElements != null) {
window.clearTimeout(timmerNoElements);
timmerNoElements = null;
//console.log("Clean timeout");
}
timmerNoElements = window.setTimeout(function () {
//console.log("update pois!");
self.updatePois();
}, 500);
} else {
cercalia.Exception(cercalia.i18n._('WIDGET_ERR_NO_MAP "%"', this.CLASS_NAME_));
}
};
this.poiListWidget_ = new cercalia.widget.PoiList(this.poiListOptions_);
}
};
/**
* Modify the map with which interacts the widget.
* @param {cercalia.Map} map Map with which will interact the widget.
*/
cercalia.widget.PoiMap.prototype.setMap = function (map) {
this.map_ = map;
if(this.tilePoiMap_) {
this.tilePoiMap_.remove();
delete this.tilePoiMap_;
}
this.tilePoiMap_ = new cercalia.TilePoiMap({
map : this.map_,
tileSize: [256, 256],
iconBigZoomLevel: 15
});
};
/**
* Returns the type of the object.
* @return {string}
*/
cercalia.widget.PoiMap.prototype.getClass = function(){
return this.CLASS_NAME_;
};
/**
* Force to reload pois
*/
cercalia.widget.PoiMap.prototype.updatePois = function() {
if(this.tilePoiMap_) {
this.tilePoiMap_.setCategories(this.poiListWidget_.getSelectedId());
}
};
/**
* Remove all pois.
*/
cercalia.widget.PoiMap.prototype.removePois = function() {
if(this.tilePoiMap_) {
this.tilePoiMap_.removeAll();
}
};