Skip to content

Commit

Permalink
add map
Browse files Browse the repository at this point in the history
  • Loading branch information
River Honer committed Oct 27, 2019
1 parent 62f0669 commit 54e83c3
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 6 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@types/leaflet": "^1.5.5",
"core-js": "^3.3.2",
"leaflet": "^1.5.1",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
Expand Down
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>refuge_restrooms_fe</title>
<title>Refuge Restrooms</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css">
</head>
<body>
<noscript>
<strong>We're sorry but refuge_restrooms_fe doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
<strong>We're sorry but Refuge Restrooms doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import Restroom from '../models/restroom';
export default {
name: 'bathroom-card',
name: 'restroom-list-card',
props: {
restroom: {
type: Restroom,
Expand Down
49 changes: 49 additions & 0 deletions src/apps/restrooms/components/RestroomListMap.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<v-card>
<div id="map"></div>
</v-card>
</template>

<script>
import Map from '@/core/models/map';
export default {
name: 'restroom-list-map',
props: {
data: {
type: undefined,
},
userCoords: {
type: undefined,
},
},
data() {
return {
map: null,
};
},
mounted() {
this.initMap();
},
watch: {
userCoords(value) {
if (value) {
this.map.setView(value, 14);
}
},
},
methods: {
initMap() {
this.$nextTick(() => {
this.map = new Map('map', { zoomControl: false });
});
},
},
};
</script>

<style>
#map {
height: 90vh;
}
</style>
19 changes: 16 additions & 3 deletions src/apps/restrooms/views/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<v-col
v-if="restrooms"
cols="6"
md="6"
xs="12"
sm="12"
>
<!-- Toolbar for filter -->
<v-toolbar
Expand All @@ -15,27 +18,37 @@
</v-toolbar>

<!-- List of cards -->
<restroom-card
<restroom-list-card
v-for="restroom in restrooms"
:restroom="restroom"
:key="restroom.id"
/>

</v-col>
<!-- Map col -->
<v-col
cols="6"
md="6"
xs="12"
sm="12"
>
<restroom-list-map />
</v-col>
</v-row>
</v-container>
</template>

<script>
import Restroom from '../models/restroom';
import RestroomCard from '../components/RestroomCard.vue';
import RestroomListCard from '../components/RestroomListCard.vue';
import RestroomListMap from '../components/RestroomListMap.vue';
import WebApi from '../webapi';
export default {
name: 'restroom-list',
components: {
RestroomCard,
RestroomListCard,
RestroomListMap,
},
data() {
return {
Expand Down
47 changes: 47 additions & 0 deletions src/core/models/map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import L from 'leaflet';

const routeStyle = {
color: '#F9971E',
weight: 5,
};

const startEndPointsStyle = {
color: '#F9971E',
radius: 10,
fillOpacity: 1,
};

export default class Map extends L.Map {
constructor(id: any, params: any) {
super(id, params);
// Custom Map Setup
const tonerUrl = 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png';
const url = tonerUrl.replace(/({[A-Z]})/g, s => s.toLowerCase());
const basemap = L.tileLayer(url, {
subdomains: ['', 'a.', 'b.', 'c.', 'd.'],
minZoom: 0,
maxZoom: 17,
attribution: 'Map tiles by <a href="//stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>',
});
basemap.addTo(this);
this.setView([51.505, -0.09], 13);
}

drawRoute(route: any) {
L.geoJSON(route.geojson, routeStyle).addTo(this);
if (route.startPoint && route.endPoint) {
this.drawStartEndPoints([route.startPoint, route.endPoint]);
}
}

drawStartEndPoints(startEndPoints: any) {
startEndPoints.forEach((coords: any) => {
const circle = L.circle(coords.reverse(), startEndPointsStyle);
circle.addTo(this);
});
}

fitZoomToRoute(startEndPoints: any) {
this.fitBounds(startEndPoints);
}
}

0 comments on commit 54e83c3

Please sign in to comment.