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
a7c23d50
Commit
a7c23d50
authored
5 years ago
by
Taneli Riihimäki
Browse files
Options
Downloads
Patches
Plain Diff
Update the markers position on map when the geolocation changes
parent
dbb65b50
No related branches found
No related tags found
1 merge request
!21
Development
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/UserMap.js
+47
-82
47 additions, 82 deletions
src/components/UserMap.js
with
47 additions
and
82 deletions
src/components/UserMap.js
+
47
−
82
View file @
a7c23d50
...
@@ -3,45 +3,44 @@ import {
...
@@ -3,45 +3,44 @@ import {
Map
,
Map
,
TileLayer
,
TileLayer
,
Marker
,
Marker
,
Popup
Popup
,
LayersControl
,
GeoJSON
}
from
'
react-leaflet
'
}
from
'
react-leaflet
'
import
DrawTools
from
'
./DrawTools
'
import
DrawTools
from
'
./DrawTools
'
class
UserMap
extends
Component
{
class
UserMap
extends
Component
{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
this
.
state
=
{
this
.
state
=
{
ownLat
:
null
,
ownLat
:
null
,
ownLng
:
null
,
ownLng
:
null
,
mapUrl
:
'
https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg
'
,
mapUrl
:
'
https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg
'
,
marker
:
{
geojsonLayer
:
{
type
:
"
FeatureCollection
"
,
"
type
"
:
"
FeatureCollection
"
,
latitude
:
""
,
"
latitude
"
:
""
,
longitude
:
""
,
"
longitude
"
:
""
,
timestamp
:
""
,
"
timestamp
"
:
""
,
features
:
[{
"
features
"
:
[{
type
:
"
Feature
"
,
"
type
"
:
"
Feature
"
,
properties
:
{},
"
properties
"
:
{},
geometry
:
{
"
geometry
"
:
{
type
:
"
Point
"
,
"
type
"
:
"
Point
"
,
coordinates
:
[
"
coordinates
"
:
[
25.7597186
,
62.20416479
]
62.2416479
,
25.7597186
]
}
}
}]
}]
}
}
}
}
this
.
watchPositionId
=
null
;
this
.
watchPositionId
=
null
;
}
}
componentDidMount
(){
componentDidMount
(){
console
.
log
(
JSON
.
stringify
(
this
.
state
.
marker
))
this
.
getCurrentPosition
((
position
)
=>
{
this
.
getCurrentPosition
((
position
)
=>
{
this
.
setCurrentPosition
(
position
);
this
.
setCurrentPosition
(
position
);
});
});
console
.
log
(
JSON
.
stringify
(
this
.
state
.
marker
))
//sendGeoJSON()
//sendGeoJSON()
}
}
// Sends the players marker to the backend
// Sends the players marker to the backend
...
@@ -53,7 +52,7 @@ class UserMap extends Component {
...
@@ -53,7 +52,7 @@ class UserMap extends Component {
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
'
Content-Type
'
:
'
application/json
'
},
},
body
:
JSON
.
stringify
(
this
.
state
.
mark
er
)
body
:
JSON
.
stringify
(
this
.
state
.
geojsonLay
er
)
})
})
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
res
.
json
())
.
then
(
result
=>
console
.
log
(
result
))
.
then
(
result
=>
console
.
log
(
result
))
...
@@ -65,26 +64,27 @@ class UserMap extends Component {
...
@@ -65,26 +64,27 @@ class UserMap extends Component {
navigator
.
geolocation
.
clearWatch
(
this
.
watchPositionId
);
navigator
.
geolocation
.
clearWatch
(
this
.
watchPositionId
);
}
}
}
}
// Sets the state for the changed position
setCurrentPosition
(
position
){
setCurrentPosition
(
position
){
this
.
setState
({
this
.
setState
({
ownLat
:
position
.
coords
.
latitude
,
ownLat
:
position
.
coords
.
latitude
,
ownLng
:
position
.
coords
.
longitude
,
ownLng
:
position
.
coords
.
longitude
,
marker
:
{
geojsonLayer
:
{
features
:
[
"
type
"
:
"
FeatureCollection
"
,
{
"
latitude
"
:
""
,
geometry
:
{
"
longitude
"
:
""
,
type
:
"
Point
"
,
"
timestamp
"
:
""
,
coordinates
:
[
"
features
"
:
[{
position
.
coords
.
latitude
,
"
type
"
:
"
Feature
"
,
position
.
coords
.
longitude
"
properties
"
:
{},
]
"
geometry
"
:
{
}
"
type
"
:
"
Point
"
,
}
"
coordinates
"
:
[
position
.
coords
.
latitude
,
position
.
coords
.
longitude
]
]
}
}]
}
}
});
});
console
.
log
(
this
.
state
.
marker
)
console
.
log
(
this
.
state
.
geojsonLayer
.
coordinates
)
}
}
getCurrentPosition
(
callback
){
getCurrentPosition
(
callback
){
...
@@ -104,7 +104,7 @@ class UserMap extends Component {
...
@@ -104,7 +104,7 @@ class UserMap extends Component {
this
.
watchPositionId
=
navigator
.
geolocation
.
watchPosition
((
position
)
=>
{
this
.
watchPositionId
=
navigator
.
geolocation
.
watchPosition
((
position
)
=>
{
//success
//success
if
(
position
!=
null
){
if
(
position
!=
null
){
callback
(
position
);
callback
(
position
);
}
}
},
(
error
)
=>
{
},
(
error
)
=>
{
console
.
log
(
error
);
console
.
log
(
error
);
...
@@ -112,57 +112,22 @@ class UserMap extends Component {
...
@@ -112,57 +112,22 @@ class UserMap extends Component {
}
}
}
}
positionToGeoJSON
(
position
){
let
geoJSON
=
{
type
:
"
Feature
"
,
properties
:
{},
geometry
:
{
type
:
"
Point
"
,
coordinates
:
[
position
.
coords
.
longitude
,
position
.
coords
.
latitude
]
}
}
return
JSON
.
stringify
(
geoJSON
);
}
mockGeoJSON
(){
return
(
JSON
.
stringify
({
type
:
"
FeatureCollection
"
,
latitude
:
""
,
longitude
:
""
,
timestamp
:
""
,
features
:
[{
type
:
"
Feature
"
,
properties
:
{},
geometry
:
{
type
:
"
Point
"
,
coordinates
:
[
62.2416479
,
25.7597186
]
}
}]
}))
}
render
()
{
render
()
{
return
(
return
(
<
Map
className
=
'
map
'
center
=
{
this
.
props
.
position
}
zoom
=
{
this
.
props
.
zoom
}
>
<
Map
className
=
'
map
'
center
=
{
this
.
props
.
position
}
zoom
=
{
this
.
props
.
zoom
}
>
<
TileLayer
<
TileLayer
attribution
=
'
© <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>
'
attribution
=
'
© <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>
'
url
=
{
this
.
props
.
mapUrl
}
url
=
{
this
.
props
.
mapUrl
}
/
>
/
>
<
DrawTools
position
=
{
this
.
props
.
position
}
/
>
<
DrawTools
position
=
{
this
.
props
.
position
}
/
>
<
Marker
position
=
{
this
.
props
.
position
}
>
<
Marker
position
=
{
this
.
props
.
position
}
>
<
Popup
maxWidth
=
"
600px
"
>
<
Popup
maxWidth
=
"
600px
"
>
<
img
src
=
"
wimma.png
"
alt
=
"
Wimma Lab
"
width
=
"
600px
"
/>
<
img
src
=
"
wimma.png
"
alt
=
"
Wimma Lab
"
width
=
"
600px
"
/>
<
/Popup
>
<
/Popup
>
<
/Marker
>
<
/Marker
>
{
this
.
state
.
ownLat
!==
null
&&
<
Marker
position
=
{[
this
.
state
.
ownLat
,
this
.
state
.
ownLng
]}
>
{
this
.
state
.
ownLat
!==
null
&&
<
Marker
position
=
{[
this
.
state
.
ownLat
,
this
.
state
.
ownLng
]}
>
<
Popup
>
<
/Marker>
}
User
'
s real position.<br />
<
GeoJSON
key
=
{
JSON
.
stringify
(
this
.
state
.
geojsonLayer
)}
data
=
{
this
.
state
.
geojsonLayer
}
/>
</Popup>
</Marker>}
<
/Map
>
<
/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