123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
- <meta name="author" content="火星科技 http://mars3d.cn " />
- <meta name="apple-touch-fullscreen" content="yes" />
- <meta name="apple-mobile-web-app-capable" content="yes" />
- <meta name="apple-mobile-web-app-status-bar-style" content="black" />
- <meta name="format-detection" content="telephone=no" />
- <meta name="x5-fullscreen" content="true" />
- <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
- <!-- 标题及搜索关键字 -->
- <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
- <meta
- name="description"
- content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
- />
- <link rel="shortcut icon" type="image/x-icon" href="" />
- <title>二三维联动 (leaflet+cesium) </title>
- <!--第三方lib-->
- <script
- type="text/javascript"
- src="../lib/include-lib.js"
- libpath="../lib/"
- include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars2d,mars3d"
- ></script>
- <link href="css/style.css" rel="stylesheet" />
- <style>
- #centerDiv {
- position: absolute;
- top: 0;
- left: 0;
- height: 100%;
- width: 100%;
- margin: 0;
- padding: 0;
- }
- #centerDiv3D {
- position: absolute;
- top: 0;
- right: 0;
- height: 100%;
- width: 100%;
- margin: 0;
- padding: 0;
- }
- /**cesium工具栏位置*/
- .cesium-viewer-toolbar {
- top: auto;
- left: auto;
- right: 5px;
- bottom: 5px;
- }
- .cesium-viewer-toolbar > .cesium-toolbar-button,
- .cesium-navigationHelpButton-wrapper,
- .cesium-viewer-geocoderContainer {
- margin-bottom: 5px;
- float: right;
- clear: both;
- }
- .cesium-baseLayerPicker-dropDown {
- bottom: 0;
- right: 40px;
- max-height: 700px;
- margin-bottom: 5px;
- }
- .cesium-navigation-help {
- top: auto;
- bottom: 0;
- right: 40px;
- transform-origin: right bottom;
- }
- </style>
- </head>
- <body>
- <div id="centerDiv">
- <div id="map2d" class="mars2d-container"></div>
- </div>
- <div id="centerDiv3D">
- <div id="mars3dContainer" class="mars3d-container"></div>
- </div>
- <!-- 面板 -->
- <div class="infoview" style="left: 43%; top: 2px">
- <input type="button" class="btn btn-primary" value="分屏" onclick="mapManager.viewTo23D();" />
- <input type="button" class="btn btn-primary" value="仅2D" onclick="mapManager.viewTo2d();" />
- <input type="button" class="btn btn-primary" value="仅3D" onclick="mapManager.viewTo3d();" />
- </div>
- <script src="./js/common.js"></script>
- <script type="text/javascript">
- "use script"; //开发环境建议开启严格模式
- //最佳的二三维联动是:https://github.com/openlayers/ol-cesium
- var map3d;
- function initMap(options) {
- //合并属性参数,可覆盖config.json中的对应配置
- var mapOptions = mars3d.Util.merge(options, {});
- //创建三维地球场景
- map3d = new mars3d.Map("mars3dContainer", mapOptions);
- haoutil.loading.show();
- //读取 config.json 配置文件
- var configUrl = "http://mars2d.cn/example/config/config.json";
- return mars2d.axios
- .get(configUrl)
- .then(function (response) {
- //构建地图
- mapManager.createMap2D("map2d", response.data.map);
- mapManager.bind3D(map3d);
- mapManager.viewTo23D(); //默认
- haoutil.loading.hide();
- })
- .catch(function (error) {
- console.log(error);
- haoutil.alert(error && error.message, "出错了");
- });
- }
- //二三维地图联动控制
- var mapManager = {
- map2d: null, //leaflet map 对象
- map3d: null, //cesium map3d对象
- createMap2D: function (id, mapOptions) {
- //创建地图
- this.map2d = new mars2d.Map(id, mapOptions);
- this.bind2dEvent(this.map2d);
- },
- bind3D: function (map3d) {
- this.map3d = map3d;
- this.bind3dEvent();
- this._map_extentChangeHandler();
- },
- viewTo2d: function () {
- $("#centerDiv3D").hide();
- $("#centerDiv").css({ width: "100%" }).show();
- if (this.map2d) {
- this.map2d.invalidateSize(false);
- }
- },
- viewTo3d: function () {
- $("#centerDiv").hide();
- $("#centerDiv3D").css({ width: "100%" }).show();
- },
- viewTo23D: function () {
- $("#centerDiv").css({ width: "50%" }).show();
- $("#centerDiv3D").css({ width: "50%" }).show();
- if (this.map2d) {
- this.map2d.invalidateSize(false);
- }
- },
- //二维地图变化事件
- bind2dEvent: function () {
- this.map2d.on("drag", this._map_extentChangeHandler, this);
- this.map2d.on("zoomend", this._map_extentChangeHandler, this);
- },
- unbind2dEvent: function () {
- this.map2d.off("drag", this._map_extentChangeHandler, this);
- this.map2d.off("zoomend", this._map_extentChangeHandler, this);
- },
- _map_extentChangeHandler: function (e) {
- var bounds = this.map2d.getBounds();
- var extent = {
- xmin: bounds.getWest(),
- xmax: bounds.getEast(),
- ymin: bounds.getSouth(),
- ymax: bounds.getNorth(),
- };
- console.log(`'二维地图变化了,区域: ${JSON.stringify(extent)} `);
- this.unbind3dEvent();
- this.map3d.camera.setView({
- destination: Cesium.Rectangle.fromDegrees(extent.xmin, extent.ymin, extent.xmax, extent.ymax),
- });
- this.bind3dEvent();
- },
- //三维地图相机移动结束事件
- bind3dEvent: function () {
- this.map3d.on(mars3d.EventType.cameraChanged, this.camera_moveEndHandler, this);
- },
- unbind3dEvent: function () {
- this.map3d.off(mars3d.EventType.cameraChanged, this.camera_moveEndHandler, this);
- },
- camera_moveEndHandler: function (e) {
- // 范围对象
- var point = this.map3d.getCenter();
- var level = this.map3d.level;
- console.log(`'三维地图变化了,位置: ${point.toString()},层级 ${level} `);
- this.unbind2dEvent();
- this.map2d.setView([point.lat, point.lng], level, { animate: false });
- this.bind2dEvent();
- },
- };
- </script>
- </body>
- </html>
|