Google地图无法加载。灰色的盒子。然后在一段时间后加载

时间:2014-05-20 18:59:48

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

工作正常,我不知道发生了什么。

我使用自定义knockout.js绑定加载地图。它显示了一个交互式的灰色区域,就像地图在那里一样,但没有地图。如果我让它坐下,最终会抛出此错误"无法执行' drawImage' on' CanvasRenderingContext2D':未找到与提供的签名匹配的功能。"在Chrome中,或者在Firefox中的这个:" CanvasRenderingContext2D.drawImage的参数1无法转换为以下任意内容:HTMLImageElement,HTMLCanvasElement,HTMLVideoElement"。

之后地图正常加载。

有什么想法吗?

这是绑定:

        ko.bindingHandlers.iMap = {
        update: function (element, valueAccessor) {
            var value = valueAccessor()();
            var lat_lon = new google.maps.LatLng(value.lat(),value.lon());

            if(!value.map){
                var styles = [
                   {
                     featureType: "poi",
                     stylers: [
                      { visibility: "off" }
                     ]   
                    },
                   {
                     featureType: "transit",
                     stylers: [
                      { visibility: "off" }
                     ]   
                    }                        
                ];

                var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});                    
                var mapOptions = {
                    zoom: 10,
                    center: lat_lon,
                    mapTypeControlOptions: {
                      mapTypeIds: []
                    },
                };   
                value.map = new google.maps.Map(element,mapOptions);
                value.map.mapTypes.set('map_style', styledMap);
                if(value.legit_data){
                    value.setMarker();
                }
                value.map.setMapTypeId('map_style');                    
                google.maps.event.addListener(value.map, 'click', function(event){ value.clickEvent(event) });     
            }

            value.map.setCenter(lat_lon);
        }
    };   

这是初始化程序:

        function loadScript() {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://maps.googleapis.com/maps/api/js?key=API_KEY_WOULD_BE_HERE&sensor=false&' +
        'callback=initialize';
        document.body.appendChild(script);
    }    

    window.onload = loadScript;  

    function initialize() {
        viewmodel = new viewModel();     
        ko.applyBindings(viewmodel); 
    }  

管理以获取错误:

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided. VM2835:37
(anonymous function) VM2835:37
RP.(anonymous function).A.RP.(anonymous function).F VM2835:37
IP VM2835:31
a.j VM2835:31
wf.(anonymous function).ka main.js:24
b.j VM2835:31
wf.(anonymous function).ka main.js:24
PP.(anonymous function).md VM2835:36
(anonymous function) VM2835:35
(anonymous function) main.js:25
(anonymous function) VM2835:35
(anonymous function) VM2835:25
Wv.(anonymous function).H VM2832:90
(anonymous function) main.js:11
(anonymous function) VM2832:90
(anonymous function) VM2832:89
(anonymous function) VM2832:90
(anonymous function) main.js:12

0 个答案:

没有答案