/**
* Add a bemap.Polyline to the layer
* @public
* @param {bemap.Polyline} bemap.Polyline.
* @param {object} options
* @return {bemap.OlMap}
*/
bemap.OlMap.prototype.addPolyline = function(polyline, options) {
if (polyline !== null && bemap.inheritsof(polyline, bemap.Polyline)) {
polyline.native = new ol.Feature({
geometry: new ol.geom.LineString(polyline.getLonLatArrays()),
});
if (polyline.map === null) {
polyline.map = this;
}
if (polyline.id !== undefined && polyline.id !== null) {
polyline.native.setId(polyline.id);
}
bemap.OlMap.prototype._addOwnToProperties(polyline);
polyline.native.getGeometry().transform(bemap.Map.PROJ.EPSG_WGS84, this.native.getView().getProjection());
if (polyline.style !== null) {
if (polyline.style.native === null) {
this.buildLineStyle(polyline.style);
}
polyline.native.setStyle(polyline.style.native);
}
var opts = options || {};
var l = null;
if (opts.layer !== null && bemap.inheritsof(opts.layer, bemap.VectorLayer)) {
l = opts.layer;
} else {
l = this.getLayerByName(bemap.Map.DEFAULT_LAYER.POLYLINE);
if (l === null) {
l = new bemap.VectorLayer({
name: bemap.Map.DEFAULT_LAYER.POLYLINE
});
this.addLayer(l);
}
}
if (polyline.layer === null) {
polyline.layer = l;
}
l.native.getSource().addFeature(polyline.native);
}
return this;
};
/**
* Remove a polyline from his layer.
* @public
* @param {bemap.Polyline} polyline the polyline object to remove.
*/
bemap.OlMap.prototype.removePolyline = function(polyline) {
if (polyline !== null && polyline.layer !== null && polyline.layer.native !== null && bemap.inheritsof(polyline, bemap.Polyline)) {
polyline.layer.native.getSource().removeFeature(polyline.native);
polyline.layer = null;
polyline.map = null;
}
return this;
};
/**
* Set the listner when an specified eventType occur on bemap.Polyline.
* @public
* @param {bemap.Polyline} polyline
* @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.Listener} this.
*/
bemap.OlMap.prototype.onPolyline = function(polyline, eventType, callback, options) {
return this._onFeature(polyline, eventType, callback, options, {
singleFeature: true
});
};
/**
* Set the listner when an specified eventType occur on all bemap.Polyline.
* @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.Listener} this.
*/
bemap.OlMap.prototype.onPolylines = function(eventType, callback, options) {
return this._onFeature(null, eventType, callback, options, {
polylines: true
});
};
/**
* Define the draggable capability for bemap.Polyline.
* @protected
* @param {bemap.Polyline} polyline bemap object.
* @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.OlMap.prototype.draggablePolyline = function(polyline, callback, options) {
return this._draggableFeature(polyline, callback, options, {
singleFeature: true
});
};
/**
* Define the draggable capability for all bemap.Polyline.
* @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.OlMap.prototype.draggablePolylines = function(callback, options) {
return this._draggableFeature(null, callback, options, {
polylines: true
});
};