/**
* <span>
* Copyright Franson Technology AB, Sweden, 2009
* </span>
* <a href="http://gpsgate.com/">http://gpsgate.com</a>, <a href="http://franson.com/">http://franson.com</a>
* <span>
* author Fredrik Blomqvist
* </span>
*
* @module Map
*
*/
var Franson = Franson || {};
/**
* namespace
* @class Franson.Map
* @static
*/
Franson.Map = Franson.Map || {};
/**
* similar to standard marker but with blinking (uses Shape.getAlarmIcon)
* @class Franson.Map.AlarmMarker
* @extends Franson.Map.IOverlay
* @constructor
* @param {LatLng} pos
* @param {literal} [options]
*/
Franson.Map.AlarmMarker = function(pos, options)
{
this._options = MochiKit.Base.setdefault(options, {
hide: false,
blinkInterval: 700,
title: null
});
this._icon = null;
this._layer = null;
this._latlng = pos;
this._clickHandler = null;
this._blinkHandler = null;
this._hidden = this._options.hide;
this._boundsHidden = false;
};
// methods
Franson.Map.AlarmMarker.prototype =
{
/**
* @method initialize
* @param {Franson.Map.Layer} layer
* @protected
*/
initialize: function(layer) // similar to GMap::initialize(map)
{
this._layer = layer;
this._icon = Franson.Graphics.Shape.createAlarmIcon(null, null, this._layer.getRoot());
// add blinking
this._blinkHandler = setInterval(
method(this, function()
{
// does Not use this.hide/show to not affect the true hide/show state
if (!this.isHidden() && !this._boundsHidden)
{
if (Franson.Graphics.isHidden(this._icon))
Franson.Graphics.show(this._icon);
else
Franson.Graphics.hide(this._icon);
}
}),
this._options.blinkInterval
);
if (this._options.title !== null)
Franson.Graphics.setTitle(this._icon, this._options.title);
this._clickHandler = this._icon.connect('onclick', this, function(e)
{
this._icon.moveToFront();
signal(this, 'onclick', this._latlng);
});
Franson.Graphics.setCursor(this._icon, Franson.Util.isIE() ? 'hand' : 'pointer'); // todo: do this stuff with CSS?
if (this._options.hide)
this.hide();
//this._layer.getRoot().add(this._icon);
},
getIcon: function()
{
return this._icon;
},
/**
* destructor
*/
destroy: function()
{
this.remove();
disconnectAll(this);
this._icon = null;
this._layer = null;
},
/**
* @method remove
* @protected
*/
remove: function()
{
if (this._blinkHandler)
{
clearInterval(this._blinkHandler);
this._blinkHandler = null;
}
if (this._icon)
{
if (this._clickHandler != null)
{
this._icon.disconnect(this._clickHandler);
this._clickHandler = null;
}
this._icon.removeShape();
signal(this, 'onremove');
}
},
/**
* @method setLatLng
* @param {LatLng} latlng
*/
setLatLng: function(latlng)
{
this._latlng = latlng;
if (this._layer !== null)
this.redraw(true);
},
/**
* @method isHidden
* @return {boolean}
*/
isHidden: function()
{
return this._hidden;
},
/**
* @method show
*/
show: function()
{
Franson.Graphics.show(this._icon);
this._hidden = false;
signal(this, 'onvisibilitychanged', true);
},
/**
* @method hide
*/
hide: function()
{
Franson.Graphics.hide(this._icon);
this._hidden = true;
signal(this, 'onvisibilitychanged', false);
},
/**
* @method redraw
* @param {boolean} [force=false]
* @protected
*/
redraw: function(force)
{
if (force && !this._hidden)
{
if (this._layer.getSurface()._getCullBounds().containsLatLng(this._latlng)) // todo: better culling
{
var pos = this._layer.getProjection().fromLatLngToDivPixel(this._latlng);
Franson.Graphics.setPosition(this._icon, pos);
this._boundsHidden = false;
Franson.Graphics.show(this._icon);
}
else
{
this._boundsHidden = true;
Franson.Graphics.hide(this._icon);
}
}
}
}; // Franson.Map.AlarmMarker.prototype
/**
* @event onclick
* @param {LatLng} latlng
*/
/**
* fired in remove()
* @event onremove
*/
/**
* fired in hide() and show()
* @event onvisibilitychanged
* @param {boolean} visible
*/
/**
* @event onclick
* @param {LatLng} latlng
*/