Skip to content
Snippets Groups Projects
Commit 0dd90a7e authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

WIP drawing layer to the server / back

parent a7c23d50
No related branches found
No related tags found
1 merge request!21Development
...@@ -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() {
......
...@@ -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='&copy; <a href="https://www.maanmittauslaitos.fi/">Maanmittauslaitos</a>' attribution='&copy; <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
} }
} }
......
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