/**
* BeNomad BeMap JavaScript API - Circle class
*/
/**
* @classdesc
* Base class for Circle.
* @public
* @constructor
* @param {bemap.Coordinate} center Array of bemap.Coordinate.
* @param {int} radius Radius of circle.
* @param {Object} options See below the available values.
* @param {bemap.LineStyle} options.style Style of poyline used by the renderer.
* @param {String} options.name Name of circle.
* @param {Object} options.properties custom object.
*/
bemap.Circle = function(center, radius, options) {
var opts = options || {};
/**
* @type {Object}
* @protected
*/
this.native = null;
/**
* @type {Object}
* @protected
*/
this.map = null;
/**
* @type {Object}
* @protected
*/
this.layer = null;
/**
* @type {bemap.Coordinate}
* @protected
*/
this.coordinate = center ? center : new bemap.Coordinate();
/**
* @type {int}
* @protected
*/
this.radius = radius ? radius : null;
/**
* @type {
bemap.LineStyle
}
* @protected
*/
this.style = opts.style ? opts.style : null;
/**
* @type {String}
* @protected
*/
this.id = opts.id ? opts.id : null;
/**
* @type {String}
* @protected
*/
this.name = opts.name ? opts.name : null;
/**
* @type {Array}
* @protected
*/
this.events = [];
/**
* @type {Function}
* @protected
*/
this.callback = [];
/**
* @type {Object}
* @protected
*/
this.properties = opts.properties ? opts.properties : null;
};
/**
* Return the id of the circle.
* @public
* @return {String} Return the id of the circle.
*/
bemap.Circle.prototype.getId = function() {
return this.id;
};
/**
* Define the id of circle
* @public
* @param {String} id the new id to set.
* @return {bemap.Circle} this
*/
bemap.Circle.prototype.setId = function(id) {
this.id = id;
return this;
};
/**
* Return the name of the circle.
* @public
* @return {String} Return the name of the circle.
*/
bemap.Circle.prototype.getName = function() {
return this.name;
};
/**
* Define the name of circle
* @public
* @param {String} name the new name to set.
* @return {bemap.Circle} this
*/
bemap.Circle.prototype.setName = function(name) {
this.name = name;
return this;
};
/**
* Return the radius of the circle.
* @public
* @return {int} return radius of the circle.
*/
bemap.Circle.prototype.getRadius = function() {
return this.radius;
};
/**
* Return the radius of the circle.
* @public
* @return {int} return radius of the circle.
*/
bemap.Circle.prototype.setRadius = function(radius) {
this.radius = radius;
if (this.native && this.map) {
this.map.setRadiusCircle(this);
}
return this;
};
/**
* Return the coordinate. See bemap.Coordinate.
* @public
* @return {bemap.Coordinate} Return the coordinate. See bemap.Coordinate.
*/
bemap.Circle.prototype.getCenter = function() {
if (this.map && this.native) {
this.map.updateCircleCenter(this);
}
return this.coordinate;
};
/**
* Return the coordinate. See bemap.Coordinate.
* @public
* @return {bemap.Coordinate} Return the coordinate. See bemap.Coordinate.
*/
bemap.Circle.prototype.getCoordinate = function() {
return this.coordinate;
};
/**
* Return the style of the circle.
* @public
* @return {bemap.LineStyle} Return the style of the circle.
*/
bemap.Circle.prototype.getStyle = function() {
return this.style;
};
/** Set the center of the circle.
* @public
* @param {bemap.Coordinate} center the new coordinates to set.
* @return {bemap.Marker} this
*/
bemap.Circle.prototype.setCenter = function(coordinate) {
this.coordinate = coordinate;
if (this.native && this.map) {
this.map.setCoordinateCircle(this);
}
return this;
};
/**
* Remove the Circle from the layer.
* @public
* @return {bemap.Circle} this
*/
bemap.Circle.prototype.remove = function() {
if (this.map !== null && bemap.inheritsof(this.map, bemap.Map)) {
this.map.removeCircle(this);
}
return this;
};
/**
* Set the listner when an specified eventType occur on bemap.Circle.
* @public
* @param {bemap.Map.EventType} eventType Event type.
* @param {function} callback Function will be called when the specified eventType is occur.
* @param {object} options options.
* @return {bemap.Circle} this.
*/
bemap.Circle.prototype.on = function(eventType, callback, options) {
if (this.map !== null && bemap.inheritsof(this.map, bemap.Map)) {
this.map.onCircle(this, eventType, callback, options);
}
return this;
};
/**
* Define the draggable capability for bemap.Circle.
* @protected
* @param {function} callback Function will be called when the specified eventType is occur.
* @param {object} options Options.
* @param {bemap.Layer} options.layerFilter set the bemap layer used as filter.
* @return {bemap.Listener} bemap.listener.
*/
bemap.Circle.prototype.draggable = function(callback, options) {
if (this.map !== null && bemap.inheritsof(this.map, bemap.Map)) {
return this.map.draggableCircle(this, callback, options);
}
return new bemap.listener();
};