Skip to content
Snippets Groups Projects
Commit 9ad5424a authored by Joni Laukka's avatar Joni Laukka
Browse files

Map drawings fixed so it works with roles

parent 96853dfd
No related branches found
No related tags found
2 merge requests!46Development to testing,!41Notifications + small updates
...@@ -246,51 +246,54 @@ class DrawTools extends Component { ...@@ -246,51 +246,54 @@ class DrawTools extends Component {
// The elements you draw will be added to this FeatureGroup layer, // The elements you draw will be added to this FeatureGroup layer,
// when you hit edit button only items in this layer will be edited." // when you hit edit button only items in this layer will be edited."
<FeatureGroup> <FeatureGroup>
<EditControl {(this.props.role === "admin" ||
position="topright" this.props.role === "factionleader") && (
onCreated={this._onCreated} <EditControl
onEdited={this._onEdited} position="topright"
onEditStart={this._onEditDeleteStart} onCreated={this._onCreated}
onEditStop={this._onEditDeleteStop} onEdited={this._onEdited}
onDeleted={this._onDeleted} onEditStart={this._onEditDeleteStart}
onDeleteStart={this._onEditDeleteStart} onEditStop={this._onEditDeleteStop}
onDeleteStop={this._onEditDeleteStop} onDeleted={this._onDeleted}
draw={{ onDeleteStart={this._onEditDeleteStart}
circle: { onDeleteStop={this._onEditDeleteStop}
repeatMode: false, // allows using the tool again after finishing the previous shape draw={{
shapeOptions: { circle: {
color: "#f9f10c", repeatMode: false, // allows using the tool again after finishing the previous shape
opacity: 1 // affects the outline only. for some reason it wasn't at full opacity, so this is needed for more clarity shapeOptions: {
} color: "#f9f10c",
}, opacity: 1 // affects the outline only. for some reason it wasn't at full opacity, so this is needed for more clarity
rectangle: { }
repeatMode: false
},
polygon: {
repeatMode: true,
allowIntersection: false, // Restricts shapes to simple polygons
drawError: {
color: "#e1e100", // Color the shape will turn when intersects
message: "<strong>Oh snap!<strong> you can't draw that!" // Message that will show when intersect
}, },
shapeOptions: { rectangle: {
color: "#ed2572", repeatMode: false
opacity: 1 },
} polygon: {
}, repeatMode: true,
polyline: { allowIntersection: false, // Restricts shapes to simple polygons
repeatMode: true, drawError: {
shapeOptions: { color: "#e1e100", // Color the shape will turn when intersects
color: "#ed2572", message: "<strong>Oh snap!<strong> you can't draw that!" // Message that will show when intersect
opacity: 1 },
} shapeOptions: {
}, color: "#ed2572",
marker: { opacity: 1
repeatMode: false }
}, },
circlemarker: false polyline: {
}} repeatMode: true,
/> shapeOptions: {
color: "#ed2572",
opacity: 1
}
},
marker: {
repeatMode: false
},
circlemarker: false
}}
/>
)}
{/* iterate through every element fetched from back-end */} {/* iterate through every element fetched from back-end */}
{this.props.geoJSONLayer.features.map(feature => { {this.props.geoJSONLayer.features.map(feature => {
......
...@@ -98,7 +98,7 @@ export default class GameView extends React.Component { ...@@ -98,7 +98,7 @@ export default class GameView extends React.Component {
getSocketSignal = data => { getSocketSignal = data => {
this.setState( this.setState(
{ {
socketSignal: data socketSignal: data // TODO: change to data
}, },
() => { () => {
this.setState({ this.setState({
......
...@@ -17,7 +17,7 @@ export default class ClientSocket extends React.Component { ...@@ -17,7 +17,7 @@ export default class ClientSocket extends React.Component {
// initiate the socket on component mount // initiate the socket on component mount
async componentWillMount() { async componentWillMount() {
// console.log("hi socket"); console.log("hi socket");
// need to explicitly update drawings and trackings when gameID first becomes available // need to explicitly update drawings and trackings when gameID first becomes available
if (this.props.gameId !== null) { if (this.props.gameId !== null) {
await this.props.getSocketSignal("drawing-update"); await this.props.getSocketSignal("drawing-update");
...@@ -47,9 +47,10 @@ export default class ClientSocket extends React.Component { ...@@ -47,9 +47,10 @@ export default class ClientSocket extends React.Component {
// set the socket to listen gameId-thread // set the socket to listen gameId-thread
socket.on(this.props.gameId, data => { socket.on(this.props.gameId, data => {
this.props.getSocketSignal(data); console.log(data.type);
this.props.getSocketSignal(data.type);
// check socket update type // check socket update type
this.setState({ update: data.type }); this.setState({ update: data });
}); });
this.props.onSocketChange(socket); this.props.onSocketChange(socket);
...@@ -57,7 +58,6 @@ export default class ClientSocket extends React.Component { ...@@ -57,7 +58,6 @@ export default class ClientSocket extends React.Component {
}; };
render() { render() {
//TODO: return needed?
return this.state.update; return this.state.update;
} }
} }
...@@ -39,6 +39,7 @@ class UserMap extends Component { ...@@ -39,6 +39,7 @@ class UserMap extends Component {
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
console.log(prevProps.socketSignal);
if (prevProps.socketSignal === "drawing-update") { if (prevProps.socketSignal === "drawing-update") {
this.fetchGeoJSON(); this.fetchGeoJSON();
} }
...@@ -162,15 +163,15 @@ class UserMap extends Component { ...@@ -162,15 +163,15 @@ class UserMap extends Component {
url={this.props.mapUrl} url={this.props.mapUrl}
/> />
<ZoomControl position="topright" /> <ZoomControl position="topright" />
{(this.props.role === "admin" ||
this.props.role === "factionleader") && ( <DrawTools
<DrawTools position={this.props.position}
position={this.props.position} sendGeoJSON={this.sendGeoJSON}
sendGeoJSON={this.sendGeoJSON} geoJSONLayer={this.state.geoJSONLayer}
geoJSONLayer={this.state.geoJSONLayer} currentGameId={this.props.currentGameId}
currentGameId={this.props.currentGameId} role={this.props.role}
/> />
)}
{this.state.ownLat !== null && ( {this.state.ownLat !== null && (
<Marker position={[this.state.ownLat, this.state.ownLng]}> <Marker position={[this.state.ownLat, this.state.ownLng]}>
<Popup> <Popup>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment