You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Atlas Maps天气叠加层无法正常加载问题求助

Azure Maps天气叠加层加载失败的解决方案

核心问题定位

你的代码中天气瓦片URL写死了固定的zoom=2&x=2&y=1参数,这会导致TileLayer只能加载单个固定位置的瓦片,无法根据地图的缩放和视野动态加载对应区域的天气瓦片,这是加载失败的主要原因。

修正后的代码

将天气瓦片URL中的固定参数替换为TileLayer支持的动态占位符{z}(缩放级别)、{x}、{y},同时确保订阅密钥正确配置:

<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" type="text/css" />

<div>
    <div id="map" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
</div>

@section Scripts{
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
<script src="https://atlas.microsoft.com/sdk/javascript/service/2/atlas-service.min.js"></script>

<script>
    $(function() {
        var map, tileLayer;

        // 替换为动态占位符的天气瓦片URL
        var weatherTileUrl = 'https://atlas.microsoft.com/map/tile?api-version=2022-08-01&tilesetId=microsoft.weather.radar.main&zoom={z}&x={x}&y={y}'; 

        map = new atlas.Map('map', {
            style: 'satellite_road_labels',
            center: [-99.47, 40.75],
            zoom: 2,
            language: 'en-US',
            view: 'Auto',
            authOptions: {
                authType: 'subscriptionKey',
                subscriptionKey: '你的Azure Maps订阅密钥' // 替换为实际密钥
            }
        });

        map.events.add('ready', function () {
            map.controls.add(new atlas.control.StyleControl({
                mapStyles: 'all'
            }), {
                position: 'top-right'
            });

            updateTileLayer();
        });

        function updateTileLayer() {
            if (!tileLayer) {
                tileLayer = new atlas.layer.TileLayer({
                    tileUrl: weatherTileUrl,
                    opacity: 0.9,
                    tileSize: 256
                });

                map.layers.add(tileLayer, 'labels');
            } else {
                tileLayer.setOptions({
                    tileUrl: weatherTileUrl 
                });
            }
        }
    })
</script>
}

额外排查步骤

如果修正后仍无法加载,检查以下几点:

  • 确认你的Azure Maps订阅密钥已启用天气服务权限,在Azure门户的Maps账户中,确保天气相关的API服务未被禁用。
  • 验证瓦片集ID是否正确:microsoft.weather.radar.main是雷达瓦片,若要加载其他天气图层,需使用对应ID(如microsoft.weather.temperature.main等)。
  • 检查图层添加顺序:map.layers.add(tileLayer, 'labels')确保天气瓦片叠加在地图标签下方,若顺序错误可能导致瓦片被遮挡。
  • 确认SDK版本兼容性:当前使用的mapcontrol v3与service v2版本兼容,无需调整。

内容的提问来源于stack exchange,提问作者cherrys26

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 22:02:12