Change zoom with html tag event

前端 未结 3 1207
慢半拍i
慢半拍i 2021-01-16 22:48

i\'am a beginner in GMaps API and javascript, so this should be an easy question for you that are really experts. I have started to \"play around\" with the API, and wanted

3条回答
  •  感情败类
    2021-01-16 22:59

    Your problem is that the cambiarZOOM function and map variable are only accessible within the scope of the initialize function. To use a function on an onclick event, either it has to be available globally (this is discouraged), or you have to attach the function to the button while the function is in scope.

    If you give your button an id (id='zoomButton'), you can attach cambiarZOOM within the initialize function like so:

    ...
    function cambiarZOOM(nro) {
        var newZ = ez + nro;
        map.setZoom(newZ);
        }
    }
    
    var button = document.getElementById('zoomButton');
    button.onclick = function () { cambiarZOOM(5); };
    

提交回复
热议问题