/**
* BeNomad BeMap JavaScript API - MultiMarker
*/
/**
* @classdesc
* Base class for multimarker.
* @public
* @constructor
* @param {bemap.Coordinate} coordinates Array of bemap.Coordinate.
* @param {Object} options See below the available values.
* @param {bemap.Icon} options.icon Style of marker used by the renderer.
* @param {String} options.name Name of multimarker.
* @param {Object} options.properties custom object.
*/
bemap.MultiMarker = function(coordinates, options) {
var opts = options || {};
/**
* @type {Object}
* @protected
*/
this.native = null;
/**
* @type {Object}
* @protected
*/
this.map = null;
/**
* @type {Object}
* @protected
*/
this.layer = null;
/**
* @protected
*/
this.coords = coordinates ? coordinates : [];
/**
* @type {bemap.Icon}
* @protected
*/
this.icon = opts.icon ? opts.icon : null;
/**
* @type {String}
* @protected
*/
this.id = opts.id ? opts.id : null;
/**
* @type {Array}
* @protected
*/
this.events = [];
/**
* @type {Function}
* @protected
*/
this.callback = [];
/**
* @type {String}
* @protected
*/
this.name = opts.name ? opts.name : null;
/**
* @type {String}
* @protected
*/
this.textStyle = opts.textStyle ? opts.textStyle : null;
/**
* @type {Object}
* @protected
*/
this.properties = opts.properties ? opts.properties : null;
};
/**
* Add a coordinate.
* @public
* @param {bemap.Coordinate} coordinate bemap.Coordinate.
*/
bemap.MultiMarker.prototype.addCoordinate = function(coordinate) {
if (coordinate === null || !bemap.inheritsof(coordinate, bemap.Coordinate)) {
throw new bemap.Exception("coordinate is not an bemap.Coordinate object");
}
this.coords.push(coordinate);
return this;
};
/**
* Add a coordinate.
* @public
* @param {double} lon Longitude in degres deciaml (WGS84).
* @param {double} lat Latitude in degres deciaml (WGS84).
*/
bemap.MultiMarker.prototype.addLonLat = function(lon, lat) {
this.coords.push(new bemap.Coordinate(lon, lat));
return this;
};
/**
* Return an array with longitude and latitude in degres decimal (WGS94).
* @public
* @param {int} index Index of the coordinates in multimarker.
* @return {array} Return an array with longitude and latitude in degres decimal (WGS94).
*/
bemap.MultiMarker.prototype.getLonLatArray = function(index) {
return [this.coords[index].lon, this.coords[index].lat];
};
/**
* Return an array with latitude and longitude in degres decimal (WGS94).
* @public
* @param {int} index Index of coordinate in polyline.
* @return {array} Return an array with latitude and longitude in degres decimal (WGS94).
*/
bemap.MultiMarker.prototype.getLatLonArray = function(index) {
return this.coords[index].getLatLonArray();
};
/**
* Return an array with longitude and latitude in degres decimal (WGS94).
* Example: [ [lon, lat], [lon, lat], ... ]
* @public
* @return {array} Return an array with longitude and latitude in degres decimal (WGS94).
*/
bemap.MultiMarker.prototype.getLonLatArrays = function() {
var i = 0,
iLen = this.coords.length,
rets = [],
c;
for (; i < iLen; i++) {
c = this.coords[i];
rets.push([c.lon, c.lat]);
}
return rets;
};
/**
* Return the bemap.Icon that define the style of the multimarker.
* @public
* @return {bemap.Icon} Return the bemap.Icon that define the style of the multimarker.
*/
bemap.MultiMarker.prototype.getIcon = function() {
return this.icon;
};
/**
* Set the icon style of the multimarker.
* @public
* @param {bemap.Icon} icon the new icon style to set.
* @return {bemap.MultiMarker} Return this.
*/
bemap.MultiMarker.prototype.setIcon = function(icon) {
this.icon = icon;
return this;
};
/**
* Return the id of the multimarker.
* @public
* @return {String} Return the id of the multimarker.
*/
bemap.MultiMarker.prototype.getId = function() {
return this.id;
};
/**
* Define the id of multimarker
* @public
* @param {String} id the new id to set.
* @return {bemap.MultiMarker} this
*/
bemap.MultiMarker.prototype.setId = function(id) {
this.id = id;
return this;
};
/**
* Return the name of the multimarker.
* @public
* @return {String} Return the name of the multimarker.
*/
bemap.MultiMarker.prototype.getName = function() {
return this.name;
};
/**
* Define the name of multimarker.
* @public
* @param {String} name the new name to set.
* @return {bemap.MultiMarker} Return this.
*/
bemap.MultiMarker.prototype.setName = function(name) {
this.name = name;
return this;
};
/**
* Return the bemap.TextStyle that define the style of text.
* @public
* @return {bemap.TextStyle} Return the bemap.TextStyle that define the style of text.
*/
bemap.Marker.prototype.getTextStyle = function() {
return this.textStyle;
};
/**
* Set the text style of the multimarker.
* @public
* @param {bemap.TextStyle} icon the new text style to set.
* @return {bemap.MultiMarker} this
*/
bemap.Marker.prototype.setTextStyle = function(textStyle) {
this.textStyle = textStyle;
return this;
};
/**
* Define the coordinate.
* @public
* @param {int} index index of coordinates in multimarker.
* @param {bemap.Coordinate} coords new coordinates to set.
* @return {bemap.MultiMarker} Return this.
*/
bemap.MultiMarker.prototype.setCoordinate = function(index, coords) {
this.coords[index] = coords;
return this;
};
/**
* Define the coordinates.
* @public
* @param {bemap.Coordinate} coords new coordinates to set.
* @return {bemap.MultiMarker} Return this.
*/
bemap.MultiMarker.prototype.setCoordinates = function(coords) {
this.coords = coords;
return this;
};
/**
* Return the coordinates. See bemap.Coordinate.
* @public
* @return {bemap.Coordinate} Return the coordinates. See bemap.Coordinate.
*/
bemap.MultiMarker.prototype.getCoordinates = function() {
return this.coords;
};
/**
* Return the coordinate. See bemap.Coordinate.
* @public
* @param {int} index Index of coordinate in multimarker.
* @return {bemap.Coordinate} Return the coordinate. See bemap.Coordinate.
*/
bemap.MultiMarker.prototype.getCoordinate = function(index) {
return this.coords[index];
};
/**
* Remove the MultiMarker from the layer.
* @public
*/
bemap.MultiMarker.prototype.remove = function() {
if (this.map !== null && bemap.inheritsof(this.map, bemap.Map)) {
this.map.removeMultimarker(this);
}
return this;
};