【问题标题】:Change zoom on map update (JS)在地图更新时更改缩放 (JS)
【发布时间】:2018-05-17 17:06:26
【问题描述】:

我有地图更新功能

这里是代码

function update() {

            ajaxLoader.removeClass('mc-warning-noConnection');
            ajaxLoader.show();

            $.ajax({
                url: '/Mobile/Map/GetMapData',
                type: 'GET',
                timeout: 10000,
                success: function (data) {
                    if (data.redirectUrl) window.location.replace(data.redirectUrl);
                    else if (data.error) alert(data.error);
                    else {
                        setTimeout(function () { ajaxLoader.hide() }, 300);
                        data.forEach(function (vehicleData) {
                            mapWrapper.getEntity(vehicleData.Imei).update(vehicleData);
                        });
                    }
                },
                error: function () {
                    ajaxLoader.addClass('mc-warning-noConnection');
                },
                complete: function () {
                    timeout = setTimeout(update, 10000);
                }
            });
        }

需要通过控制器从数据库中获取值

这是控制器代码。

 public async Task<ActionResult> GetMapData()
    {
        var mapData = await repository.GetVehicleMapData(15, null).ConfigureAwait(false);
        Session["PreviousMapQueryTime"] = DateTime.Now.AddMinutes(-5); //5 minutes offset because tables aren't always up-to-date

        return CreateJsonDataResult(mapData);
    }

然后将它们传递给映射和更新标记。

这是 MapWrapper 脚本

MapWrapper

标记一切正常,但更新时缩放不起作用。

当我重新加载地图时一切正常。但不是在不重新加载整个页面的情况下更新。

问题出在哪里以及如何解决?

【问题讨论】:

    标签: javascript c# asp.net-mvc google-maps google-maps-api-3


    【解决方案1】:

    你应该在更新实体后使用mapWrapper.zoomToLayer(layerID)函数,其中Layerid是你的实体放置的层的ID。

    success: function (data) {
                        if (data.redirectUrl) window.location.replace(data.redirectUrl);
                        else if (data.error) alert(data.error);
                        else {
                            setTimeout(function () { ajaxLoader.hide() }, 300);
                            data.forEach(function (vehicleData) {
                                mapWrapper.getEntity(vehicleData.Imei).update(vehicleData);
                            });
                              mapWrapper.zoomToLayer(layerID);
                        }
                    },
    

    【讨论】:

    • 是的,我发现我的缩放问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2014-07-22
    相关资源
    最近更新 更多