调整高度在谷歌地图 [英] Resize height in Google Maps

查看:174
本文介绍了调整高度在谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从谷歌地图API的例子code调整大小的高度地图

I get an example code from Google Map API for resize height "map"

 var recalcHeight = function() {
    $("#map").height($(window).height() - 100); //Example
    map && google.maps.event.trigger(map, 'resize'); //(*) Don't understand this line
}; 
$(window).resize(recalcHeight);
recalcHeight();

好吧,在我的PHP文件,我有一个div标签:
1.我不明白这上面(*)行。

Ok, in my php file, I have a div tag: 1. I don't understand this (*) line above.

推荐答案

我真的不知道你的问题是什么样的,因为你没有用的的JavaScript 的标签,但我认为如果你明白这一点,你会问什么 google.maps.event.trigger(X,Y)一样。另外,我不知道这是什么在你的PHP文件,你的 DIV 标签来。

I don't really know what you question is about because you didn't tag it with Javascript, but I think if you knew this, you would have asked what google.maps.event.trigger(X, Y) did. Plus, I don't know what this has to do with your div tags in your PHP files.

这很简单,找出触发在这里所做的:

It's simple to find out what trigger does here:

在触发特定的事件。 eventName的之后的所有参数都作为参数传递给听众通过。

Triggers the given event. All arguments after eventName are passed as arguments to the listeners.

(从谷歌地图API ,我发现它在任何时候)

(From the Google Maps API, I found it in no time)

如果你的问题是关于整个&放大器;&安培; 结构,我会解释给你听:

If your question is about this whole && construct, I'll explain it to you:

map && google.maps.event.trigger(map, 'resize');

&放大器;&安培; 是一个逻辑短cirquit评价这意味着:

The && is a logical AND with short-cirquit evaluation which means:


  • 如果它的第一个参数是的真正的,它计算第二个参数。 IFF 这是的真正的也一样,它返回的真正

  • If its first argument is true, it evaluates the second argument. Iff this is true too, it returns true.

如果它的第一个参数是的的,整个前pression不能成为的真正的,所以它的甚至不评价第二个参数并返回的马上。

If its first argument is false, the whole expression can't become true, so it doesn't even evaluate its second argument and returns false immediately.

此机制可以是(AB)用于改变流量控制。如果条件(&放大器;&安培; 的第一个参数)是假的,第二个参数没有得到评估,因此这是一样的。

This mechanism can be (ab)used to change flow control. If the condition (&&'s first argument) is false, the second argument doesn't get evaluated, so it's the same as

if (map) {
    google.maps.event.trigger(map, 'resize');
}

我不知道是怎么地图初始化,但也许是事件触发仅添加如果有一个地图元素。

I don't know how map was initialized, but maybe the event trigger is added only if there's a map element.

这篇关于调整高度在谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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