/*
 * SVGOverlay - SVG Overlay for the Google Maps JavaScript API v3
 * https://github.com/ubilabs/google-maps-api-svg-overlay
 *
 * Version: 0.1
 * Author: Martin Kleppe <kleppe@ubilabs.net>
 */

function SVGOverlay(options) {

  options = options || {};

  this.div_ = document.createElement('div');
  this.div_.style.position = 'absolute';

  this.center_ = new google.maps.LatLng(0, 0);

  if (options.map){
    this.setMap(options.map);
  }

  if (options.content){
    this.setContent(options.content);
  }
}

SVGOverlay.prototype = new google.maps.OverlayView();

// Internal method. Triggered when `setMap` was called with an argument.
SVGOverlay.prototype.onAdd = function() {
  this.getPanes().overlayLayer.appendChild(this.div_);
};

// Set the new SVG content to display on a map.
SVGOverlay.prototype.setContent = function(content){

  this.div_.innerHTML = content;

  this.svg_ = this.div_.getElementsByTagName("svg")[0];
  this.svg_.setAttribute("width", "100%");
  this.svg_.setAttribute("height", "100%");

  this.content_ = content;
};

// Return the assigned SVG string.
SVGOverlay.prototype.getContent = function(){
  return this.content_;
};

// Return the surrounding DOM container.
SVGOverlay.prototype.getContainer = function(){
  return this.div_;
};

// Return the SVG element.
SVGOverlay.prototype.getSVG = function(){
  return this.svg_;
};

// Internal method. Called when the layer needs an update.
SVGOverlay.prototype.draw = function() {
  var projection = this.getProjection(),
    center = projection.fromLatLngToDivPixel(this.center_),
    width = projection.getWorldWidth(),
    offset = width / 2,
    style = this.div_.style;

  style.left = (center.x - offset) + 'px';
  style.top = (center.y - offset) + 'px';
  style.width = width + 'px';
  style.height = width + 'px';
};

// Internal method. Triggered when `setMap` was called with `null.
SVGOverlay.prototype.onRemove = function() {
  this.div_.parentNode.removeChild(this.div_);
};
@@ -933,95 +933,8 @@
 %5B0%5D;
-%0A  this.svg_.setAttribute(%22width%22, %22100%25%22);%0A  this.svg_.setAttribute(%22height%22, %22100%25%22);
 %0A%0A  
@@ -957,16 +957,32 @@
 content;
+%0A%0A  this.draw();
 %0A%7D;%0A%0A// 
@@ -1393,16 +1393,17 @@
 ion() %7B%0A
+%0A
   var pr
@@ -1433,21 +1433,69 @@
 ection()
-,%0A   
+;%0A%0A  if (!projection %7C%7C !this.svg_)%7B return; %7D%0A%0A  var
  center 
@@ -1637,16 +1637,102 @@
 style;%0A%0A
+  this.svg_.setAttribute(%22width%22, width);%0A  this.svg_.setAttribute(%22height%22, width);%0A%0A
   style.
@@ -1812,69 +1812,8 @@
 x';%0A
-  style.width = width + 'px';%0A  style.height = width + 'px';%0A
 %7D;%0A%0A

Move site attributes from DIV to SVG.