Guide drawing

This commit is contained in:
portree_kid 2020-06-29 09:08:53 +02:00
parent b9a34df117
commit 94779a1686
10 changed files with 427 additions and 17 deletions

View File

@ -4,7 +4,7 @@
<script lang="js"> <script lang="js">
import L from 'leaflet' import L from 'leaflet'
export default { export default {
name: 'edit-layer', name: 'airport-layer',
props: [], props: [],
mounted () { mounted () {
this.add() this.add()

View File

@ -1,8 +1,8 @@
<template> <template>
<div id="EditBar"> <div id="EditBar">
<Upload :visible.sync="uploadVisible" ref="upload"></Upload> <Upload :visible.sync="uploadVisible" ref="upload"></Upload>
<EditButton icon="fas fa-th" v-on:click="zoomin" :show="true" tooltip="Zoomin"></EditButton> <ZoomButton icon="fas fa-th" v-on:click="zoomin" :show="true" tooltip="Zoomin"></ZoomButton>
<EditButton icon="fas fa-th-large" v-on:click="zoomout" :show="!editing" tooltip="Zoomout"></EditButton> <ZoomButton icon="fas fa-th-large" v-on:click="zoomout" :show="!editing" tooltip="Zoomout"></ZoomButton>
<EditButton icon="fas fa-upload" v-on:click="upload" :show="!editing" tooltip="Upload"></EditButton> <EditButton icon="fas fa-upload" v-on:click="upload" :show="!editing" tooltip="Upload"></EditButton>
<EditButton icon="fas fa-plane" v-on:click="test" :show="!editing" tooltip="Export"></EditButton> <EditButton icon="fas fa-plane" v-on:click="test" :show="!editing" tooltip="Export"></EditButton>
@ -63,6 +63,7 @@
<script lang="js"> <script lang="js">
/* eslint-disable */ /* eslint-disable */
import EditButton from './EditButton' import EditButton from './EditButton'
import ZoomButton from './ZoomButton';
import Upload from './Upload' import Upload from './Upload'
import Vue from 'vue' import Vue from 'vue'
@ -71,7 +72,7 @@
const fs = require('fs'); const fs = require('fs');
export default { export default {
components: { EditButton, Upload }, components: { EditButton, Upload, ZoomButton },
data () { data () {
return {isEditing: false, uploadVisible: false, centerDialogVisible: false, saveDialogVisible: false, checkDialogVisible: false, checking: false, progress: 0, max: 0} return {isEditing: false, uploadVisible: false, centerDialogVisible: false, saveDialogVisible: false, checkDialogVisible: false, checking: false, progress: 0, max: 0}
}, },
@ -92,19 +93,20 @@
this.$parent.$parent.zoomUpdated(14) this.$parent.$parent.zoomUpdated(14)
}, },
edit () { edit () {
this.editing = true this.isEditing = true
this.$parent.$parent.$refs.map.mapObject.options.minZoom = 13; this.$emit('edit')
this.$parent.$parent.$refs.editLayer.enableEdit()
}, },
undoFirst () { undoFirst () {
this.editing = false this.isEditing = false
this.$emit('edit')
this.centerDialogVisible = false this.centerDialogVisible = false
this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1; this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1;
this.$parent.$parent.$refs.editLayer.disableEdit() this.$parent.$parent.$refs.editLayer.disableEdit()
this.$parent.$parent.$refs.editLayer.reload(true) this.$parent.$parent.$refs.editLayer.reload(true)
}, },
undoLast () { undoLast () {
this.editing = false this.isEditing = false
this.$emit('edit')
this.centerDialogVisible = false this.centerDialogVisible = false
this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1; this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1;
this.$parent.$parent.$refs.editLayer.disableEdit() this.$parent.$parent.$refs.editLayer.disableEdit()
@ -112,10 +114,11 @@
}, },
save () { save () {
this.$parent.$parent.$refs.editLayer.stopDrawing() this.$parent.$parent.$refs.editLayer.stopDrawing()
this.editing = false this.isEditing = false
this.$emit('edit')
this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1; this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1;
Vue.set(this, 'saveDialogVisible', true) Vue.set(this, 'saveDialogVisible', true)
this.editing = false this.$emit('edit')
Vue.nextTick( function () { Vue.nextTick( function () {
setTimeout( this.saveDefered.bind(this), 100); setTimeout( this.saveDefered.bind(this), 100);
}, this) }, this)

View File

@ -17,7 +17,6 @@
--> -->
<!--<l-marker :lat-lng="marker"></l-marker>--> <!--<l-marker :lat-lng="marker"></l-marker>-->
<LeafletSidebar></LeafletSidebar> <LeafletSidebar></LeafletSidebar>
<EditBar></EditBar>
<AiLayer ref="aiLayer"></AiLayer> <AiLayer ref="aiLayer"></AiLayer>
<PavementLayer ref="pavementLayer"></PavementLayer> <PavementLayer ref="pavementLayer"></PavementLayer>
<!--<ThresholdLayer ref="thresholdLayer"></ThresholdLayer>--> <!--<ThresholdLayer ref="thresholdLayer"></ThresholdLayer>-->
@ -33,6 +32,9 @@
></l-circle> ></l-circle>
</l-layer-group> </l-layer-group>
<EditLayer ref="editLayer"></EditLayer> <EditLayer ref="editLayer"></EditLayer>
<ToolLayer ref="toolLayer"></ToolLayer>
<EditBar ref="editBar" @edit="onEdit"></EditBar>
<ToolBar ref="toolBar"></ToolBar>
</l-map> </l-map>
</template> </template>
@ -42,7 +44,9 @@
import LeafletSidebar from './LeafletSidebar' import LeafletSidebar from './LeafletSidebar'
import AiLayer from './AiLayer' import AiLayer from './AiLayer'
import EditBar from './EditBar' import EditBar from './EditBar'
import ToolBar from './ToolBar'
import EditLayer from './EditLayer' import EditLayer from './EditLayer'
import ToolLayer from './ToolLayer'
import PavementLayer from './PavementLayer' import PavementLayer from './PavementLayer'
import ThresholdLayer from './ThresholdLayer' import ThresholdLayer from './ThresholdLayer'
import L from 'leaflet' import L from 'leaflet'
@ -57,7 +61,7 @@
}) })
export default { export default {
name: 'flightgear-map', name: 'flightgear-map',
components: { LMap, LTileLayer, LMarker, LCircle, LeafletSidebar, AiLayer, EditBar, EditLayer, PavementLayer, LLayerGroup, LControl, ThresholdLayer }, components: { LMap, LTileLayer, LMarker, LCircle, LeafletSidebar, AiLayer, EditBar, ToolBar, EditLayer, PavementLayer, LLayerGroup, LControl, ThresholdLayer, ToolLayer },
props: [], props: [],
mounted () { mounted () {
this.$store.dispatch('getAirports') this.$store.dispatch('getAirports')
@ -76,8 +80,12 @@
*/ */
this.editingAirport = airportsToLoad[0] this.editingAirport = airportsToLoad[0]
} }
this.$refs.editLayer.setVisible(this.zoom >= 12) if (this.$refs.editLayer) {
this.$refs.airportLayer.setVisible(this.zoom < 12) this.$refs.editLayer.setVisible(this.zoom >= 12)
}
if (this.$refs.airportLayer) {
this.$refs.airportLayer.setVisible(this.zoom < 12)
}
// console.log(this.groundnet) // console.log(this.groundnet)
} }
@ -97,6 +105,11 @@
} }
}, },
methods: { methods: {
onEdit (event) {
this.$refs.map.mapObject.options.minZoom = 13
this.$refs.editLayer.enableEdit()
this.$refs.toolBar.setEdit(this.$refs.editBar.isEditing)
},
editAirport () { editAirport () {
if (this.editingAirport) { if (this.editingAirport) {
let airportsToLoad = this.$store.state.Airports.airports let airportsToLoad = this.$store.state.Airports.airports
@ -197,6 +210,9 @@
zoom: function () { zoom: function () {
return this.$store.state.Settings.zoom return this.$store.state.Settings.zoom
}, },
isEditing: function () {
return this.$refs.editLayer !== undefined && this.$refs.editLayer.editing
},
center: function () { center: function () {
return this.$store.state.Settings.center return this.$store.state.Settings.center
} }

View File

@ -0,0 +1,55 @@
<template>
<div id="ToolBar">
<ToolButton
icon="fas fa-draw-polygon"
v-on:click="drawPolyline"
:show="editing"
tooltip="Draw Guidline"
></ToolButton>
</div>
</template>
<script lang="js">
/* eslint-disable */
import ToolButton from './ToolButton'
import Vue from 'vue'
import fileUrl from 'file-url'
const path = require('path')
const fs = require('fs');
export default {
components: { ToolButton },
data () {
return {isEditing: false}
},
created () {
},
methods: {
drawPolyline () {
this.$parent.$parent.$refs.toolLayer.stopDrawing()
this.$parent.$parent.$refs.toolLayer.drawPolyline()
},
setEdit (edit) {
this.isEditing = edit;
if(!this.isEditing) {
this.$parent.$parent.$refs.toolLayer.stopDrawing()
}
}
},
computed: {
editing: {
// getter
get: function () {
console.log(`Getting Visible : ${this.isEditing}`)
return this.isEditing
},
// setter
set: function (newValue) {
this.isEditing = newValue
console.log(`Setting Visible : ${this.isEditing}`)
}
}
}
}
</script>

View File

@ -0,0 +1,64 @@
<template></template>
<script lang="js">
import L from 'leaflet'
import '@fortawesome/fontawesome-free/css/all.css'
import ToolControl from '../leaflet/ToolControl.js'
export default {
name: 'edit-bar',
props: {
icon: String,
show: Boolean,
tooltip: String
},
watch: {
show: function (newVal, oldVal) { // watch it
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
if (newVal) {
this.add()
} else {
this.remove()
}
}
},
mounted () {
console.debug(L)
console.debug(ToolControl)
this.add()
},
beforeDestroy () {
this.remove()
},
data () {
return {
}
},
methods: {
deferredMountedTo (parent) {
this.editbutton = new L.ToolControl({html: `<i class="${this.icon}"></i>`, callback: this.click, tooltip: this.tooltip})
if (this.show) {
parent.addControl(this.editbutton)
}
},
click () {
// console.log(parent)
this.$emit('click')
},
remove () {
if (this.editbutton) {
this.$parent.$parent.mapObject.removeControl(this.editbutton)
}
},
add () {
if (this.$parent.$parent._isMounted) {
this.deferredMountedTo(this.$parent.$parent.mapObject)
}
}
},
computed: {
}
}
</script>
<style scoped lang="scss">
</style>

View File

@ -0,0 +1,69 @@
<!--
Copyright 2020 Keith Paterson
This file is part of FG Airports.
FG Airports is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
FG Airports is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with FG Airports. If not, see http://www.gnu.org/licenses/.
-->
<template></template>
<script lang="js">
/* eslint-disable */
import {LMap, LMarker} from 'vue2-leaflet'
import L from 'leaflet'
import LEdit from 'leaflet-editable/src/Leaflet.Editable.js'
export default {
name: 'tool-layer',
props: [],
mounted () {
this.add()
},
beforeDestroy () {
this.remove()
},
data () {
return {
}
},
methods: {
deferredMountedTo (parent) {
this.toolLayerGroup = L.layerGroup();
this.toolLayerGroup.addTo(this.$parent.mapObject)
},
remove () {
if (this.sidebar) {
this.$parent.removeLayer(this.sidebar)
}
},
add () {
if (this.$parent._isMounted) {
this.deferredMountedTo(this.$parent.mapObject)
}
},
stopDrawing () {
this.$parent.mapObject.editTools.stopDrawing()
this.toolLayerGroup.eachLayer((layer) => {
layer.removeFrom(this.toolLayerGroup);
});
},
drawPolyline () {
var polyLine = this.$parent.mapObject.editTools.startPolyline(undefined, {color: 'green'})
polyLine.addTo(this.toolLayerGroup)
polyLine.toolLayerGroup = this.toolLayerGroup;
},
},
computed: {
}
}
</script>
<style scoped lang="scss">
</style>

View File

@ -0,0 +1,64 @@
<template></template>
<script lang="js">
import L from 'leaflet'
import '@fortawesome/fontawesome-free/css/all.css'
import EditBar from '../leaflet/ZoomControl.js'
export default {
name: 'edit-bar',
props: {
icon: String,
show: Boolean,
tooltip: String
},
watch: {
show: function (newVal, oldVal) { // watch it
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
if (newVal) {
this.add()
} else {
this.remove()
}
}
},
mounted () {
console.debug(L)
console.debug(EditBar)
this.add()
},
beforeDestroy () {
this.remove()
},
data () {
return {
}
},
methods: {
deferredMountedTo (parent) {
this.editbutton = new L.ZoomControl({html: `<i class="${this.icon}"></i>`, callback: this.click, tooltip: this.tooltip})
if (this.show) {
parent.addControl(this.editbutton)
}
},
click () {
// console.log(parent)
this.$emit('click')
},
remove () {
if (this.editbutton) {
this.$parent.$parent.mapObject.removeControl(this.editbutton)
}
},
add () {
if (this.$parent.$parent._isMounted) {
this.deferredMountedTo(this.$parent.$parent.mapObject)
}
}
},
computed: {
}
}
</script>
<style scoped lang="scss">
</style>

View File

@ -2,7 +2,7 @@
L.EditControl = L.Control.extend({ L.EditControl = L.Control.extend({
options: { options: {
position: 'topleft', position: 'topright',
callback: null, callback: null,
kind: '', kind: '',
html: '<i class="fas fa-draw-polygon"></i>', html: '<i class="fas fa-draw-polygon"></i>',
@ -44,6 +44,33 @@ L.NewMarkerControl = L.EditControl.extend({
callback: null, callback: null,
kind: 'marker', kind: 'marker',
html: '🖈' html: '🖈'
} },
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'),
link = L.DomUtil.create('a', '', container);
link.href = '#';
link.title = this.options.tooltip;
link.innerHTML = this.options.html;
link.callback = this.options.callback;
link.addEventListener('click',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
link.addEventListener('mousedown',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
window.LAYER = this.callback.call(map.editTools);
}, false);
link.addEventListener('mouseup',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
return container;
}
}); });

View File

@ -0,0 +1,36 @@
/* eslint-disable */
L.ToolControl = L.Control.extend({
options: {
position: 'bottomright',
callback: null,
kind: 'marker',
html: '🖈'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'),
link = L.DomUtil.create('a', '', container);
link.href = '#';
link.title = this.options.tooltip;
link.innerHTML = this.options.html;
link.callback = this.options.callback;
link.addEventListener('click',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
link.addEventListener('mousedown',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
window.LAYER = this.callback.call(map.editTools);
}, false);
link.addEventListener('mouseup',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
return container;
}
});

View File

@ -0,0 +1,76 @@
/* eslint-disable */
L.ZoomControl = L.Control.extend({
options: {
position: 'topleft',
callback: null,
kind: '',
html: '<i class="fas fa-draw-polygon"></i>',
tooltip: 'tooltip'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'),
link = L.DomUtil.create('a', '', container);
link.href = '#';
link.title = this.options.tooltip;
link.innerHTML = this.options.html;
link.callback = this.options.callback;
link.addEventListener('click',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
link.addEventListener('mousedown',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
window.LAYER = this.callback.call(map.editTools);
}, false);
link.addEventListener('mouseup',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
return container;
}
});
L.NewMarkerControl = L.EditControl.extend({
options: {
position: 'topright',
callback: null,
kind: 'marker',
html: '🖈'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'),
link = L.DomUtil.create('a', '', container);
link.href = '#';
link.title = this.options.tooltip;
link.innerHTML = this.options.html;
link.callback = this.options.callback;
link.addEventListener('click',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
link.addEventListener('mousedown',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
window.LAYER = this.callback.call(map.editTools);
}, false);
link.addEventListener('mouseup',function (event) {
event.stopPropagation();
event.preventDefault();
event.stopImmediatePropagation();
}, false);
return container;
}
});