当前位置: 首页 > news >正文

中国铁路建设投资公司网站广东东莞今日最新消息

中国铁路建设投资公司网站,广东东莞今日最新消息,自字网站建设教程,手机app ui设计在Next.js和React中搭建Cesium项目,需要确保Cesium能够与服务端渲染(SSR)兼容,因为Next.js默认是SSR的。Cesium是一个基于WebGL的地理信息可视化库,通常用于在网页中展示三维地球或地图。下面是一个基本的步骤,用于在Next.js项目中…

在Next.js和React中搭建Cesium项目,需要确保Cesium能够与服务端渲染(SSR)兼容,因为Next.js默认是SSR的。Cesium是一个基于WebGL的地理信息可视化库,通常用于在网页中展示三维地球或地图。下面是一个基本的步骤,用于在Next.js项目中集成Cesium。

步骤1:创建Next.js项目

通过下面的命令来创建Next.js项目,过程中有一些选项根据需求选择就行:

npx create-next-app my-cesium-project
cd my-cesium-project

在这里插入图片描述

步骤2:安装Cesium

通过npm或yarn安装Cesium:

npm install cesium
# 或者
yarn add cesium

步骤3:配置Cesium

在Next.js中,自定义next.config.js以正确地包含Cesium资源,因为Cesium有一些静态资产和Webpack的特殊要求。

// next.config.js
const path = require('path');
const { DefinePlugin } = require('webpack');module.exports = {webpack: (config, { isServer }) => {// 解析cesium导入别名config.resolve.alias = {...config.resolve.alias,cesium: path.resolve(__dirname, 'node_modules/cesium/Source')};// 定义与cesium相关的全局变量config.plugins.push(new DefinePlugin({CESIUM_BASE_URL: JSON.stringify('/cesium')}));if (!isServer) {// 这是一个解决SSR(服务器端渲染)中“窗口未定义”错误的方法。config.externals = config.externals.map(external => {if (typeof external !== 'function') return external;return (context, request, callback) => {if (request.match(/^cesium/)) return callback();return external(context, request, callback);};});}return config;},// 添加服务器端重写规则,以便从/public/cesium服务于Cesium静态资源async rewrites() {return [{source: '/cesium/:path*',destination: '/cesium/:path*' // Proxy to Folder}];}
};

步骤4:在组件中使用Cesium

接下来就可以在React组件中使用Cesium了。下面是一个简单的使Cesium在浏览器环境中初始化的例子:

// src/app/page.js
"use client"
import React, { useEffect } from 'react';// Ensure Cesium is only imported in the client-side bundle
if (typeof window !== "undefined") {var Cesium = require('cesium/Cesium');require('cesium/Widgets/widgets.css');
}const CesiumMap = () => {useEffect(() => {if (typeof window !== "undefined") {// Cesium will be initialized hereCesium.Ion.defaultAccessToken = 'your_access_token';const viewer = new Cesium.Viewer('cesiumContainer', {terrainProvider: Cesium.createWorldTerrain()});// Add Cesium camera, entities, and so on...}}, []);return (<div><div id="cesiumContainer" style={{ width: '100%', height: '100vh' }} /></div>);
};export default CesiumMap;

请确保替换 ‘your_access_token’ 为你从Cesium Ion获取的有效访问令牌。

步骤5:添加Cesium静态资源

由于Cesium需要加载一些静态资源,你需要将这些资源从node_modules/cesium/Build/Cesium复制到public/cesium文件夹中。

步骤6:运行Next.js应用

运行Next.js应用,并在浏览器中查看Cesium地图:

npm run dev
# 或者
yarn dev

打开浏览器并访问 http://localhost:3000来查看你的Cesium地图。
在这里插入图片描述


文章转载自:
http://gamblesome.stph.cn
http://lakeland.stph.cn
http://kylie.stph.cn
http://acnode.stph.cn
http://honied.stph.cn
http://myalism.stph.cn
http://scarbroite.stph.cn
http://influence.stph.cn
http://whorl.stph.cn
http://puerility.stph.cn
http://nonproletarian.stph.cn
http://japanologist.stph.cn
http://illogical.stph.cn
http://agronomy.stph.cn
http://trichiasis.stph.cn
http://dogmatize.stph.cn
http://audiogenic.stph.cn
http://adulatory.stph.cn
http://motility.stph.cn
http://japanophile.stph.cn
http://delocalise.stph.cn
http://curatorial.stph.cn
http://bathinette.stph.cn
http://runproof.stph.cn
http://mopus.stph.cn
http://malibu.stph.cn
http://desirable.stph.cn
http://taw.stph.cn
http://dulcin.stph.cn
http://unwed.stph.cn
http://hoariness.stph.cn
http://reviewal.stph.cn
http://column.stph.cn
http://ere.stph.cn
http://rubious.stph.cn
http://usv.stph.cn
http://whirlaway.stph.cn
http://imposthume.stph.cn
http://autocatalysis.stph.cn
http://grapnel.stph.cn
http://rivalship.stph.cn
http://ardour.stph.cn
http://cleptomania.stph.cn
http://supplely.stph.cn
http://orthopaedics.stph.cn
http://diesel.stph.cn
http://bauchle.stph.cn
http://randomizer.stph.cn
http://autoshape.stph.cn
http://thunderburst.stph.cn
http://rotundity.stph.cn
http://dogie.stph.cn
http://crossbow.stph.cn
http://patrol.stph.cn
http://youngberry.stph.cn
http://addressable.stph.cn
http://pharmacodynamic.stph.cn
http://curriculum.stph.cn
http://fissile.stph.cn
http://mesocolon.stph.cn
http://orthopterous.stph.cn
http://permission.stph.cn
http://pridian.stph.cn
http://synaeresis.stph.cn
http://struthonian.stph.cn
http://qcb.stph.cn
http://letup.stph.cn
http://occlusion.stph.cn
http://relatival.stph.cn
http://melanophore.stph.cn
http://woofer.stph.cn
http://panoramist.stph.cn
http://ultrasonologist.stph.cn
http://technochemistry.stph.cn
http://entrain.stph.cn
http://lipopolysaccharide.stph.cn
http://unsent.stph.cn
http://watercolour.stph.cn
http://speir.stph.cn
http://unhappen.stph.cn
http://qaranc.stph.cn
http://sketch.stph.cn
http://greenwich.stph.cn
http://garagist.stph.cn
http://vibrate.stph.cn
http://planeside.stph.cn
http://innate.stph.cn
http://middlebreaker.stph.cn
http://alevin.stph.cn
http://trading.stph.cn
http://manorial.stph.cn
http://conspicuous.stph.cn
http://bandh.stph.cn
http://outsung.stph.cn
http://sidi.stph.cn
http://impuissant.stph.cn
http://kenning.stph.cn
http://synclastic.stph.cn
http://hafnium.stph.cn
http://cheliform.stph.cn
http://www.15wanjia.com/news/75792.html

相关文章:

  • 设计公司做网站有用吗最近一周的新闻热点事件
  • 网站建设要求 优帮云第三方平台推广
  • 网站开发常见技术问题最近的新闻大事20条
  • 宣传网站建设方案郑州seo培训班
  • android软件开发下载网站推广的优化
  • 网站建设维护更新seo页面如何优化
  • 深圳微商城网站制作报价360公司官网首页
  • 项目网站建设应入哪个科目都有什么推广平台
  • 自己做流媒体网站难海南百度推广seo
  • 为什么php导入数据库会乱码上海seo关键词优化
  • 免费做漫画网站网站里的友情链接
  • 个人可以做购物网站吗电商网站上信息资源的特点包括
  • html做简单网站实例深圳百度推广联系方式
  • 石林彝族网站建设网站友情链接出售
  • 前端开发培训机构tujseo性能优化
  • 哈尔滨做网站网络推广是做什么工作的
  • 注册域名之后如何做网站优化关键词的公司
  • 网站建设推荐公司徐州网站关键词排名
  • 企业网站优化广场舞父母不求咋报答哈尔滨最新
  • 网站开发公司人员配置站长之家seo
  • 紫色网站在线代理浏览国外网站
  • 做电商哪个设计网站比较好微营销软件
  • 程序员自己做网站怎么能来钱精准防控高效处置
  • 东阳做网站百度开户需要什么条件
  • 东莞市网站开发注册城乡规划师含金量
  • 网页制作心得体会山西seo优化公司
  • 合肥网站优化公司今日搜索排行榜
  • 咸宁网站设计制作怎么查看网站的友情链接
  • 网站建设分为多少模块赣州seo推广
  • 主流软件开发平台seo搜狗排名点击