maps.event.trigger Resize()不起作用

时间:2013-10-28 09:28:59

标签: google-maps-api-3 resize

我正在谷歌地图上工作很长一段时间,我熟悉代码及其工作原理,但无法正确放置调整大小事件,导致我的地图在屏幕上渲染灰色瓷砖。 请告诉我确切需要放置resize事件的位置     这是我的代码:

bank.atmDetailsSuccess = function(response) {

    bank.locate = response;
    bank.getAtmStatus();

};


bank.getAtmStatus = function(results, status) {
    var status = bank.locate.Status[0].Value0;
    locate = bank.locate;
    var map;
    if (status == bank.constants.STATUS_ERROR) {
            var message = locate.Error[0].Value0;
            WL.simpledialog.show(message);
        } else if (status == bank.constants.STATUS_SESSION_EXPIRED) {
            WL.simpledialog.show("Session Expired!!");
        } else if (status == bank.constants.STATUS_SUCCESS) {
            map = bank.initializeAtm();
            google.maps.event.addDomListener(window, 'load', initializeAtm);
            google.maps.event.addDomListener(window, "resize", function() { 
                alert("In");
              var center = map.getCenter();
              google.maps.event.trigger(map, "resize");
              map.setCenter(center); 
              map.setZoom(10);
              });

    }
};


bank.initializeAtm = function(){
    locate = bank.locate;
    var firstlat = locate.Stmt[0].Value5;
    var firstlong= locate.Stmt[0].Value6;
    // var latlng = new google.maps.LatLng(latitude,longitude);

    var image = {
            //url: bank.constants.MARKER_PATH,
           url: 'images/720x720/pin.png',
            // This marker is 20 pixels wide by 32 pixels tall.
            size: new google.maps.Size(32, 40),
            // The origin for this image is 0,0.
            origin: new google.maps.Point(0,0),
            // The anchor for this image is the base of the flagpole at 0,32.
            anchor: new google.maps.Point(0, 32)
          };
    var myOptions = {
            zoom: 10,
            center:new google.maps.LatLng(firstlat, firstlong),
            mapTypeId: google.maps.MapTypeId.ROADMAP

          };

    map = new google.maps.Map($('#map-canvas')[0], myOptions);

    geocoder = new google.maps.Geocoder();
    bank.currentposition();
    $('#mapbranch').hide();
    $('#map-canvas').show();
    $('#atm').html("ATM near your current location");
    $('#results').html("");
    var directionsService = new google.maps.DirectionsService();
    MVC.local.directService = directionsService;
    directionsRenderer = new google.maps.DirectionsRenderer({
          suppressMarkers: true} );
    MVC.local.renderer = directionsRenderer;
    var n;
    for(n=0; n<locate.Stmt.length; n++)
    {
        var value = locate.Stmt[n];
        name = value.Value0,value.Value1;
        lat = value.Value5;
        lon = value.Value6; 
        bank.getDistanceFromLatLonInKm(12.919336, 77.502291,lat,lon);
        var myLatLng = new google.maps.LatLng(lat,lon);
        var marker = new google.maps.Marker({
            position: myLatLng,
            icon:image,
            map: map,
            title: name,
            zIndex: 1
        });

        bank.buildInfoWindow(marker,map,value[n]);
    }
    return map;
};

注意:这是完全正常工作的代码唯一的问题是当我手动调整broswer但在加载时不调整大小时渲染工作。请不要介意变量名。除了调整大小事件外,所有函数调用都很好。

0 个答案:

没有答案