使用html标记事件更改缩放 [英] Change zoom with html tag event

查看:72
本文介绍了使用html标记事件更改缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GMaps API和JavaScript的初学者,所以对于你来说这应该是一个非常容易的问题,他们真的是专家。我已经开始玩API了,并且想尝试一件简单的事情,但我做不到!我已经四处寻找答案,但我没有得到答案。我创建了地图:

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 to try a simple thing, but I couldn't make it! I have look around for the answer, but I didn't get it. I have created the map:

<script type="text/javascript">
function initialize() {

    //CREATE THE MAP
    var mapOptions = {
      center: new google.maps.LatLng(-35.8190,-61.9010),
      zoom: 15,
      mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        mapOptions);

    //GET THE ZOOM
    var ez = map.getZoom();

    //TRYING TO CHANGE ZOOM FROM EXTERNAL LINK (DOESN'T WORK)
function cambiarZOOM(nro) {
    var newZ = ez + nro;
    map.setZoom(newZ);
    }

}
google.maps.event.addDomListener(window, 'load', initialize);

</script>

现在,HTML:

<html><body onload="initialize()">
<input type="button" onclick="cambiarZOOM(5)" value="CAMBIAR ZOOM">
</body></html>

好吧,现在我正在阅读关于google.maps.trigger();但我没有得到它。我会大量地回答你的答案!谢谢!

Well, now I'am reading about google.maps.trigger(); but I'm not getting it. I will apreciate a lot your answer!. THANK YOU!

推荐答案

您的cambiarZOOM函数对初始化函数是本地的(它由该函数包含)。它需要处于全局范围(在任何函数声明之外)才能用于HTML事件处理程序(如onclick)。

Your cambiarZOOM function is local to the initialize function (it is contained by that function). It needs to be in the global scope (outside of any function declaration) to be used in an HTML event handler (like "onclick"). Your "map" variable also needs to be global to be used in it.

<script type="text/javascript">
var map = null;
function initialize() {

    //CREATE THE MAP
    var mapOptions = {
      center: new google.maps.LatLng(-35.8190,-61.9010),
      zoom: 15,
      mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    map = new google.maps.Map(document.getElementById("map_canvas"),
        mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);

function cambiarZOOM(nro) {
    //GET THE ZOOM
    var ez = map.getZoom();
    var newZ = ez + nro;
    map.setZoom(newZ);
    }

</script>

这篇关于使用html标记事件更改缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆