1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <template> <div id="map">Hi</div> </template>
<script> import 'leaflet/dist/leaflet.css'; import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css'; import * as L from 'leaflet'; import 'leaflet-defaulticon-compatibility';
export default { name: "my-map", mounted() { let _this = this
var map = L.map('map').setView([35.26, -80.84], 10);
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', { attribution: 'Tiles © Esri — Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012' }).addTo(map);
L.geoJSON(_this.parks, { onEachFeature: function(feature, layer) { layer.bindPopup(feature.properties.prkname) layer.on({ click: function(e) { map.setView(feature.geometry.coordinates.reverse(), 14) _this.$store.commit("selected", feature.properties) } }) } }).addTo(map); }, computed: { parks() { return this.$store.state.parks } } } </script>
<style scoped> #map { width: 100%; height: 500px; } </style>
|