bing地图获取栅格瓦片或图块
获取元数据
https://dev.virtualearth.net/REST/v1/Imagery/Metadata/{imagerySet}?key={BingMapsKey}
imagerySet:要为其请求元数据的影像类型。官方说中国支持以下两个值:RoadOnDemand、VibrantDark
BingMapsKey:key
https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?key=ApyshFI32*******************5
返回的影像元数据包括影像切片的 URL 和维度、缩放级别范围以及影像年份信息:
{"authenticationResultCode": "ValidCredentials","brandLogoUri": "http://dev.virtualearth.net/Branding/logo_powered_by.png","copyright": "Copyright © 2023 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets": [{"estimatedTotal": 1,"resources": [{"__type": "ImageryMetadata:http://schemas.microsoft.com/search/local/ws/rest/v1","imageHeight": 256,"imageUrl": "http://ecn.{subdomain}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=14009","imageUrlSubdomains": ["t0","t1","t2","t3"],"imageWidth": 256,"imageryProviders": null,"vintageEnd": null,"vintageStart": null,"zoomMax": 21,"zoomMin": 1}]}],"statusCode": 200,"statusDescription": "OK","traceId": "****"
}
其中元数据中有imageUrl
http://ecn.{subdomain}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=14009
subdomain:可以从imageUrlSubdomains中取,是构造图像切片 URL 时可以使用的一个或多个 URL 子域。
quadkey:为了优化瓦片索引和存储,每个瓦片的二维XY坐标会被组合成一维字串,即四叉树键值(quardtree keys,缩写为quadkeys)。每个quadkey唯一标识某一缩放级别下的一个瓦片,并且可以用作常见数据库 B-tree索引中的键。若要将瓦片坐标(XY)转换成quadkey,需要将Y和X坐标二进制值交错组合,并转换成4进制数字及对应的字符串(保留前导零)
瓦片坐标(XY)转换成quadkey
转换代码:https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
最终图块的请求地址:
http://ecn.t0.tiles.virtualearth.net/tiles/a12313.jpeg?g=14009
参考:https://learn.microsoft.com/en-us/bingmaps/rest-services/imagery/get-imagery-metadata