123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <!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="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>Wall 墙 </title>
- <script
- type="text/javascript"
- src="../lib/include-lib.js"
- libpath="../lib/"
- include="jquery,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,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>
- <div class="infoview">
- <div>
- 图层状态:
- <div class="checkbox checkbox-primary checkbox-inline">
- <input id="chkShow" class="styled" type="checkbox" checked />
- <label for="chkShow"> 显示隐藏 </label>
- </div>
- <div class="checkbox checkbox-primary checkbox-inline">
- <input id="chkPopup" class="styled" type="checkbox" checked />
- <label for="chkPopup"> Popup绑定 </label>
- </div>
- <div class="checkbox checkbox-primary checkbox-inline">
- <input id="chkTooltip" class="styled" type="checkbox" />
- <label for="chkTooltip"> Tooltip绑定 </label>
- </div>
- <div class="checkbox checkbox-primary checkbox-inline">
- <input id="chkContextMenu" class="styled" type="checkbox" checked />
- <label for="chkContextMenu"> 右键菜单绑定 </label>
- </div>
- </div>
- <div>
- 数据维护:
- <input id="btnStartDraw" type="button" class="btn btn-primary" value="图上标绘" title="在图上绘制新增一个矢量数据" />
- <input id="btnStartDrawClosure" type="button" class="btn btn-primary" value="闭合墙" />
- <div class="checkbox checkbox-primary checkbox-inline">
- <input id="chkHasEdit" class="styled" type="checkbox" />
- <label for="chkHasEdit"> 是否编辑 </label>
- </div>
- </div>
- <div>
- 数据管理:
- <input id="btnClear" type="button" class="btn btn-danger" value="清除" />
- <input id="btnExpFile" type="button" class="btn btn-primary" value="保存GeoJSON" title="保存为GeoJSON文件" />
- <input id="btnImpFile" type="button" class="btn btn-primary" value="打开GeoJSON" title="打开之前保存的GeoJSON文件" />
- <input id="input_draw_file" type="file" accept=".json,.geojson" style="display: none" />
- </div>
- </div>
- <!-- 切换视角到模型或地形(山区)的快捷按钮 -->
- <script type="text/javascript" src="js/center_terrain_3dtiles.js"></script>
- <!-- 图层管理相关处理js -->
- <script type="text/javascript" src="./js/graphicManager.js"></script>
- <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.473861, lng: 117.225929, alt: 52974, heading: 2, pitch: -49 },
- },
- });
- //创建三维地球场景
- map = new mars3d.Map("mars3dContainer", mapOptions);
- //创建矢量数据图层
- var graphicLayer = new mars3d.layer.GraphicLayer();
- map.addLayer(graphicLayer);
- //图层管理的相关处理,代码在\js\graphicManager.js
- initLayerManager(graphicLayer);
- //新增绘制
- $("#btnStartDraw").click(function () {
- //开始绘制
- graphicLayer.startDraw({
- type: "wall",
- style: {
- color: "#55ff33",
- opacity: 0.8,
- diffHeight: 800,
- },
- success: function (graphic) {
- console.log("绘制完成", graphic);
- },
- });
- });
- $("#btnStartDrawClosure").click(function () {
- //开始绘制
- graphicLayer.startDraw({
- type: "wall",
- style: {
- color: "#55ff33",
- opacity: 0.8,
- diffHeight: 800,
- closure: true,
- },
- success: function (graphic) {
- console.log("绘制完成", graphic);
- },
- });
- });
- //加一些演示数据
- addGraphic_a1(graphicLayer);
- addGraphic_a2(graphicLayer);
- addGraphic_a3(graphicLayer);
- addGraphic_a4(graphicLayer);
- addGraphic_a5(graphicLayer);
- addGraphic_a6(graphicLayer);
- addGraphic_a7(graphicLayer);
- addGraphic_a8(graphicLayer);
- addGraphic_a9(graphicLayer);
- }
- function addGraphic_a1(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.154815, 31.853495],
- [117.181255, 31.854257],
- [117.182284, 31.848255],
- [117.184748, 31.840141],
- [117.180557, 31.835556],
- [117.180023, 31.833741],
- [117.166846, 31.833737],
- [117.155531, 31.833151],
- [117.154787, 31.835978],
- [117.151994, 31.839036],
- [117.150691, 31.8416],
- [117.151215, 31.844734],
- ],
- style: {
- closure: true,
- diffHeight: 500,
- //动画线材质
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- image: "img/textures/fence.png",
- color: "#00ff00",
- speed: 10,
- axisY: true,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- //演示个性化处理graphic,代码在\js\graphicManager.js
- initGraphicManager(graphic);
- }
- function addGraphic_a2(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.208302, 31.85757],
- [117.234234, 31.858263],
- [117.234261, 31.833317],
- [117.207414, 31.834541],
- ],
- style: {
- closure: true,
- diffHeight: 500,
- //动画线材质
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- image: "img/textures/arrow.png",
- color: Cesium.Color.CHARTREUSE,
- repeat: new Cesium.Cartesian2(30, 1),
- speed: 20,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- function addGraphic_a3(graphicLayer) {
- //圆形时
- var positions = mars3d.PolyUtil.getEllipseOuterPositions({
- position: Cesium.Cartesian3.fromDegrees(117.276257, 31.866351, 19.57),
- radius: 1200, //半径
- count: 50, //共返回(count*4)个点
- });
- var graphic = new mars3d.graphic.WallEntity({
- positions: positions,
- style: {
- diffHeight: 800,
- closure: true,
- //动画线材质
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- image: "img/textures/fence.png",
- color: "#00ffff",
- speed: 10,
- axisY: true,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- function addGraphic_a4(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.229659, 31.908221],
- [117.240804, 31.908175],
- ],
- style: {
- diffHeight: 700,
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- //动画线材质
- image: "img/textures/fence.png",
- axisY: true,
- color: "#ff0000",
- image2: "img/textures/tanhao.png",
- color2: "#ffff00",
- speed: 10,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- function addGraphic_a5(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.153945, 31.881122, 36.4],
- [117.168352, 31.880147, 32.6],
- [117.178047, 31.885925, 29.25],
- ],
- style: {
- diffHeight: 200,
- color: "#00ffff",
- opacity: 0.4,
- label: {
- text: "我是原始的",
- font_size: 18,
- color: "#ffffff",
- distanceDisplayCondition: true,
- distanceDisplayCondition_far: 500000,
- distanceDisplayCondition_near: 0,
- },
- },
- });
- graphicLayer.addGraphic(graphic);
- //graphic转geojson
- var geojson = graphic.toGeoJSON();
- console.log("转换后的geojson", geojson);
- addGeoJson(geojson, graphicLayer);
- }
- //添加单个geojson为graphic,多个直接用graphicLayer.loadGeoJSON
- function addGeoJson(geojson, graphicLayer) {
- var graphicCopy = mars3d.Util.geoJsonToGraphics(geojson)[0];
- delete graphicCopy.attr;
- //新的坐标
- graphicCopy.positions = [
- [117.105938, 31.883825, 43.6],
- [117.125006, 31.876243, 42.6],
- [117.135525, 31.882068, 39],
- [117.151507, 31.874259, 39.7],
- ];
- graphicCopy.style.label = graphicCopy.style.label || {};
- graphicCopy.style.label.text = "我是转换后生成的";
- graphicLayer.addGraphic(graphicCopy);
- }
- function addGraphic_a6(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.353776, 31.887406, 21.2],
- [117.321028, 31.887207, 21.3],
- [117.290341, 31.902469, 15.1],
- ],
- style: {
- diffHeight: 400,
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- //动画线材质
- image: "img/textures/arrow.png",
- color: "#00eba8",
- repeat: new Cesium.Cartesian2(20, 1),
- speed: 20,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- function addGraphic_a7(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.192113, 31.80998, 32.2],
- [117.228145, 31.792757, 26.7],
- [117.2717, 31.798397, 20.7],
- ],
- style: {
- diffHeight: 500,
- color: "#00ffff",
- opacity: 0.4,
- label: { text: "鼠标移入会高亮", pixelOffsetY: -30 },
- //高亮时的样式(默认为鼠标移入,也可以指定type:'click'单击高亮),构造后也可以openHighlight、closeHighlight方法来手动调用
- highlight: {
- opacity: 0.8,
- },
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- function addGraphic_a8(graphicLayer) {
- var graphic = new mars3d.graphic.WallEntity({
- positions: [
- [117.206138, 31.877321],
- [117.206326, 31.901436],
- ],
- style: {
- diffHeight: 400,
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Image, {
- image: getColorRampCanvas(),
- transparent: false,
- }),
- },
- });
- graphicLayer.addGraphic(graphic);
- }
- //纹理图绘制
- function getColorRampCanvas(elevationRamp) {
- if (elevationRamp == null) {
- // elevationRamp = { 0.0: "blue", 0.1: "cyan", 0.37: "lime", 0.54: "yellow", 1: "red" };
- // elevationRamp = { 0.0: '#000000', 0.045: '#2747E0', 0.1: '#D33B7D', 0.15: '#D32738', 0.37: '#FF9742', 0.54: '#ffd700', 1.0: '#ffffff' }
- elevationRamp = {
- 0.0: "#FFEDA0",
- 0.05: "#FED976",
- 0.1: "#FEB24C",
- 0.15: "#FD8D3C",
- 0.37: "#FC4E2A",
- 0.54: "#E31A1C",
- 0.7: "#BD0026",
- 1.0: "#800026",
- };
- }
- var canvas = document.createElement("canvas");
- canvas.width = 1;
- canvas.height = 100;
- var ctx = canvas.getContext("2d");
- var grd = ctx.createLinearGradient(0, 0, 0, 100);
- for (var key in elevationRamp) {
- grd.addColorStop(1 - Number(key), elevationRamp[key]);
- }
- ctx.fillStyle = grd;
- ctx.fillRect(0, 0, 1, 100); //参数:左上角x 左上角y 宽度width 高度height
- return canvas.toDataURL();
- }
- //边界墙绘制
- function addGraphic_a9(graphicLayer) {
- queryAreasData().then(function (data) {
- let arr = mars3d.Util.geoJsonToGraphics(data); //解析geojson
- for (let i = 0; i < arr.length; i++) {
- let item = arr[i];
- var graphic = new mars3d.graphic.WallEntity({
- positions: item.positions,
- style: {
- diffHeight: 3000,
- material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
- image: "img/textures/fence.png",
- color: "#bdf700",
- repeat: new Cesium.Cartesian2(5, 1),
- axisY: true, //方向,true时上下,false左右
- speed: 10,
- }),
- },
- attr: item.attr,
- });
- graphicLayer.addGraphic(graphic);
- graphic.bindTooltip("合肥欢迎您 - 火星科技");
- }
- });
- }
- //边界墙绘制 - 数据获取
- function queryAreasData() {
- return new Promise(function (resolve, reject) {
- $.ajax({
- url: "//data.mars3d.cn/file/geojson/areas/340100.json",
- type: "get",
- dataType: "json",
- success: function (result) {
- resolve(result);
- },
- error: function (data) {
- reject(data);
- },
- });
- });
- }
- </script>
- </body>
- </html>
|