vue2 组件内部 调用天地图基本演示,网上找了好多文档没找到自己想要的,记录下!
<template>
<div>
<remote-js
src="http://api.tianditu.gov.cn/api?v=4.0&tk=你申请的KEY"
@load="initMap"
></remote-js>
<div id="mapDiv"></div>
</div>
</template>
<script>
export default {
name: "Tmap",
components: {
"remote-js": {
render(createElement) {
var self = this;
return createElement("script", {
attrs: { type: "text/javascript", src: this.src },
on: {
load: function (event) {
self.$emit("load", event);
},
error: function (event) {
self.$emit("error", event);
},
readystatechange: function (event) {
if (this.readyState == "complete") {
self.$emit("load", event);
}
},
},
});
},
props: {
src: { type: String, required: true },
},
},
},
data() {
return {
map: null,
zoom: 12,
};
},
methods: {
initMap() {
this.map = new T.Map("mapDiv", {
projection: "EPSG:4326",
});
this.map.centerAndZoom(new T.LngLat(116.40769, 39.89945), this.zoom);
},
},
created() {},
mounted() {
},
};
</script>
<style lang="scss" scoped>
.mapDiv {
width: 100%;
height: calc(100vh - 100px);
}
</style>
天地图版权隐藏
::v-deep .tdt-bottom.tdt-left{
display: none;
}