Skip to content

Instantly share code, notes, and snippets.

@adash333
Last active September 6, 2019 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adash333/a0a11a9918029a9f52e36658ba9fd490 to your computer and use it in GitHub Desktop.
Save adash333/a0a11a9918029a9f52e36658ba9fd490 to your computer and use it in GitHub Desktop.
<template>
<div id="mapid"></div>
</template>
<script>
import "leaflet/dist/leaflet.css";
import L from "leaflet";
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconUrl: require("leaflet/dist/images/marker-icon.png"),
iconRetinaUrl: require("leaflet/dist/images/marker-icon-2x.png"),
shadowUrl: require("leaflet/dist/images/marker-shadow.png")
});
export default {
name: 'Map',
mounted() {
// マップオブジェクト生成
// データソースはOpenStreetMap
const map = L.map("mapid").addLayer(
L.tileLayer("https://{s}.tile.osm.org/{z}/{x}/{y}.png", {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, '
})
);
// 位置情報検索
setInterval(() => {
map.locate({ setView: true, maxZoom: 20, zoom: 20 });
}, 5000);
// map.locate({ setView: true, maxZoom: 10 });
// 位置情報取得成功処理
function onLocationFound(e) {
var radius = e.accuracy / 2;
L.marker(e.latlng).addTo(map);
//.bindPopup("You are within " + radius + " meters from this point")
//.openPopup();
L.circle(e.latlng, radius).addTo(map);
}
map.on("locationfound", onLocationFound);
// 位置情報取得エラー処理
function onLocationError(e) {
alert(e.message);
}
map.on("locationerror", onLocationError);
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
html,
body,
#app,
#mapid {
height: 600px;
}
body {
margin: 0;
}
</style>
<template>
<Map/>
</template>
<script>
// @ is an alias to /src
import Map from '@/components/Map.vue'
export default {
name: 'home',
components: {
Map
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment