Added control for selecting walk or driving directions

This commit is contained in:
2021-09-07 15:00:45 +02:00
parent 0c1abff773
commit 4c0f2750fd
2 changed files with 22 additions and 2 deletions

2
dist/js/field.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -6,6 +6,16 @@
:value="localValue" :value="localValue"
@input="triggerChange" @input="triggerChange"
/> />
<l-control position="topleft" v-if="edit" class="block my-2">
<div class="flex">
<div v-for="option in routeTypes">
<input type="radio" :id="option.value" :value="option.value" v-model="selectedRouteType">
<label :for="option.value">{{ option.name }}</label>
</div>
</div>
</l-control>
</div> </div>
</template> </template>
@@ -29,10 +39,20 @@ export default {
data() { data() {
return { return {
localValue: {}, localValue: {},
routeTypes: [{
value: 'driving',
name: 'Bil'
}, {
value: 'walking',
name: 'Gange'
}],
selectedRouteType: null
}; };
}, },
created() { created() {
this.selectedRouteTypes = this.routeTypes[0];
if (this.value !== null) { if (this.value !== null) {
this.localValue = this.value; this.localValue = this.value;
} }
@@ -44,7 +64,7 @@ export default {
.map((marker) => `${marker.lng},${marker.lat}`) .map((marker) => `${marker.lng},${marker.lat}`)
.join(";"); .join(";");
const URL = `https://api.mapbox.com/directions/v5/mapbox/driving/${cords}?geometries=geojson&access_token=pk.eyJ1Ijoia2V2aW5taWRib2UiLCJhIjoiY2pydWhlamQyMHJ2NTRhdGN1em5ndXVyMyJ9.Ejdo_3iuuGOD662Bh6es4w`; const URL = `https://api.mapbox.com/directions/v5/mapbox/${this.selectedRouteType.value}/${cords}?geometries=geojson&access_token=pk.eyJ1Ijoia2V2aW5taWRib2UiLCJhIjoiY2pydWhlamQyMHJ2NTRhdGN1em5ndXVyMyJ9.Ejdo_3iuuGOD662Bh6es4w`;
return fetch(URL) return fetch(URL)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((response) => response.routes[0].geometry.coordinates) .then((response) => response.routes[0].geometry.coordinates)