Cesium-React 적용
create-react-app
react 프로젝트 생성
create-react-app cesium-react-test
cd cesium-react-test
yarn eject
yarn install
모듈 설치
- cesium
- cesium-react
- html-webpack-include-assets-plugin
- copy-webpack-plugin
yarn add cesium cesium-react html-webpack-include-assets-plugin copy-webpack-plugin
webpack.config 수정
config/webpack.config.dev.js
// config/webpack.config.dev.js
const HtmlIncludeAssetsPlugin = require("html-webpack-include-assets-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
externals: {
cesium: "Cesium"
},
plugins: {
new CopyWebpackPlugin([
{
from: "node_modules/cesium/Build/CesiumUnminified",
to: "cesium"
}
]),
new HtmlIncludeAssetsPlugin({
append: false,
assets: [
"cesium/Widgets/widgets.css",
"cesium/Cesium.js"
]
}),
new webpack.DefinePlugin({
"process.env": {
CESIUM_BASE_URL: JSON.stringify("/cesium")
}
})
// ...
}
// ...
}
config/webpack.config.prod.js
// config/webpack.config.prod.js
const HtmlIncludeAssetsPlugin = require("html-webpack-include-assets-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
externals: {
cesium: "Cesium"
},
plugins: {
new CopyWebpackPlugin([
{
from: "node_modules/cesium/Build/Cesium",
to: "cesium"
}
]),
new HtmlIncludeAssetsPlugin({
append: false,
assets: [
"cesium/Widgets/widgets.css",
"cesium/Cesium.js"
]
}),
new webpack.DefinePlugin({
"process.env": {
CESIUM_BASE_URL: JSON.stringify("/cesium")
}
})
// ...
}
// ...
}
소스 수정
App.js 수정
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
import CesiumPage from "./CesiumPage";
class App extends Component {
render() {
return (
<div className="App">
<CesiumPage />
</div>
);
}
}
export default App;
CesiumPage.js 생성
import React, { Component } from "react";
import { Cartesian3 } from "cesium";
import { Viewer, Entity } from "cesium-react";
class CesiumPage extends Component {
render() {
return (
<div>
cesium page
<Viewer full>
<Entity name="Seoul" position={Cartesian3.fromDegrees(126.97224, 37.40076, 100)} point={{ pixelSize: 10 }}>
test
</Entity>
</Viewer>
</div>
);
}
}
export default CesiumPage;
'Programming > JavaScript' 카테고리의 다른 글
[책] React.JS 프로 리액트 (1/2) (0) | 2018.05.19 |
---|---|
Cesium Viewer 화면 설정 확인 (0) | 2018.05.18 |
[책] 빠른 모바일 앱 개발을 위한 React Native (0) | 2018.05.16 |
[책] Learning React (0) | 2018.04.25 |
React App 빌드시 sourcemap 파일 제외하기 (0) | 2018.04.22 |
댓글