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
0dd90a7e
Commit
0dd90a7e
authored
5 years ago
by
Taneli Riihimäki
Browse files
Options
Downloads
Patches
Plain Diff
WIP drawing layer to the server / back
parent
a7c23d50
No related branches found
No related tags found
1 merge request
!21
Development
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/DrawTools.js
+1
-0
1 addition, 0 deletions
src/components/DrawTools.js
src/components/UserMap.js
+34
-42
34 additions, 42 deletions
src/components/UserMap.js
with
35 additions
and
42 deletions
src/components/DrawTools.js
+
1
−
0
View file @
0dd90a7e
...
@@ -10,6 +10,7 @@ class DrawTools extends Component {
...
@@ -10,6 +10,7 @@ class DrawTools extends Component {
let
layer
=
e
.
layer
;
let
layer
=
e
.
layer
;
let
geoJSON
=
layer
.
toGeoJSON
();
let
geoJSON
=
layer
.
toGeoJSON
();
console
.
log
(
JSON
.
stringify
(
geoJSON
,
null
,
4
));
// makes the output readable in the console
console
.
log
(
JSON
.
stringify
(
geoJSON
,
null
,
4
));
// makes the output readable in the console
this
.
props
.
setCurrentPosition
(
geoJSON
);
}
}
render
()
{
render
()
{
...
...
This diff is collapsed.
Click to expand it.
src/components/UserMap.js
+
34
−
42
View file @
0dd90a7e
...
@@ -3,8 +3,6 @@ import {
...
@@ -3,8 +3,6 @@ import {
Map
,
Map
,
TileLayer
,
TileLayer
,
Marker
,
Marker
,
Popup
,
LayersControl
,
GeoJSON
GeoJSON
}
from
'
react-leaflet
'
}
from
'
react-leaflet
'
import
DrawTools
from
'
./DrawTools
'
import
DrawTools
from
'
./DrawTools
'
...
@@ -19,27 +17,18 @@ class UserMap extends Component {
...
@@ -19,27 +17,18 @@ class UserMap extends Component {
mapUrl
:
'
https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg
'
,
mapUrl
:
'
https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg
'
,
geojsonLayer
:
{
geojsonLayer
:
{
"
type
"
:
"
FeatureCollection
"
,
"
type
"
:
"
FeatureCollection
"
,
"
latitude
"
:
""
,
"
features
"
:
[]
"
longitude
"
:
""
,
"
timestamp
"
:
""
,
"
features
"
:
[{
"
type
"
:
"
Feature
"
,
"
properties
"
:
{},
"
geometry
"
:
{
"
type
"
:
"
Point
"
,
"
coordinates
"
:
[
25.7597186
,
62.20416479
]
}
}]
}
}
}
}
this
.
setCurrentPosition
=
this
.
setCurrentPosition
.
bind
(
this
);
this
.
watchPositionId
=
null
;
this
.
watchPositionId
=
null
;
}
}
componentDidMount
(){
componentDidMount
(){
this
.
getCurrentPosition
((
position
)
=>
{
this
.
getCurrentPosition
((
position
)
=>
{
this
.
setCurrentPosition
(
position
);
//
this.setCurrentPosition(position);
});
});
//sendGeoJSON()
//sendGeoJSON()
}
}
...
@@ -52,7 +41,7 @@ class UserMap extends Component {
...
@@ -52,7 +41,7 @@ class UserMap extends Component {
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
'
Content-Type
'
:
'
application/json
'
},
},
body
:
JSON
.
stringify
(
this
.
state
.
geojsonLayer
)
body
:
this
.
state
.
geojsonLayer
})
})
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
res
.
json
())
.
then
(
result
=>
console
.
log
(
result
))
.
then
(
result
=>
console
.
log
(
result
))
...
@@ -64,27 +53,35 @@ class UserMap extends Component {
...
@@ -64,27 +53,35 @@ class UserMap extends Component {
navigator
.
geolocation
.
clearWatch
(
this
.
watchPositionId
);
navigator
.
geolocation
.
clearWatch
(
this
.
watchPositionId
);
}
}
}
}
// Sets the state for the changed position
// // Sets the state for the changed position
setCurrentPosition
(
position
){
// setCurrentPosition(position){
// this.setState({
// ownLat: position.coords.latitude,
// ownLng: position.coords.longitude,
// geojsonLayer: {
// "type": "FeatureCollection",
// "latitude": "",
// "longitude": "",
// "timestamp": "",
// "features": [{
// "type": "Feature",
// "properties": {},
// "geometry": {
// "type": "Point",
// "coordinates": [ position.coords.latitude, position.coords.longitude ]
// }
// }]
// }
// });
// console.log(this.state.geojsonLayer.coordinates)
// }
setCurrentPosition
(
data
){
this
.
setState
({
this
.
setState
({
ownLat
:
position
.
coords
.
latitude
,
...
this
.
state
,
ownLng
:
position
.
coords
.
longitude
,
geojsonLayer
:
data
geojsonLayer
:
{
"
type
"
:
"
FeatureCollection
"
,
"
latitude
"
:
""
,
"
longitude
"
:
""
,
"
timestamp
"
:
""
,
"
features
"
:
[{
"
type
"
:
"
Feature
"
,
"
properties
"
:
{},
"
geometry
"
:
{
"
type
"
:
"
Point
"
,
"
coordinates
"
:
[
position
.
coords
.
latitude
,
position
.
coords
.
longitude
]
}
}]
}
});
});
console
.
log
(
this
.
state
.
geojsonLayer
.
coordinates
)
console
.
log
(
"
User mapin statessa oleva geojson:
"
+
JSON
.
stringify
(
this
.
state
.
geojsonLayer
)
)
}
}
getCurrentPosition
(
callback
){
getCurrentPosition
(
callback
){
...
@@ -119,17 +116,12 @@ class UserMap extends Component {
...
@@ -119,17 +116,12 @@ class UserMap extends Component {
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
}
setCurrentPosition
=
{
this
.
setCurrentPosition
}
/
>
<
Marker
position
=
{
this
.
props
.
position
}
>
<
Popup
maxWidth
=
"
600px
"
>
<
img
src
=
"
wimma.png
"
alt
=
"
Wimma Lab
"
width
=
"
600px
"
/>
<
/Popup
>
<
/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
]}
>
<
/Marker>
}
<
/Marker>
}
<
GeoJSON
key
=
{
JSON
.
stringify
(
this
.
state
.
geojsonLayer
)}
data
=
{
this
.
state
.
geojsonLayer
}
/>
<
GeoJSON
key
=
{
JSON
.
stringify
(
this
.
state
.
geojsonLayer
)}
data
=
{
this
.
state
.
geojsonLayer
}
/>
<
/Map
>
<
/Map
>
);
);
// this.state.geojsonLayer
}
}
}
}
...
...
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