仅显示部分地图API V3问题
我想在一页上使用两个(或更多)地图。(使用 telerik Grid)
如您所见,如果我尝试打开一行的“详细信息”(可能是第一行、第二行或最后一行)地图将正确显示。如果尝试展开另一行的详细信息,地图将显示无效。我无法理解我做错了什么?
function onTabSelect(e) {
//...
if (node.childNodes.length == 0) {// If Coordinates tab not contain map
map = document.createElement('DIV');
map.setAttribute('id', selectedGeoObject.Id + "_gmap"); //Generates Id for div container
map.setAttribute('style', 'width:400px; height:278px; margin : 0px; padding : 0px;');
node.appendChild(map);
initMap(map);
}
}
function initMap(gMapContainer) {
var myLatlng = new google.maps.LatLng(51.0, 9.0);
var myOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//width:400px; height:278px;
var gMap = new google.maps.Map(gMapContainer, myOptions);
// Can not solve the problem.
//google.maps.event.trigger(gMap, 'resize');
//gMap.setCenter(myLatlng);
return gMap;
}
如果我尝试调整浏览器窗口的大小,两个地图都会正确显示(我已经在 Firefox、Opera、Chrome 中尝试过此操作)。你能帮我解决这个奇怪的错误吗?
I want to use two(or more) maps on one page.(using telerik Grid)
As you see, If I will try to open "details" for one row(It could be first, second, or last row) map will be displayed correctly. If will try to expand details for another row, map will be displayed not valid. I cannot understand what have I done wrong?
function onTabSelect(e) {
//...
if (node.childNodes.length == 0) {// If Coordinates tab not contain map
map = document.createElement('DIV');
map.setAttribute('id', selectedGeoObject.Id + "_gmap"); //Generates Id for div container
map.setAttribute('style', 'width:400px; height:278px; margin : 0px; padding : 0px;');
node.appendChild(map);
initMap(map);
}
}
function initMap(gMapContainer) {
var myLatlng = new google.maps.LatLng(51.0, 9.0);
var myOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//width:400px; height:278px;
var gMap = new google.maps.Map(gMapContainer, myOptions);
// Can not solve the problem.
//google.maps.event.trigger(gMap, 'resize');
//gMap.setCenter(myLatlng);
return gMap;
}
If I will try to resize my browser window, both maps will be displayed correctly(I've tried this in Firefox, Opera, Chrome). Could you help me with this strange bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在窗口调整大小时调用此方法:
像这样:(请注意,您需要通过 document.getElementByID 等获取 gMap 句柄)
Call this on the window resize:
Like So: ( Note you'll need the gMap handle via document.getElementByID etc )
您可以添加此代码:
You can add this code:
问题是,当您尝试使用 style.visibility ='hidden' 初始化 DIV 标记内的 Google 地图
来解决此问题时,您必须在可见 DIV 内声明 map_canvas div,例如:
现在,如果您使用 jQuery ,在 $(function()) 中,您应该将“MapWindow”可见性设置为隐藏(如果您希望 GMap 开始隐藏)。
最后,当您想要显示 DIV(或弹出窗口,例如)时,在显示之前,您必须将 DIV 可见性设置为“visible”
;)
The problem is when you try to initialize a Google Map inside a DIV tag with style.visibility ='hidden'
to solve this, you have to declare the map_canvas div inside a visible DIV, for example:
now, if you're using jQuery, in $(function()) you should set 'MapWindow' visibility in hidden (if you want that GMap starts hidden).
Finally, when you wan to show de DIV (or popup window, for example), before show it, you have to set the DIV visibility in 'visible'
;)