网站制作 番禺,网络营销策划方案步骤,北京住建网站,泉州网站建设选择讯呢目录 想要实现的效果实现过程踩坑安装依赖引入页面 想要实现的效果
示例地址 实现过程
踩坑 示例是通过script引入的依赖#xff0c;但本人需要在react项目中实现该效果。按照react-globe.gl官方方法引入总是报错 Cant import the named export AmbientLight from non EcmaS… 目录 想要实现的效果实现过程踩坑安装依赖引入页面 想要实现的效果
示例地址 实现过程
踩坑 示例是通过script引入的依赖但本人需要在react项目中实现该效果。按照react-globe.gl官方方法引入总是报错 Cant import the named export AmbientLight from non EcmaScript module (only default export is available)。原因是通过import Globe from react-globe.gl;引入的是.mjs文件react-globe.gl.mjs。尝试各种方法都失败最终通过改为引入.js文件import Globe from ../../node_modules/react-globe.gl/dist/react-globe.gl.min;成功。 安装依赖
package.json版本 react-globe.gl: ^2.27.0,satellite.js: ^5.0.0,three: ^0.157.0,three-globe: ^2.30.0,web-vitals: ^2.1.4引入页面
import React, { Component, useState, useEffect, useRef, useMemo } from react;
import Globe from ../../node_modules/react-globe.gl/dist/react-globe.gl.min;
import * as THREE from three;
import * as satellite from satellite.js;function World() {const w window.screen.width * 0.5;const h (window.screen.height - 80) * 0.7;const EARTH_RADIUS_KM 6371; // kmconst SAT_SIZE 80; // kmconst TIME_STEP 3 * 1000; // per frameconst globeEl useRef();const [satData, setSatData] useState();const [globeRadius, setGlobeRadius] useState();const [time, setTime] useState(new Date());useEffect(() {// time ticker(function frameTicker() {requestAnimationFrame(frameTicker);setTime((time) new Date(time TIME_STEP));})();}, []);useEffect(() {// load satellite datafetch(//unpkg.com/globe.gl/example/datasets/space-track-leo.txt).then((r) r.text()).then((rawData) {const tleData rawData.replace(/\r/g, ).split(/\n(?[^12])/).filter((d) d).map((tle) tle.split(\n));const satData tleData.map(([name, ...tle]) ({satrec: satellite.twoline2satrec(...tle),name: name.trim().replace(/^0 /, ),}))// exclude those that cant be propagated.filter((d) !!satellite.propagate(d.satrec, new Date()).position).slice(0, 1500);setSatData(satData);});}, []);const objectsData useMemo(() {if (!satData) return [];// Update satellite positionsconst gmst satellite.gstime(time);return satData.map((d) {const eci satellite.propagate(d.satrec, time);if (eci.position) {const gdPos satellite.eciToGeodetic(eci.position, gmst);const lat satellite.radiansToDegrees(gdPos.latitude);const lng satellite.radiansToDegrees(gdPos.longitude);const alt gdPos.height / EARTH_RADIUS_KM;return { ...d, lat, lng, alt };}return d;});}, [satData, time]);const satObject useMemo(() {if (!globeRadius) return undefined;const satGeometry new THREE.OctahedronGeometry((SAT_SIZE * globeRadius) / EARTH_RADIUS_KM / 2,0);const satMaterial new THREE.MeshLambertMaterial({color: palegreen,transparent: true,opacity: 0.7,});return new THREE.Mesh(satGeometry, satMaterial);}, [globeRadius]);useEffect(() {setGlobeRadius(globeEl.current.getGlobeRadius());globeEl.current.pointOfView({ altitude: 3.5 });}, []);return (div idglobeViz classNamemap_bgGlobewidth{w}height{h}backgroundColorrgba(0,0,0,0)ref{globeEl}globeImageUrl//unpkg.com/three-globe/example/img/earth-blue-marble.jpgobjectsData{objectsData}objectLabelnameobjectLatlatobjectLnglngobjectAltitudealtobjectFacesSurface{false}objectThreeObject{satObject}//div);
}class App extends Component {...render() {return (...World /...)}
}export default App;
文章转载自: http://www.morning.ybnps.cn.gov.cn.ybnps.cn http://www.morning.ttaes.cn.gov.cn.ttaes.cn http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.enjoinfo.cn.gov.cn.enjoinfo.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.zxqxx.cn.gov.cn.zxqxx.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn http://www.morning.spnky.cn.gov.cn.spnky.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.snlxb.cn.gov.cn.snlxb.cn http://www.morning.hymmq.cn.gov.cn.hymmq.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.qrpx.cn.gov.cn.qrpx.cn http://www.morning.cxsdl.cn.gov.cn.cxsdl.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.wnwjf.cn.gov.cn.wnwjf.cn http://www.morning.c7630.cn.gov.cn.c7630.cn http://www.morning.mrfbp.cn.gov.cn.mrfbp.cn http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn http://www.morning.hphqy.cn.gov.cn.hphqy.cn http://www.morning.nmngq.cn.gov.cn.nmngq.cn http://www.morning.rkzk.cn.gov.cn.rkzk.cn http://www.morning.lwlnw.cn.gov.cn.lwlnw.cn http://www.morning.qzpkr.cn.gov.cn.qzpkr.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.lpqgq.cn.gov.cn.lpqgq.cn http://www.morning.c7500.cn.gov.cn.c7500.cn http://www.morning.snxbf.cn.gov.cn.snxbf.cn http://www.morning.mmxnb.cn.gov.cn.mmxnb.cn http://www.morning.jtqxs.cn.gov.cn.jtqxs.cn http://www.morning.fbxlj.cn.gov.cn.fbxlj.cn http://www.morning.ysckr.cn.gov.cn.ysckr.cn http://www.morning.fktlg.cn.gov.cn.fktlg.cn http://www.morning.dtcsp.cn.gov.cn.dtcsp.cn http://www.morning.zkdbx.cn.gov.cn.zkdbx.cn http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn http://www.morning.xnpj.cn.gov.cn.xnpj.cn http://www.morning.xsctd.cn.gov.cn.xsctd.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.nlysd.cn.gov.cn.nlysd.cn http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.mwhqd.cn.gov.cn.mwhqd.cn http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn http://www.morning.rlbc.cn.gov.cn.rlbc.cn http://www.morning.yfqhc.cn.gov.cn.yfqhc.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.rjfr.cn.gov.cn.rjfr.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.tpnxr.cn.gov.cn.tpnxr.cn http://www.morning.ftync.cn.gov.cn.ftync.cn http://www.morning.dygqq.cn.gov.cn.dygqq.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.hnkkm.cn.gov.cn.hnkkm.cn http://www.morning.mnccq.cn.gov.cn.mnccq.cn http://www.morning.thlzt.cn.gov.cn.thlzt.cn http://www.morning.lsssx.cn.gov.cn.lsssx.cn http://www.morning.bntgy.cn.gov.cn.bntgy.cn http://www.morning.tztgq.cn.gov.cn.tztgq.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.cqyhdy.cn.gov.cn.cqyhdy.cn http://www.morning.rnzbr.cn.gov.cn.rnzbr.cn http://www.morning.tktcr.cn.gov.cn.tktcr.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.gcqs.cn.gov.cn.gcqs.cn http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn http://www.morning.yyzgl.cn.gov.cn.yyzgl.cn http://www.morning.wgtnz.cn.gov.cn.wgtnz.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn