summaryrefslogtreecommitdiff
path: root/src/components/map/MapStage.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-31 17:59:51 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:50 +0200
commit3f736cd3db63f106eac02f220477b4a0f3b0eceb (patch)
tree80afa73f8c4d281b2fccba8ad2baa7c10f7e7e84 /src/components/map/MapStage.js
parentb17f1d8cb4815f57a4b7043cc91b867ec3cbc867 (diff)
Implement room creation
Diffstat (limited to 'src/components/map/MapStage.js')
-rw-r--r--src/components/map/MapStage.js31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/components/map/MapStage.js b/src/components/map/MapStage.js
index 644b4c54..541df1d6 100644
--- a/src/components/map/MapStage.js
+++ b/src/components/map/MapStage.js
@@ -1,6 +1,7 @@
import React from "react";
import {Group, Layer, Stage} from "react-konva";
import DatacenterContainer from "../../containers/map/DatacenterContainer";
+import HoverTileLayer from "../../containers/map/layers/HoverTileLayer";
import jQuery from "../../util/jquery";
import {NAVBAR_HEIGHT} from "../navigation/Navbar";
import Backdrop from "./elements/Backdrop";
@@ -10,7 +11,11 @@ import {MAP_SIZE_IN_PIXELS} from "./MapConstants";
class MapStage extends React.Component {
state = {
width: 600,
- height: 400
+ height: 400,
+ x: 0,
+ y: 0,
+ mouseX: 0,
+ mouseY: 0
};
componentWillMount() {
@@ -29,18 +34,30 @@ class MapStage extends React.Component {
this.setState({width: jQuery(window).width(), height: jQuery(window).height() - NAVBAR_HEIGHT});
}
+ updateMousePosition() {
+ const mousePos = this.stage.getStage().getPointerPosition();
+ this.setState({mouseX: mousePos.x, mouseY: mousePos.y});
+ }
+
dragBoundFunc(pos) {
- return {
+ const updatedPosition = {
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)
- }
+ };
+
+ this.setState(updatedPosition);
+
+ return updatedPosition;
}
render() {
return (
- <Stage width={this.state.width} height={this.state.height}>
+ <Stage ref={(stage) => {this.stage = stage;}}
+ width={this.state.width}
+ height={this.state.height}
+ onMouseMove={this.updateMousePosition.bind(this)}>
<Layer>
<Group draggable={true} dragBoundFunc={this.dragBoundFunc.bind(this)}>
<Backdrop/>
@@ -48,6 +65,12 @@ class MapStage extends React.Component {
<GridGroup/>
</Group>
</Layer>
+ <HoverTileLayer
+ mainGroupX={this.state.x}
+ mainGroupY={this.state.y}
+ mouseX={this.state.mouseX}
+ mouseY={this.state.mouseY}
+ />
</Stage>
)
}