百度地图的瓦块切片规则与大多数地图不同,其中心点位于地理坐标的0,0点,多数地图的切片是以地图左上角为瓦块切片的起点。Cesium中默认的切片地图(UrlTemplateImageryProvider)包括经纬度模式和投影(墨卡托)模式都是以左上角切片为基准。所以当我们加载百度地图瓦块地图时,需要自定义地图影像地图类。

BaiduImageryProvider = function(options) {this._errorEvent = new Cesium.Event();this._tileWidth = 256;this._tileHeight = 256;this._maximumLevel = 18;this._minimumLevel = 1;let southwestInMeters = new Cesium.Cartesian2(-33554054, -33746824);let northeastInMeters = new Cesium.Cartesian2(33554054, 33746824);this._tilingScheme = new Cesium.WebMercatorTilingScheme({rectangleSouthwestInMeters: southwestInMeters,rectangleNortheastInMeters: northeastInMeters});this._rectangle = this._tilingScheme.rectangle;this._resource = Cesium.Resource.createIfNeeded(options.url);this._tileDiscardPolicy = undefined;this._credit = undefined;this._readyPromise = undefined;
};Object.defineProperties(Cesium.gm.BaiduImageryProvider.prototype, {url: {get: function () {return this._resource.url;}},proxy: {get: function () {return this._resource.proxy;}},tileWidth: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('tileWidth must not be called before the imagery provider is ready.');}return this._tileWidth;}},tileHeight: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('tileHeight must not be called before the imagery provider is ready.');}return this._tileHeight;}},maximumLevel: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('maximumLevel must not be called before the imagery provider is ready.');}return this._maximumLevel;}},minimumLevel: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('minimumLevel must not be called before the imagery provider is ready.');}return this._minimumLevel;}},tilingScheme: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('tilingScheme must not be called before the imagery provider is ready.');}return this._tilingScheme;}},tileDiscardPolicy: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('tileDiscardPolicy must not be called before the imagery provider is ready.');}return this._tileDiscardPolicy;}},rectangle: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('rectangle must not be called before the imagery provider is ready.');}return this._rectangle;}},errorEvent: {get: function () {return this._errorEvent;}},ready: {get: function () {return this._resource;}},readyPromise: {get: function () {return this._readyPromise;}},credit: {get: function () {if (!this.ready) {throw new Cesium.DeveloperError('credit must not be called before the imagery provider is ready.');}return this._credit;}},
});BaiduImageryProvider.prototype.requestImage = function (x, y, level, request) {let xTileCount = this._tilingScheme.getNumberOfXTilesAtLevel(level);let yTileCount = this._tilingScheme.getNumberOfYTilesAtLevel(level);let url = this.url.replace("{x}", x - xTileCount / 2).replace("{y}", yTileCount / 2 - y - 1).replace("{z}", level).replace("{s}", Math.floor(10 * Math.random()));console.log("zxy:" + level + ", " + x + ", " + y + "; " + url);return Cesium.ImageryProvider.loadImage(this, url);
};

调用时,传入url参数即可,url服务可以使在线服务,也可以是代理服务(按百度地图切片索引规则)。例如:

let baiduImageryProvider = new BaiduImageryProvider({url: "http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1"
});let viewer = new Cesium.Viewer('cesiumContainer', {imageryProvider: baiduImageryProvider,...
}

这时就可以在Cesium中正常加载百度地图了。

Cesium添加百度地图相关推荐

  1. java怎么添加地图_javaweb怎样添加百度地图

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 pageEncoding="utf-8"%> body, html,#allmap {width: 100%;height: 1 ...

  2. cesium模仿百度地图二三维切换

    百度地图二三维切换效果感觉比cesium自带的更平滑 不过百度地图的二三维切换只是简单的三维视角切换,二维是垂直视角 //传入viewer和要切换的维数 onChange2D3DClick(viewe ...

  3. openlayers入门添加百度地图绘制点线面

    1.构建一个地图容器 <div id="map" class="map"></div> 2.创建一个地图 2.1初始化一个openlay ...

  4. Android的清单文件添加百度地图SDK

    一.http://lbsyun.baidu.com/登录自己百度帐号 二.开发文档,Android地图SDK 三.创建应用 四.填写信息 五.复制并替换KEY

  5. 添加百度地图最简单的办法

    http://map.baidu.com/?newmap=1&ie=utf-8&s=s%26wd%3D%E4%B8%8A%E6%B5%B7%E9%9D%92%E6%B5%A6%E5%8 ...

  6. 百度地图API 海量点 自定义添加信息

    <!--添加百度地图--> <script type="text/javascript" src="http://api.map.baidu.com/a ...

  7. Vue实现百度地图并添加热力图(附源码)

    1. 效果图 2. vue项目中调用百度地图API使用介绍 开始需要先申请秘钥(ak)才可以使用,如需获取更高的配额,需要申请认证企业用户.百度地图API 链接地址:http://lbsyun.bai ...

  8. cesium实现鹰眼地图(三维)效果

    文章目录 1.实现效果 2.实现方法 2.1实现思路 2.2具体实现 2.2.1核心代码 2.2.2样式设置 2.2.3具体调用 Cesium实战系列文章总目录: 传送门 1.实现效果 2.实现方法 ...

  9. 用百度地图API分析打交通大数据

    百度地图API, 文档不全,例子不细致. 在网上还没有太多有用的例子.比如说下面几个需求的解决方案就找不到: 1. 如何用百度地图API查询一个地点的经纬度. 2. 如何用百度地图通过一个经纬度查询商 ...

  10. Android 百度地图开发(一)--- 申请API Key和在项目中显示百度地图

    2019独角兽企业重金招聘Python工程师标准>>> 最近自己想研究下地图,本来想研究google Map,但是申请API key比较坑爹,于是从百度地图入手,其实他们的用法都差不 ...

最新文章

  1. linux数据库什么意思,Linux系统中的数据库命令是什么
  2. cp -r dir1/. dir2 表示将dir1下的文件复制到dir2,不包括dir1目录
  3. response.setContentType()方法浅析
  4. 收集的一些操作系统面试题
  5. sae mysql django_Python+Django+SAE系列教程12-----配置MySQL数据库
  6. Android—设计模式原则及常见的设计模式
  7. mysql group by 规则_mysql 的group by 满足的规则要求:
  8. 最简单的EasyUI菜单栏
  9. 我为什么关注范冰冰和苍井空
  10. 【提高组NOIP2007】矩阵取数游戏
  11. VFB组件:MonthCalendar控件(月日历)
  12. 审慎 合宜与慈善三种学派的分类与核心思想
  13. 广告:互联网公司的纽带
  14. MYSQL补充SQL语句
  15. 5种顶级逻辑思维训练法:1min 轻松上手,工作学习都能用
  16. [转]gps中的广义和狭义相对论效应
  17. 1219 骑士游历(棋盘DP)
  18. xilinx基础篇Ⅰ(8)ISE14.7下载CPLD
  19. 人工神经网络matlab代码,matlab神经网络30例代码
  20. sqlite 表的列增加,修改,删除及表的重构和去重操作

热门文章

  1. CTF_Web:长安杯-2021 Old But A Little New asuka题解
  2. 戴德金--连续性和无理数--我自己做的中文翻译第1页
  3. 制造业数字化转型的困难_制造业数字化转型的难点与对策
  4. ARP报文的存入条件和回复条件
  5. 北京大学灵异事件计算机房,北大 清华高校 发生的真实恐怖灵异事件
  6. pageoffice如何离线申请_pageoffice常见问题
  7. 西方文化系列讲座之希腊文化(下)
  8. 高通modem log分析基础
  9. zuul+ribbon实现负载均衡
  10. 芯动科技面试——数字IC/FPGA面试案例总结1