2011-09-12 177 views
2

我在谷歌地圖中的自定義覆蓋圖標標記有問題。 它在所有縮放級別都能正常工作,但在最大變焦時消失。在演示中,只有下面的圖標消失,但上面的圖標沒問題。谷歌地圖覆蓋圖在某些縮放級別消失

演示:http://random.hypervolume.com/map_bug.html

嘗試放大下標記時,一個在34個街道。在最大縮放級別消失。

這裏是源:

var map; 

    function init() { 
    var opts = { zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP }; 
    map = new google.maps.Map(document.getElementById('mapcanvas'), opts); 
    map.setCenter(new google.maps.LatLng(40.761231, -73.9839609)); 

    new MyMarker(new google.maps.LatLng(40.761231, -73.9839609), map, "A"); 
    new MyMarker(new google.maps.LatLng(40.75013, -73.987974), map, "B"); 
    } 

    var ICON_WIDTH = 52; 
    var ICON_HEIGHT = 52; 
    var ICON_URL = "http://random.hypervolume.com/m1.png"; 

    function MyMarker(position, map, id) { 
    this.id = id; 
    this.position = position; 
    this.map = map; 
    this.setMap(map); 
    } 

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

    MyMarker.prototype.onAdd = function() { 
    var div = this.div = document.createElement('DIV'); 
    div.id = this.id; 

    div.style.width = ICON_WIDTH; 
    div.style.height = ICON_HEIGHT; 
    div.style.position = 'absolute'; 

    var image = new Image(); 
    image.src = ICON_URL; 
    div.appendChild(image); 

    this.getPanes().overlayMouseTarget.appendChild(div); 
    }; 


    MyMarker.prototype.draw = function() { 
    var pos = this.getProjection().fromLatLngToDivPixel(this.position); 
    pos.x -= ICON_WIDTH/2; 
    pos.y -= ICON_HEIGHT/2; 
    this.div.style.top = pos.y + 'px'; 
    this.div.style.left = pos.x + 'px'; 
    }; 

回答