谷歌地图缩放控件和标记消失

时间:2013-10-02 15:01:18

标签: javascript google-maps google-maps-api-3 chromium

我在谷歌地图上遇到两个非常奇怪的问题,这些问题似乎只发生在Chrome / Mac和Chrome / Windows上

  1. 如果单击位于科罗拉多州的第一个图钉并尝试平移地图,将鼠标向右移动,您会发现缩放控件将开始消失。我已经尝试用max-width修复它:无;所以这不是同一个错误。

  2. 如果单击位于Skopje的右侧标记,您会注意到标记将在缩放级别20消失

  3. 更新:如果我在Chrome上停用了硬件加速功能,那么这两个错误都会被修复,所以我认为这比谷歌地图更能解决这个问题。

    这是一个重现问题的{jsfiddle链接http://jsfiddle.net/sokarovski/rx74P/2/

    var posSkopje = new google.maps.LatLng(42.007652282715,21.372894287109034);
    var posColorado = new google.maps.LatLng(38.960487365723,-104.76946258545001);
    
    google.maps.visualRefresh = false;
    var map = new google.maps.Map(document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(0, 0),
        zoom: 3,
        mapTypeId: google.maps.MapTypeId.HYBRID,
        maxZoom: 20
    });
    
    var markerSkopje = new CustomMarker('img.svg');
    markerSkopje.setPosition(posSkopje);
    markerSkopje.setMap(map);
    
    var markerColorado = new CustomMarker('img.svg');
    markerColorado.setPosition(posColorado);
    markerColorado.setMap(map);
    
    var zoomOnClick = function(arg1) {
        map.setCenter(this.getPosition());
        map.setZoom(22);
    }
    
    google.maps.event.addListener(markerColorado, 'open', jQuery.proxy(zoomOnClick, markerColorado));
    google.maps.event.addListener(markerSkopje, 'open', jQuery.proxy(zoomOnClick, markerSkopje));
    

2 个答案:

答案 0 :(得分:1)

该帖子已经很老了,但问题仍然存在。 对于其他人,磕磕绊绊;你可以这样做:

从谷歌制作Markermanager.js的本地副本并进行修改 这一行(第107号行)

发件人:

me.maxZoom_ = opt_opts.maxZoom || 19;

me.maxZoom_ = opt_opts.maxZoom || 21;

答案 1 :(得分:0)

代码中的一些问题看看这个

//=========== > Custom Marker Class
function CustomMarker(opts) {
    this.location_ = null;
    this.div_ = null;
    this.inner_ = null;
    this.opts = {
        image:      null
    }
    this.constructor = function(image) {
        this.inner_ = document.createElement('img');
        jQuery(this.inner_).addClass('thumb').click(jQuery.proxy(this.onPinClick, this));
        if (image) this.setImage(image);
    }
    this.setPosition = function(ll) {
        this.location_  = ll;
    }
    this.getPosition = function() {
        return this.location_;
    }
    this.onAdd = function() {
        var div = document.createElement('div');
        div.style.border = "none";
        div.style.borderWidth = "0px";
        div.style.position = "absolute";
        div.appendChild(this.inner_);
        this.div_ = div;
        var panes = this.getPanes();
        panes.overlayMouseTarget.appendChild(div);
    }
    this.onPinClick = function(e) {
        google.maps.event.trigger(this, 'open');
    }
    this.draw = function() {
        var overlayProjection = this.getProjection();
        if (overlayProjection) {
            var pixPosition = overlayProjection.fromLatLngToDivPixel(this.location_);
            this.div_.style.left = (pixPosition.x ) + "px";
            this.div_.style.top = (pixPosition.y) + "px";
        }
    }
    this.setImage = function(image) {
        this.inner_.src = image;
    }
    this.constructor.apply(this, arguments);
}
CustomMarker.prototype = new google.maps.OverlayView();
//=========== > Initialization 
var posSkopje = new google.maps.LatLng(42.007652282715,21.372894287109034);
var posColorado = new google.maps.LatLng(38.960487365723,-104.76946258545001);

var map = new google.maps.Map(document.getElementById("map_canvas"), {
    center: new google.maps.LatLng(0, 0),
    zoom: 3,
    mapTypeId: google.maps.ROADMAP,
    maxZoom: 20
});

var markerSkopje = new CustomMarker('http://www.gnhl.ca/images/pushed-pin-hi.png');
markerSkopje.setPosition(posSkopje);
markerSkopje.setMap(map);

var zoomOnClick = function(arg1) {
    map.setCenter(this.getPosition());
    map.setZoom(20);
}

google.maps.event.addListener(markerSkopje, 'open', jQuery.proxy(zoomOnClick, markerSkopje));