diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..da07aa6 Binary files /dev/null and b/.DS_Store differ diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/app/assets/images/.DS_Store differ diff --git a/app/javascript/app/views/home/Index.vue b/app/javascript/app/views/home/Index.vue index 185d184..78f2841 100644 --- a/app/javascript/app/views/home/Index.vue +++ b/app/javascript/app/views/home/Index.vue @@ -1,36 +1,54 @@ \ No newline at end of file diff --git a/app/javascript/app/views/location/Index.vue b/app/javascript/app/views/location/Index.vue index 4acb1ca..a7b4c43 100644 --- a/app/javascript/app/views/location/Index.vue +++ b/app/javascript/app/views/location/Index.vue @@ -1,11 +1,25 @@ @@ -24,9 +38,11 @@ export default { data() { return { - lat: null, lon: null, + lat: null, radius: null, + location: null, + loading: true } }, computed: { @@ -49,28 +65,29 @@ var map = new Map({ layers: [raster, vector], - target: 'map', + target: 'map-loc', view: new View({ center: fromLonLat([this.lon, this.lat]), zoom: 16 }) }); - var draw; // global so we can remove it later - function addInteraction() { - var geometryFunction; - draw = new Draw({ - source: source, - type: 'Circle', - geometryFunction: geometryFunction - }); - map.addInteraction(draw); - } + if (this.isUserLoggedIn()) { + var draw; // global so we can remove it later + function addInteraction() { + var geometryFunction; + draw = new Draw({ + source: source, + type: 'Circle', + geometryFunction: geometryFunction + }); + map.addInteraction(draw); + } - addInteraction(); + addInteraction(); - draw.on('drawend', async () => { - /* + draw.on('drawend', async () => { + /* WARNING: HACK!!!!!!!!!!! BAD HACK!!!!!!!!!!!!!!!! BAD!!!!!!!!!!!!!!!!!!!!! @@ -80,32 +97,33 @@ We have to wait for a change, probably. So let's do that. Probably. */ - // Save the current feature array length - let cur = vector.getSource().getFeatures().length; - - let tries = 0; - // Has the length changed yet? - while (vector.getSource().getFeatures().length === cur && - tries <= 40 /* 40*25=1000; 1s */) { - await new Promise(r => setTimeout(r, 25)); - tries++; - console.log(tries); - } - - let features = vector.getSource().getFeatures(); - let feature = features[features.length - 1]; - console.log(feature); - console.log(feature.values_.geometry); - - let radius = feature.values_.geometry.getRadius(); - let center = feature.values_.geometry.transform('EPSG:3857', 'EPSG:4326').getCenter(); - let lon = center[0]; - let lat = center[1]; - - console.log("lon: " + lon); - console.log("lat: " + lat); - console.log("radius: " + radius); - }); + // Save the current feature array length + let cur = vector.getSource().getFeatures().length; + + let tries = 0; + // Has the length changed yet? + while (vector.getSource().getFeatures().length === cur && + tries <= 40 /* 40*25=1000; 1s */) { + await new Promise(r => setTimeout(r, 25)); + tries++; + console.log(tries); + } + + let features = vector.getSource().getFeatures(); + let feature = features[features.length - 1]; + console.log(feature); + console.log(feature.values_.geometry); + + let radius = feature.values_.geometry.getRadius(); + let center = feature.values_.geometry.transform('EPSG:3857', 'EPSG:4326').getCenter(); + let lon = center[0]; + let lat = center[1]; + + console.log("lon: " + lon); + console.log("lat: " + lat); + console.log("radius: " + radius); + }); + } let coordinate = fromLonLat([this.lon, this.lat]); source.addFeature(new Feature(new Circle(coordinate, this.radius))); @@ -117,11 +135,18 @@ return response.json(); }) .then((data) => { + this.location = data; + this.lon = parseFloat(data.long); this.lat = parseFloat(data.lat); this.radius = parseFloat(data.radius); - this.setupMap(); + this.loading = false; + + + this.$nextTick(() => { + this.setupMap(); + }); }); } } diff --git a/app/javascript/app/views/location/New.vue b/app/javascript/app/views/location/New.vue index a2168c3..fb8437e 100644 --- a/app/javascript/app/views/location/New.vue +++ b/app/javascript/app/views/location/New.vue @@ -1,8 +1,12 @@ @@ -159,7 +163,7 @@ var map = new Map({ layers: [raster, vector], - target: 'map', + target: 'map-loc-new', view: new View({ center: [-11000000, 4600000], zoom: 4 diff --git a/app/javascript/packs/vue.js b/app/javascript/packs/vue.js index 1ed8719..a11cdb6 100644 --- a/app/javascript/packs/vue.js +++ b/app/javascript/packs/vue.js @@ -19,6 +19,10 @@ import 'vuelayers/lib/style.css'; Vue.use(VueLayers); Vue.use(BootstrapVue); +Vue.prototype.isUserLoggedIn = () => { + return document.head.querySelector("meta[name='user-logged-in']").content === 'true'; +}; + document.addEventListener('DOMContentLoaded', () => { if (document.getElementById('app-spa') !== null) { const app = new Vue({ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6cd67b4..2edc2ca 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,12 +1,20 @@ + + App + <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all' %> <%= stylesheet_pack_tag 'vue' %> + + + + + diff --git a/public/.DS_Store b/public/.DS_Store new file mode 100644 index 0000000..c22a756 Binary files /dev/null and b/public/.DS_Store differ