/*
  this is just handy sometimes:
  
  var line = new BpPolyline(same args);
  var arr  = line.asGLatLngs()
  var arr  = line.asObjects(); // an array of { lat: X, lng: Y }
  var bool = line.isMapped()
*/

(function(){

function BpPolyline() {
  GPolyline.apply(this, arguments);
}

BpPolyline.prototype = new GPolyline([new GLatLng(0,0),new GLatLng(0,0)]);

BpPolyline.prototype.asObjects = function(){
  var a = [];
  
  for (var i = 0; i < this.getVertexCount(); i++) {
    var ll = this.getVertex(i);
    a.push({
      lat: ll.lat(),
      lng: ll.lng()
    });
  }
  
  return a;
};

BpPolyline.prototype.asGLatLngs = function(){
  var a = [];
  
  for (var i = 0; i < this.getVertexCount(); i++)
    a.push(this.getVertex(i));
  
  return a;
};

BpPolyline.prototype.initialize = function(map){
  GPolyline.prototype.initialize.call(this, map);
  this._map = map;
};

BpPolyline.prototype.remove = function(){
  GPolyline.prototype.remove.call(this);
  delete this._map;
};

BpPolyline.prototype.isMapped = function(){
  return this._map ? true : false;
};

// can't/doesn't handle options
BpPolyline.cast = function(line){
  var points = this.prototype.asGLatLngs.call(line);
  return new this(points, line.color, line.weight, line.opacity);
};
  
BpPolyline.fromBounds = function(bounds, color, weight, opacity, opts){
  var ne = bounds.getNorthEast();
  var sw = bounds.getSouthWest();
  var nw = new GLatLng(ne.lat(), sw.lng());
  var se = new GLatLng(sw.lat(), ne.lng());

  return new this([ne, nw, sw, se, ne], color, weight, opacity, opts);
};

window.BpPolyline = BpPolyline;
  
})();

