Skip to content
Snippets Groups Projects
Commit 3cddb452 authored by L4929's avatar L4929
Browse files

Text box functionality, still not fully functional; Remove zoom control at top...

Text box functionality, still not fully functional; Remove zoom control at top left corner; Add max and min zooms; Non-functional fix to dragging out of bounds
parent 8e349c9e
No related branches found
No related tags found
3 merge requests!21Development,!15Get game creation to user-marker-database-interactions,!10Add text
/*
Do not touch classes with 'leaflet' in them!
They're Leaflet's own classes
*/
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
...@@ -151,16 +156,25 @@ div.login button:hover { ...@@ -151,16 +156,25 @@ div.login button:hover {
-moz-user-select: text; -moz-user-select: text;
-ms-user-select: text; -ms-user-select: text;
user-select: text; user-select: text;
pointer-events: auto; pointer-events: auto;
cursor: auto;
}
.leaflet-tooltip-top:before,
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
pointer-events: auto;
} }
/* Editing editable tooltips */ /* Editing editable tooltips */
.editable { .editable {
cursor: text; cursor: text; /* the cursor icon doesn't change by default when hovering on top of the text; overriding */
min-width: 120px; min-width: 120px;
min-height: 18px; min-height: 18px;
} }
/* placeholder text for tooltip */
[contenteditable=true]:empty:before { [contenteditable=true]:empty:before {
content: attr(placeholder); content: attr(placeholder);
display: block; /* For Firefox */ display: block; /* For Firefox */
......
...@@ -16,12 +16,13 @@ L.Draw.MarkerTextBox = L.Draw.Marker.extend({ ...@@ -16,12 +16,13 @@ L.Draw.MarkerTextBox = L.Draw.Marker.extend({
options: { options: {
icon: emptyicon, icon: emptyicon,
repeatMode: false, repeatMode: false,
interactive: true
}, },
initialize: function (map, options) { initialize: function (map, options) {
this.type = 'textbox'; // important to have a unique type, so that it won't get mixed up with other elements this.type = 'textbox'; // important to have a unique type, so that it won't get mixed up with other elements
this.featureTypeCode = 'textbox'; this.featureTypeCode = 'textbox';
L.Draw.Feature.prototype.initialize.call(this, map, options); L.Draw.Feature.prototype.initialize.call(this, map, options);
} }
}); });
L.DrawToolbar.include ({ L.DrawToolbar.include ({
...@@ -47,7 +48,7 @@ L.DrawToolbar.include ({ ...@@ -47,7 +48,7 @@ L.DrawToolbar.include ({
handler: new L.Draw.Marker(map, this.options.marker), handler: new L.Draw.Marker(map, this.options.marker),
title: L.drawLocal.draw.toolbar.buttons.marker title: L.drawLocal.draw.toolbar.buttons.marker
},{ },{
enabled: this.options.marker, enabled: this.options.marker,
handler: new L.Draw.MarkerTextBox(map, this.options.marker), handler: new L.Draw.MarkerTextBox(map, this.options.marker),
title: 'Write text' title: 'Write text'
}]; }];
...@@ -55,6 +56,13 @@ L.DrawToolbar.include ({ ...@@ -55,6 +56,13 @@ L.DrawToolbar.include ({
}); });
class DrawTools extends Component { class DrawTools extends Component {
constructor(props){
super(props);
this.state = {
geoJSONAll: [] // property for all GeoJSON data in the map
}
}
_onCreated = (e) => { _onCreated = (e) => {
// check if a drawn polyline has just one point in it // check if a drawn polyline has just one point in it
if (e.layerType === 'polyline' && e.layer.getLatLngs().length === 1) { if (e.layerType === 'polyline' && e.layer.getLatLngs().length === 1) {
...@@ -62,13 +70,26 @@ class DrawTools extends Component { ...@@ -62,13 +70,26 @@ class DrawTools extends Component {
return; return;
} }
// binding text field to textbox // binding text field to textbox
// clicking on tooltip fires the marker's click handler
if (e.layerType === 'textbox') { if (e.layerType === 'textbox') {
e.layer.bindTooltip('<div class="editable" contenteditable="true" placeholder="Type here"></div>', {permanent: true}); e.layer.bindTooltip('<div class="editable" contenteditable="true" placeholder="Click here and type"></div>', {permanent: true, direction: 'center', interactive: true});
} }
// turning layer data to geoJSON // turning layer data to GeoJSON
let layer = e.layer; let layer = e.layer;
let geoJSON = layer.toGeoJSON(); this.makeGeoJSON(e.layer);
console.log(JSON.stringify(geoJSON, null, 4)); // makes the output readable in the console
/* Original GeoJSON code. Uncomment if needed
let geoJSON = layer.toGeoJSON();
console.log(JSON.stringify(geoJSON, null, 4)); // makes the output readable in the console
*/
}
makeGeoJSON = (e) => {
let geoJSON = e.toGeoJSON();
let newAllGeoJSON = this.state.geoJSONAll;
newAllGeoJSON.push(geoJSON);
console.log(JSON.stringify(newAllGeoJSON, null, 4));
this.setState({geoJSONAll: newAllGeoJSON});
} }
render() { render() {
......
...@@ -92,9 +92,9 @@ class UserMap extends Component { ...@@ -92,9 +92,9 @@ class UserMap extends Component {
minZoom='7' minZoom='7'
maxZoom='17' maxZoom='17'
// onzoomend={this.testers} // getting the zoom level // onzoomend={this.testers} // getting the zoom level
maxBounds={this.props.bounds} maxBounds={this.props.bounds} // maxBounds settings don't work for now, for some reason
maxBoundsViscosity='1' maxBoundsViscosity='1'
zoomControl={false} /* remove the default zoom control button at the top left corner */> zoomControl={false} /* remove the default zoom control button at the top left corner */ >
<TileLayer <TileLayer
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}
......
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