Пользовательский маркер API Карт Google версии 3 не отображается - PullRequest
3 голосов
/ 27 января 2011

Я сейчас использую примеры ванильного кода и даже не могу заставить это работать!

Я вызываю маркер создания, используя ...

overlay = new CustomMarker(new google.maps.LatLng(subitem[2], subitem[3]), mapView);
overlay.setMap(mapView);

А код для CustomMarker -

function CustomMarker(latlng,  map) {
google.maps.OverlayView.call(this);

this.latlng_ = latlng;

// Once the LatLng and text are set, add the overlay to the map.  This will
// trigger a call to panes_changed which should in turn call draw.
this.set_map(map);


}


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

  CustomMarker.prototype.draw = function() {
var me = this;

// Check if the div has been created.
var div = this.div_;
if (!div) {
  // Create a overlay text DIV
  div = this.div_ = document.createElement('DIV');
  // Create the DIV representing our CustomMarker
  div.style.border = "0px solid none";
  div.style.position = "absolute";
  div.style.paddingLeft = "0px";
  div.style.cursor = 'pointer';

  var img = document.createElement("img");
  img.src = "../../images/tile_images/ship_black_0.png";
  div.appendChild(img);
  google.maps.event.addDomListener(div, "click", function(event) {
    google.maps.event.trigger(me, "click");
  });

  // Then add the overlay to the DOM
  var panes = this.get_panes();
  panes.overlayImage.appendChild(div);
}

// Position the overlay 
var point = this.get_projection().fromLatLngToDivPixel(this.latlng_);
if (point) {
  div.style.left = point.x + 'px';
  div.style.top = point.y + 'px';
}


 };

  CustomMarker.prototype.remove = function() {
    // Check if the overlay was on the map and needs to be removed.
    if (this.div_) {
      this.div_.parentNode.removeChild(this.div_);
      this.div_ = null;
    }
  };

  CustomMarker.prototype.get_position = function() {
   return this.latlng_;
  };

Создание стандартного маркера с использованием того же LatLng и mapView работает отлично.

Я получаю ошибку

TypeError: Результат выражения 'this.set_map' [undefined] не является функция.

1 Ответ

3 голосов
/ 28 января 2011

Похоже, что

this.set_map(map); 

устарела и теперь

this.setMap(map);
...