Commit 28c490ef authored by 陈珊's avatar 陈珊

11

parent a6c0f4c7
...@@ -53,6 +53,7 @@ new Vue({ ...@@ -53,6 +53,7 @@ new Vue({
} }
}, },
created(){ created(){
let _this = this;
this.getToken(); this.getToken();
}, },
methods:{ methods:{
...@@ -103,6 +104,8 @@ new Vue({ ...@@ -103,6 +104,8 @@ new Vue({
success: function (data) { success: function (data) {
_this.info = data.data; _this.info = data.data;
station_id = data.data.station_id; station_id = data.data.station_id;
province = data.data.province;
city = data.data.city;
setTimeout(() => { setTimeout(() => {
map.getData(); map.getData();
}, 2000); }, 2000);
...@@ -557,47 +560,96 @@ var map = { ...@@ -557,47 +560,96 @@ var map = {
}) })
}, },
getMap: function (data) { getMap: function (data) {
var map = new AMap.Map("map", { var options = {
expandZoomRange: true, subdistrict: 0,
zoom: 7, extensions: 'all',
zooms: [5, 20], level: 'province'
mapStyle: 'amap://styles/d3ce37d9fe39b7cc5f08f48af52802a2', };
resizeEnable: true, var district = new AMap.DistrictSearch(options);
viewMode: '3D', district.search(province, function (status, result) {
showLabel: true var bounds = result.districtList[0]['boundaries'];
}); var mask = [];
var infoWindow = new AMap.InfoWindow({ for (var i = 0; i < bounds.length; i++) {
offset: new AMap.Pixel(0, -30) mask.push([bounds[i]]);
}); }
if (data && data.length > 0) { var map = new AMap.Map("map", {
for (var i = 0; i < data.length; i++) { mask: mask,
let item = data[i]; expandZoomRange: true,
var img = '../static/images/gczljc/icn_shiyi.png'; zoom: 7,
var marker = new AMap.Marker({ zooms: [5, 20],
position: [item.mapx, item.mapy], mapStyle: 'amap://styles/d3ce37d9fe39b7cc5f08f48af52802a2',
icon: new AMap.Icon({ resizeEnable: true,
size: new AMap.Size(28, 28), viewMode: '3D',
image: img showLabel: true
}), });
map: map var district = null;
var polygons = [];
function drawBounds() {
if (!district) {
var opts = {
subdistrict: 0,
extensions: 'all',
level: 'district'
};
district = new AMap.DistrictSearch(opts);
}
//行政区查询
district.setLevel('district')
district.search(city, function(status, result) {
// district.search('杭州市', function (status, result) {
map.remove(polygons)//清除上次结果
polygons = [];
var bounds = result.districtList[0].boundaries;
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
var polygon = new AMap.Polygon({
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.4,
fillColor: '#80d8ff',
strokeColor: '#0091ea'
});
polygons.push(polygon);
}
}
map.add(polygons)
map.setFitView(polygons);//视口自适应
}); });
marker.content = `<p class="info-item">${item.project_name}</p>`;
marker.on('mouseover', infoOpen);
marker.on('click', newMAp);
} }
map.setZoomAndCenter(7, [Number(data[0].mapx), Number(data[0].mapy)]); drawBounds();
}
function newMAp(e) {
var infoWindow = new AMap.InfoWindow({ var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, -30) offset: new AMap.Pixel(0, -30)
}); });
infoWindow.setContent(e.target.content); if (data && data.length > 0) {
infoWindow.open(map, e.target.getPosition()); for (var i = 0; i < data.length; i++) {
} let item = data[i];
function infoOpen(e) { var img = '../static/images/gczljc/icn_shiyi.png';
infoWindow.setContent(e.target.content); var marker = new AMap.Marker({
infoWindow.open(map, e.target.getPosition()); position: [item.mapx, item.mapy],
} icon: new AMap.Icon({
map.setMapStyle('amap://styles/d3ce37d9fe39b7cc5f08f48af52802a2'); size: new AMap.Size(28, 28),
image: img
}),
map: map
});
marker.content = `<p class="info-item">${item.project_name}</p>`;
marker.on('mouseover', infoOpen);
marker.on('click', newMAp);
}
map.setZoomAndCenter(7, [Number(data[0].mapx), Number(data[0].mapy)]);
}
function newMAp(e) {
var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, -30)
});
infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
}
function infoOpen(e) {
infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
}
map.setMapStyle('amap://styles/d3ce37d9fe39b7cc5f08f48af52802a2');
})
}, },
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ const api_key = 16859729295369; ...@@ -3,6 +3,8 @@ const api_key = 16859729295369;
const api_secret = "C7DEA02B195942EAA973A6FBF4151741"; const api_secret = "C7DEA02B195942EAA973A6FBF4151741";
var station_id = ''; var station_id = '';
var access_token = ''; var access_token = '';
var province = '';
var city = '';
window._AMapSecurityConfig = { window._AMapSecurityConfig = {
securityJsCode: '0711374220aba81dbf7515aaac08e50b', securityJsCode: '0711374220aba81dbf7515aaac08e50b',
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment