简体   繁体   English

我第二次未载入地图

[英]Map doesn't load second time i click

I want to show my open street map on a Kendo UI window. 我想在Kendo UI窗口上显示打开的街道地图。 At First time on click the map shows, but after that it doesn't load. 首次点击时,地图会显示,但此后不会加载。 Even if I use google map the same result. 即使我使用谷歌地图相同的结果。 After searching on google, I have found that we can not initialize map more than one time. 在Google上搜索后,我发现我们不能多次初始化地图。 I have tried in different ways, but it doesn't work. 我已经尝试了不同的方法,但是没有用。 May be my approach was not good. 可能是我的方法不好。 Here 'is my code 这是我的代码

var data=' ';

function createMap() {
    data = $("#map").kendoMap({
        center: [23.7099, 90.4071],
        zoom: 15,
        layers: [
            {
                type: "tile",
                urlTemplate: "http://#= subdomain #.tile2.opencyclemap.org/transport/#= zoom #/#= x #/#= y #.png",
                subdomains: ["a", "b", "c"],
                attribution: "&copy; <a href='http://osm.org/copyright'>OpenStreetMap</a>."
            }
        ]
    });   
}

function showMap(e) {
    e.preventDefault();
    var wnd = $("#Map").data("kendoWindow");
    createMap();
    wnd.content(data);
    wnd.center().open();

}
@(Html.Kendo().Window().Name("Map")
  .Title("<span class='glyphicon glyphicon-map-marker'></span> Map of the road")
  .Visible(false)
  .Modal(true)
  .Draggable(true)
  .Width(635)
)

ShowMap fire on user click 用户点击即可触发ShowMap

当我第一次点击 当我单击多个

You have to redraw the map. 您必须重新绘制地图。 You can do this using the following code: 您可以使用以下代码执行此操作:

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

This will make the map refresh, fixing your issue. 这将使地图刷新,从而解决了您的问题。

请在函数末尾尝试

$("#map").data("kendoMap").resize(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript单击第二次不起作用 - JavaScript click doesn't work the second time 赛普拉斯:页面未在点击操作的第二个“it”块内加载 - Cypress: Page doesn't load within the second 'it' block for the click action 在点击事件中加载Google Map API,标记不会显示 - Load google map API on click event, the marker doesn't show 来自 mapbox 的 map 在选项卡单击时未完全加载 - map from mapbox doesn't load completely on tab click 为什么当我加载页面时我的 scrollBy 似乎不起作用,尽管它通过了低谷? 尽管第二次进入 hashchange 它工作 - Why my scrollBy doesn't seems to work when I load the page altough it passes trough? Altough the second time into the hashchange it works 单击功能不适用于第二次单击 - click function doesn't work for second click Jquery .animate()在第二次触发它时不起作用 - Jquery .animate() doesn't work second time i trigger it jQuery事件第二次调用时不起作用 - Jquery the event doesn't work the second time i call it 单击按钮加载jqGrid,但第二次失败 - load jqGrid on button click but it fails on second time 我的提交表单不是第一次发送,而是在单击提交按钮时第二次发送 - my submit form doesn't send in first time but send in second time when submit button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM