当链接点击事件时,谷歌地图InfoWindow不打开地图窗口



地图视图调试信息窗口未打开

但是我没有得到什么问题与我的代码信息窗口没有打开。

我的代码

 columns.Bound(e => e.AssetNumber).Template(@<text></text>).ClientTemplate("<a style="cursor: pointer;" onclick="showmapbyassetid('#:AssetId#','#:AssetNumber#');">#=AssetNumber#</a>").Title("Asset Number");

当我点击链接showmapbyassetid方法调用一切工作正常时,我调试,但Infowindow没有打开地图视图

这是我的javascript方法

  function showmapbyassetid(_assetid, _assetnumber) {
            var IsAuthorized = '@AssetTrackingSystem.Utils.Authorize.IsAuthorized((System.Data.DataTable)Session["Priviliges"], new Guid(Session["CurrentCompanyId"].ToString()), 3, 2)';
            if (IsAuthorized.toLowerCase() == 'false') {
                alert("You are not authorized to view Asset Details");
                return false;
            }
            //debugger;
            assetid = _assetid;
            if (markerarray != null) {
                //debugger;
                var cnt = null;
                var lat = null, long = null;
                var mycenter = null;
                var got = false;
                $.each(markerarray, function (i, item) {
                    // //debugger;
                    if (item.title.toLowerCase() == _assetnumber.toLowerCase()) {
                        mycenter = new google.maps.LatLng(item.position.B, item.position.k);
                        $.each(infowindowcontent, function (j, info) {
                            //debugger;
                            var iiii = allinfowindows;
                            if (info.indexOf("AssetId=" + _assetid) != -1) {
                                cnt = info;
                                got = true;
                            }
                            if (got)
                                return false;
                        });
                        //debugger;
                        SetDeffColor();
                        closeAllInfoWindows();
                        item.setIcon('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png')
                        var infowindow = new google.maps.InfoWindow({
                            content: cnt
                        });
                        allinfowindows.push(infowindow);
                        map.setCenter(mycenter);
                        infowindow.open(map, item);
                    }
                    if (got)
                        return false;
                });
            }
        }

我相信你的代码中缺少了一些东西,我的例子是在angular中完成的,但显示了创建标记,信息窗口和侦听器的过程:

var infoWindow = new google.maps.InfoWindow();
var createMarker = function (info){
    var marker = new google.maps.Marker({
        map: $scope.map,
        position: new google.maps.LatLng(info.latitude, info.longitude),
        title: info.city
    });
    google.maps.event.addListener(marker, 'click', function(){
        var contentString  = '<table class="popup">'+
            '<tbody>'+
            // infowindow content
            '</tbody>'+
          '</table>';
        infoWindow.setContent(contentString);
        infoWindow.open($scope.map, marker);
    });
    $scope.markers.push(marker);
}  
for (i = 0; i < hotels.length; i++){
    createMarker(hotels[i]);
}
$scope.openInfoWindow = function(e, selectedMarker){
    e.preventDefault();
    google.maps.event.trigger(selectedMarker, 'click');
}

希望这对你有帮助。

你可以在这里查看的工作代码

最新更新