-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
473 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
<template> | ||
<div> | ||
Hello! I am / :) | ||
<div class="container pt-4"> | ||
<h4>Welcome to Inclusive Access!</h4> | ||
<p>Please select a location to continue, or <router-link to="/location/new">create a location</router-link>:</p> | ||
<div v-if="loading"> | ||
Please wait for the locations to load... | ||
</div> | ||
<div v-else> | ||
<div v-if="data.length < 1"> | ||
There are no locations to display. | ||
</div> | ||
<ul v-else> | ||
<li | ||
v-for="loc in data" | ||
:key="'location-' + loc.id" | ||
> | ||
<router-link | ||
:to="'/location/' + loc.id" | ||
> | ||
{{ loc.name }} | ||
</router-link> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
loading: true, | ||
data: [] | ||
} | ||
}, | ||
mounted() { | ||
console.log("fetching"); | ||
fetch('/locations.json') | ||
.then((response) => { | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
this.data = data; | ||
this.loading = false; | ||
}); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<template> | ||
<div class="pt-4"> | ||
<div id="map"></div> | ||
</div> | ||
</template> | ||
<style> | ||
#map { | ||
height: calc(100vh - 200px); | ||
} | ||
</style> | ||
|
||
<script> | ||
import 'ol/ol.css'; | ||
import {fromLonLat} from 'ol/proj'; | ||
import Map from 'ol/Map.js'; | ||
import View from 'ol/View.js'; | ||
import Draw from 'ol/interaction/Draw.js'; | ||
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer.js'; | ||
import {OSM, Vector as VectorSource} from 'ol/source.js'; | ||
import {Feature} from "ol"; | ||
import Circle from "ol/geom/Circle"; | ||
export default { | ||
data() { | ||
return { | ||
lat: null, | ||
lon: null, | ||
radius: null, | ||
} | ||
}, | ||
computed: { | ||
id() { | ||
return this.$route.params.id; | ||
} | ||
}, | ||
methods: { | ||
setupMap() | ||
{ | ||
var raster = new TileLayer({ | ||
source: new OSM() | ||
}); | ||
var source = new VectorSource({wrapX: false}); | ||
var vector = new VectorLayer({ | ||
source: source | ||
}); | ||
var map = new Map({ | ||
layers: [raster, vector], | ||
target: 'map', | ||
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); | ||
} | ||
addInteraction(); | ||
draw.on('drawend', async () => { | ||
/* | ||
WARNING: HACK!!!!!!!!!!! | ||
BAD HACK!!!!!!!!!!!!!!!! | ||
BAD!!!!!!!!!!!!!!!!!!!!! | ||
NOT GOOD!!!!!!!!!!!!!!!! | ||
Seemingly, drawend is fired before the feature array is updated. | ||
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); | ||
}); | ||
let coordinate = fromLonLat([this.lon, this.lat]); | ||
source.addFeature(new Feature(new Circle(coordinate, this.radius))); | ||
} | ||
}, | ||
mounted() { | ||
fetch('/locations/' + this.id + '.json') | ||
.then((response) => { | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
this.lon = parseFloat(data.long); | ||
this.lat = parseFloat(data.lat); | ||
this.radius = parseFloat(data.radius); | ||
this.setupMap(); | ||
}); | ||
} | ||
} | ||
</script> |
Oops, something went wrong.