vue渲染掩模、定位、天气、
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你申请的key">
</script>
<template>
<div id="container"></div>
</template>
<script>
<template>
<div class="box">
<div id="container">
</div>
<div id="panel"></div>
</div>
</template>
<script>
export default {
name: 'maps',
data () {
return {
map: null,
disCountry: null,
mask: []
}
},
mounted () {
this.getYanmo()
this.getLocation()
},
methods: {
getYanmo () {
AMap.plugin("AMap.DistrictSearch", () => {
var opts = {
subdistrict: 0,
extensions: 'all',
};
var district = new AMap.DistrictSearch(opts);
district.search('中国', (status, result) => {
var bounds = result.districtList[0].boundaries;
this.$nextTick(() => {
if (bounds.length > 0) {
for (var i = 0; i < bounds.length; i += 1) {
this.mask.push([bounds[i]])
}
}
})
console.log('this.mask', this.mask);
AMap.plugin("AMap.DistrictLayer", () => {
this.disCountry = new AMap.DistrictLayer.World({
zIndex: 1,
rejectMapMask: true
})
})
this.map = new AMap.Map('container', {
mask: this.mask,
center: [120.16263, 33.348176],
viewMode: '3D',
labelzIndex: 130,
zoom: 3,
cursor: 'pointer',
layers: [
new AMap.TileLayer.RoadNet({
zIndex: 7
}),
this.disCountry,
new AMap.TileLayer.Satellite()
]
});
})
})
},
getLocation () {
AMap.plugin("AMap.Geolocation", function () {
var geolocation = new AMap.Geolocation({
enableHighAccuracy: true,
timeout: 2000
});
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, "complete", onComplete);
AMap.event.addListener(geolocation, "error", onError);
function onComplete (data) {
console.log('定位', data);
}
function onError (data) {
}
});
AMap.plugin('AMap.Weather', function () {
var weather = new AMap.Weather();
weather.getLive('南京', function (err, data) {
console.log('天气', data);
});
});
AMap.plugin(["AMap.StationSearch"], function () {
var station = new AMap.StationSearch({
pageIndex: 1,
pageSize: 10,
city: '010'
});
station.search('南京南站', function (status, result) {
console.log('公交信息', result);
});
});
AMap.plugin(["AMap.LineSearch"], function () {
var linesearch = new AMap.LineSearch({
pageIndex: 1,
pageSize: 1,
city: "南京",
extensions: "all"
});
linesearch.search('13路', function (status, result) {
console.log('公交线路', result);
});
});
AMap.plugin('AMap.Geocoder', function () {
var geocoder = new AMap.Geocoder({
city: '010'
})
var lnglat = [118.856371, 32.005985]
geocoder.getAddress(lnglat, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
console.log('坐标查询的地址', result);
}
})
}),
AMap.plugin('AMap.DistrictSearch', function () {
var districtSearch = new AMap.DistrictSearch({
level: 'country',
subdistrict: 1
})
districtSearch.search('中国', function (status, result) {
console.log('行政区', result);
})
})
},
}
}
</script>
<style scoped>
#container {
padding: 0px;
margin: 0px;
width: 100%;
height: 100vh;
background-color: rgb(119, 194, 216);
}