Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-frontend
Commits
77efbaec
Commit
77efbaec
authored
5 years ago
by
L4929
Browse files
Options
Downloads
Patches
Plain Diff
Get player locations from database. Currently only get them once
parent
45c48b08
No related branches found
No related tags found
2 merge requests
!21
Development
,
!20
Add tracked players to map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/Player.js
+85
-0
85 additions, 0 deletions
src/components/Player.js
src/components/UserMap.js
+2
-1
2 additions, 1 deletion
src/components/UserMap.js
with
87 additions
and
1 deletion
src/components/Player.js
0 → 100644
+
85
−
0
View file @
77efbaec
import
React
,
{
Component
}
from
"
react
"
;
import
{
Marker
,
Popup
}
from
"
react-leaflet
"
;
class
Player
extends
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
players
:
null
};
}
getPlayers
()
{
fetch
(
"
http://localhost:5000/tracking/players/
"
+
this
.
props
.
currentGameId
,
{
method
:
"
GET
"
,
headers
:
{
Authorization
:
"
Bearer
"
+
sessionStorage
.
getItem
(
"
token
"
)
}
}
)
.
then
(
res
=>
res
.
json
())
// no brackets over res.json() or it breaks (what)
.
then
(
data
=>
{
// don't do anything if data is not an array, as it breaks the map function at render
if
(
Array
.
isArray
(
data
))
{
this
.
setState
({
players
:
data
});
}
})
.
catch
(
error
=>
{
console
.
log
(
error
);
});
}
shouldComponentUpdate
(
nextProps
,
nextState
)
{
// do not update component until players have been fetched and game ID is available
if
(
this
.
state
.
players
===
null
)
{
this
.
getPlayers
();
return
false
;
}
else
if
(
this
.
props
.
currentGameId
===
null
)
{
return
false
;
}
else
{
return
true
;
}
}
componentDidUpdate
()
{
// check if game ID has changed
if
(
this
.
state
.
currentGameId
!==
this
.
props
.
currentGameId
)
{
this
.
setState
({
currentGameId
:
this
.
props
.
currentGameId
});
}
}
render
()
{
return
(
<
div
>
{
this
.
state
.
players
!==
null
&&
this
.
state
.
players
.
map
(
player
=>
{
return
(
<
Marker
key
=
{
Math
.
random
()}
position
=
{
player
.
coordinates
}
factionId
=
{
player
.
factionId
}
gamepersonId
=
{
player
.
gamepersonId
}
gamepersonRole
=
{
player
.
gamepersonRole
}
>
<
Popup
>
<
b
>
factionId
:
<
/b> {player.factionId
}
<
br
/>
<
b
>
gamepersonId
:
<
/b> {player.gamepersonId
}
<
br
/>
<
b
>
gamepersonRole
:
<
/b> {player.gamepersonRole
}
<
/Popup
>
<
/Marker
>
);
})}
<
/div
>
);
}
}
export
default
Player
;
This diff is collapsed.
Click to expand it.
src/components/UserMap.js
+
2
−
1
View file @
77efbaec
import
React
,
{
Component
}
from
"
react
"
;
import
{
Map
,
TileLayer
,
ZoomControl
,
Marker
,
Popup
}
from
"
react-leaflet
"
;
import
DrawTools
from
"
./DrawTools.js
"
;
import
Player
from
"
./Player.js
"
;
class
UserMap
extends
Component
{
constructor
(
props
)
{
...
...
@@ -111,7 +112,6 @@ class UserMap extends Component {
.
catch
(
error
=>
{
console
.
log
(
error
);
});
console
.
log
(
this
.
state
.
geoJSONLayer
);
}
componentWillUnmount
()
{
...
...
@@ -190,6 +190,7 @@ class UserMap extends Component {
</Popup>
</Marker>
)}
<Player currentGameId={this.state.currentGameId} />
</Map>
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment