summaryrefslogtreecommitdiff
path: root/src/components/map/MapStage.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-21 12:08:41 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:43 +0200
commit1b6545fa653df44b019f6676faed39880999b2bf (patch)
treecb131975db09cdb401b082700e2075d462495897 /src/components/map/MapStage.js
parent8a49e1eedebb6d4c47edf6fd1a7545ea502d59e7 (diff)
Add basic react-konva rendering prototype
Diffstat (limited to 'src/components/map/MapStage.js')
-rw-r--r--src/components/map/MapStage.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/components/map/MapStage.js b/src/components/map/MapStage.js
new file mode 100644
index 00000000..38047064
--- /dev/null
+++ b/src/components/map/MapStage.js
@@ -0,0 +1,55 @@
+import React from "react";
+import {Group, Layer, Stage} from "react-konva";
+import jQuery from "../../util/jquery";
+import Backdrop from "./elements/Backdrop";
+import GridGroup from "./groups/GridGroup";
+import RoomGroup from "./groups/RoomGroup";
+import {MAP_SIZE_IN_PIXELS} from "./MapConstants";
+
+class MapStage extends React.Component {
+ state = {
+ width: 600,
+ height: 400
+ };
+
+ componentWillMount() {
+ this.updateDimensions();
+ }
+
+ componentDidMount() {
+ window.addEventListener("resize", this.updateDimensions.bind(this));
+ }
+
+ componentWillUnmount() {
+ window.removeEventListener("resize", this.updateDimensions.bind(this));
+ }
+
+ updateDimensions() {
+ this.setState({width: jQuery(window).width(), height: jQuery(window).height()});
+ }
+
+ dragBoundHandler(pos) {
+ return {
+ x: pos.x > 0 ? 0 :
+ (pos.x < -MAP_SIZE_IN_PIXELS + this.state.width ? -MAP_SIZE_IN_PIXELS + this.state.width : pos.x),
+ y: pos.y > 0 ? 0 :
+ (pos.y < -MAP_SIZE_IN_PIXELS + this.state.height ? -MAP_SIZE_IN_PIXELS + this.state.height : pos.y)
+ }
+ }
+
+ render() {
+ return (
+ <Stage width={this.state.width} height={this.state.height}>
+ <Layer>
+ <Group draggable={true} dragBoundFunc={this.dragBoundHandler.bind(this)}>
+ <Backdrop/>
+ <RoomGroup/>
+ <GridGroup/>
+ </Group>
+ </Layer>
+ </Stage>
+ )
+ }
+}
+
+export default MapStage;