码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Cesium从零开始开发


    持续更新中

    目录

    1、下载安装部署

    2、隐藏主页控件

    3、GeoJson数据加载和转换

    4、常用方法

    4.1获取经纬度

    9999、参考资料


    1、下载安装部署

    0.环境准备Node

    1.下载安装

    https://github.com/CesiumGS/cesium/releases/download/1.110/Cesium-1.110.zip
    1. cd Cesium-1.110
    2. npm i
    3. node server.js

    打开http://localhost:8080/Apps/HelloWorld.html

    修改HelloWord.html 初始定位到中国,并设置token,token可以免费注册申请。

    1. <div id="cesiumContainer">div>
    2. <script>
    3. Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(
    4. 75.0, // 西经
    5. 0.0, // 南纬
    6. 140.0, // 东经
    7. 60.0 // 北纬
    8. );
    9. Cesium.Ion.defaultAccessToken="eyJhbGciOiJ..........."
    10. const viewer = new Cesium.Viewer("cesiumContainer");
    11. script>

    2、隐藏主页控件

    1. Geocoder : A location search tool that flies the camera to queried location. Uses Bing Maps data by default.
    2. HomeButton : Flies the viewer back to a default view.
    3. SceneModePicker : Switches between 3D, 2D and Columbus View (CV) modes.
    4. BaseLayerPicker : Chooses the imagery and terrain to display on the globe.
    5. NavigationHelpButton : Displays the default camera controls.
    6. Animation : Controls the play speed for view animation.
    7. CreditsDisplay : Displays data attributions. Almost always required!
    8. Timeline : Indicates current time and allows users to jump to a specific time using the scrubber.
    9. FullscreenButton : Makes the Viewer fullscreen.

    翻译

    1. Geocoder : 一种地理位置搜索工具,用于显示相机访问的地理位置。默认使用微软的Bing地图。
    2. HomeButton : 首页位置,点击之后将视图跳转到默认视角。
    3. SceneModePicker : 切换2D、3D 和 Columbus View (CV) 模式。
    4. BaseLayerPicker : 选择三维数字地球的底图(imagery and terrain)。
    5. NavigationHelpButton : 帮助提示,如何操作数字地球。
    6. Animation :控制视窗动画的播放速度。
    7. CreditsDisplay : 展示商标版权和数据源。
    8. Timeline : 展示当前时间和允许用户在进度条上拖动到任何一个指定的时间。
    9. FullscreenButton : 视察全屏按钮。

    1. var viewer = new Cesium.Viewer('cesiumContainer',{
    2. geocoder:false,
    3. homeButton:false,
    4. sceneModePicker:false,
    5. baseLayerPicker:false,
    6. navigationHelpButton:false,
    7. animation:false,
    8. timeline:false,
    9. fullscreenButton:false,
    10. vrButton:false
    11. });
    12. viewer._cesiumWidget._creditContainer.style.display="none"; //版权控件的显示隐藏

    3、GeoJson数据加载和转换

    以中国地图为例,首先需要获取json数据

    DataV.GeoAtlas地理小工具系列

    1. viewer.dataSources.add(Cesium.GeoJsonDataSource.load('./data/100000.json', {
    2. stroke: Cesium.Color.Red,
    3. fill: Cesium.Color.YELLOW.withAlpha(0),
    4. strokeWidth: 3,
    5. markerSymbol: '?',
    6. }));

    如果使用shp格式,可能需要转换

    https://mapshaper.org/

    或者安装npm install mapshaper

    mapshaper ./*.shp  -proj wgs84 -o myfile.geojson  precision=0.0000001 -simplify 10%

    4、常用方法

    4.1获取经纬度

    1. // 点击图像时,consoloe输出经纬度
    2. let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    3. handler.setInputAction(function (event) {
    4. let cartesian = viewer.camera.pickEllipsoid(event.position);
    5. let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
    6. let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
    7. let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
    8. let alt = cartographic.height; // 高度,椭球面height永远等于0
    9. let coordinate = {
    10. longitude: Number(lng.toFixed(6)),
    11. latitude: Number(lat.toFixed(6)),
    12. altitude: Number(alt.toFixed(2))
    13. };
    14. console.log(coordinate);
    15. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    9999、参考资料

    Cesium:入门教程(一)之 Hello World_cesium教程-CSDN博客

    Downloads – Cesium

    https://www.cnblogs.com/onsummer/p/14957839.html

    entity API:Cesium三维地球上添加点、线、面、文字、图标(图片)、模型等标绘_cesium绘制贴地点图标-CSDN博客

    控件:https://github.com/hujiulin/CesiumJS-tutorial/tree/master/%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8%E4%B8%AD%E6%96%87%E6%95%99%E7%A8%8B/Cesium%E5%85%A5%E9%97%A84%20-%20%E5%88%9B%E5%BB%BACesium%20Viewer

  • 相关阅读:
    java学习--day24(stream流)
    安装下载Anaconda注意事项以及卸载
    python-vlc
    关于低代码和无代码---喧嚣背后的致命问题
    使用iPerf3测试局域网网络带宽
    浅谈2023软件测试工程师需要掌握的能力
    后台管理系统通用解决方案
    Powerpoint不小心被覆盖?PPT误删文件如何恢复?
    初体验 在Dell R7525 服务器 RTX 3090 安装Chat with RTX
    HINet: Half Instance Normalization Network for Image Restoration
  • 原文地址:https://blog.csdn.net/hy1405430407/article/details/133811313
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号