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

如何使用Azure Maps Web SDK访问Azure Maps数据注册表中的数据

使用Azure Maps Web SDK访问数据注册表中存储的Blob数据

目前Azure Maps Web SDK并未提供直接访问数据注册表的内置方法,但可以通过以下步骤实现:

实现步骤

  1. 通过数据注册表API获取Blob的授权SAS URL
    调用数据注册表的SAS生成接口,获取目标文件的临时授权访问链接。请求格式如下:

    GET https://{region}.atlas.microsoft.com/dataRegistries/{udid}/sas?api-version=2023-06-01
    

    请求头需携带Azure Maps订阅密钥(或AAD令牌):

    # 使用AAD令牌
    Authorization: Bearer {AAD_TOKEN}
    # 或使用订阅密钥
    Ocp-Apim-Subscription-Key: {YOUR_SUBSCRIPTION_KEY}
    

    接口返回的响应中会包含sasUri字段,这是带权限的Blob访问链接。

  2. 用Web SDK加载SAS URL指向的地理数据
    拿到授权的SAS URL后,即可使用Web SDK的DataSource.importDataFromUrl方法加载数据,此时请求会被正常授权,无需担心CORS限制。

完整代码示例

// 初始化Azure Maps地图
const map = new atlas.Map('map', {
    center: [-122.33, 47.6],
    zoom: 12,
    authOptions: {
        authType: 'subscriptionKey',
        subscriptionKey: '{YOUR_SUBSCRIPTION_KEY}'
    }
});

map.events.add('ready', async () => {
    const region = 'eu'; // 替换为你的Azure Maps区域
    const udid = '{YOUR_DATA_REGISTRY_UDID}';
    const apiVersion = '2023-06-01';
    const subscriptionKey = '{YOUR_SUBSCRIPTION_KEY}';

    // 1. 获取SAS URL
    const sasResponse = await fetch(`https://${region}.atlas.microsoft.com/dataRegistries/${udid}/sas?api-version=${apiVersion}`, {
        headers: {
            'Ocp-Apim-Subscription-Key': subscriptionKey
        }
    });

    const sasData = await sasResponse.json();
    const sasUrl = sasData.sasUri;

    if (!sasUrl) {
        console.error('Failed to retrieve SAS URL');
        return;
    }

    // 2. 加载数据到地图数据源
    const datasource = new atlas.source.DataSource();
    map.sources.add(datasource);

    await datasource.importDataFromUrl(sasUrl);

    // 添加图层渲染数据
    map.layers.add(new atlas.layer.SymbolLayer(datasource));
});

注意事项

  • 确保数据注册表已正确关联Blob存储,且文件已成功注册(你之前验证的列出、分析文件操作正常即可)
  • SAS URL具有时效性,若需要长期访问,可在请求SAS接口时通过durationInSeconds参数设置有效期(默认3600秒)
  • 若仍遇到CORS问题,需确保Blob存储的CORS规则允许你的网站域名发起请求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 05:32:55