123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <!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>数字社区 </title>
- <!--第三方lib-->
- <script
- type="text/javascript"
- src="../lib/include-lib.js"
- libpath="../lib/"
- include="jquery,font-awesome,bootstrap,layer,haoutil,mars3d"
- ></script>
- <link href="css/style.css" rel="stylesheet" />
- </head>
- <body class="dark">
- <!--加载前进行操作提示,优化用户体验-->
- <div id="mask" class="signmask" onclick="removeMask()"></div>
- <div id="mars3dContainer" class="mars3d-container"></div>
- <script src="./js/common.js"></script>
- <script type="text/javascript">
- "use script"; //开发环境建议开启严格模式
- var map;
- function initMap(options) {
- //合并属性参数,可覆盖config.json中的对应配置
- var mapOptions = mars3d.Util.merge(options, {
- scene: {
- center: { lat: 31.818816, lng: 117.221131, alt: 2553, heading: 0, pitch: -55 },
- },
- });
- //创建三维地球场景
- map = new mars3d.Map("mars3dContainer", mapOptions);
- map.basemap = 2017; //切换到蓝色底图
- addTilesetLayer();
- addGraphics();
- }
- //合肥市建筑物模型
- function addTilesetLayer() {
- var fragmentShader = `
- // 注意shader中写浮点数是,一定要带小数点,否则会报错,比如0需要写成0.0,1要写成1.0
- float _baseHeight = 0.0; // 物体的基础高度,需要修改成一个合适的建筑基础高度
- float _heightRange = 25.0; // 高亮的范围(_baseHeight ~ _baseHeight + _heightRange)
- float _glowRange = 300.0; // 光环的移动范围(高度)
- // 建筑基础色
- float mars_height = marsJzwHeight - _baseHeight;
- float mars_a11 = fract(czm_frameNumber / 120.0) * 3.14159265 * 2.0;
- float mars_a12 = mars_height / _heightRange + sin(mars_a11) * 0.1;
- gl_FragColor *= vec4(vec3(mars_a12), 1.0);// 渐变
- // 动态光环
- float time = fract(czm_frameNumber / 360.0);
- time = abs(time - 0.5) * 2.0;
- float mars_h = clamp(mars_height / _glowRange, 0.0, 1.0);
- float mars_diff = step(0.005, abs(mars_h - time));
- gl_FragColor.rgb += gl_FragColor.rgb * (1.0 - mars_diff);
- `;
- var tiles3dLayer = new mars3d.layer.TilesetLayer({
- name: "合肥市建筑物",
- url: "//data.mars3d.cn/3dtiles/jzw-hefei/tileset.json",
- maximumScreenSpaceError: 1,
- maximumMemoryUsage: 1024,
- marsJzwStyle: fragmentShader,
- style: {
- color: {
- conditions: [["true", "rgba(16, 119, 209, 1)"]],
- },
- },
- });
- map.addLayer(tiles3dLayer);
- //模型裁剪
- var modelThing = new mars3d.thing.TilesetClip({
- layer: tiles3dLayer,
- positions: [
- [117.22648, 31.827441],
- [117.210341, 31.830612],
- [117.211311, 31.842438],
- [117.226091, 31.842885],
- ],
- clipOutSide: true, //外裁剪
- });
- map.addThing(modelThing);
- }
- function addGraphics() {
- //创建矢量数据图层
- var graphicLayer = new mars3d.layer.GraphicLayer();
- map.addLayer(graphicLayer);
- queryAreasData().then(function (geojson) {
- let arr = mars3d.Util.geoJsonToGraphics(geojson); //解析geojson
- for (let i = 0; i < arr.length; i++) {
- let item = arr[i];
- //polygon面
- var polygonEntity = new mars3d.graphic.PolygonEntity({
- positions: item.positions,
- style: {
- color: item.attr.color,
- opacity: 0.4,
- },
- });
- graphicLayer.addGraphic(polygonEntity);
- //PolylineEntity线
- var graphicLine = new mars3d.graphic.PolylineEntity({
- positions: item.positions,
- style: {
- width: 4,
- closure: true,
- // clampToGround: true,
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineTrail, {
- color: item.attr.color,
- speed: 4,
- }),
- },
- });
- graphicLayer.addGraphic(graphicLine);
- //动态边框文本 DIV
- var graphic = new mars3d.graphic.DivBoderLabel({
- position: polygonEntity.center,
- style: {
- text: item.attr.name,
- font_size: 15,
- font_family: "微软雅黑",
- color: "#ccc",
- boderColor: "#15d1f2",
- addHeight: 100,
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- });
- }
- function queryAreasData() {
- return new Promise(function (resolve, reject) {
- $.ajax({
- url: "//data.mars3d.cn/file/geojson/hefei-shequ.json",
- type: "get",
- dataType: "json",
- success: function (geojson) {
- resolve(geojson);
- },
- error: function (data) {
- reject(data);
- },
- });
- });
- }
- </script>
- </body>
- </html>
|