Commit 467926a8 authored by 黄奎's avatar 黄奎

页面修改

parent 5fd01be8
<style> <style>
.markers_labels{ .markers_labels {
margin-left: -24px !important; margin-left: -24px !important;
margin-top: -43px !important; margin-top: -43px !important;
} }
.gm-svpc,.gm-style-mtc,.gm-style-cc{
.gm-svpc,
.gm-style-mtc,
.gm-style-cc {
display: none; display: none;
} }
.classDetail{
height:244px; .classDetail {
width:100% height: 244px;
width: 100%
} }
.ClassList{
width:100%; .ClassList {
height:380px; width: 100%;
height: 380px;
} }
</style> </style>
<template> <template>
<div > <div>
<div id="map_canvas" :class="type==2?'classDetail':'ClassList'"></div> <div id="map_canvas" :class="type==2?'classDetail':'ClassList'"></div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
props:["dataList","type"], props: ["dataList", "type"],
data(){ data() {
return{ return {
show:false, show: false,
directionsService: new google.maps.DirectionsService(), directionsService: null,
directionsDisplay: new google.maps.DirectionsRenderer(), directionsDisplay: null,
map:{}, map: {},
} }
}, },
created(){ created() {
}, },
destroyed: function() { destroyed: function () {
}, },
mounted(){ created() {
// this.directionsService= new google.maps.DirectionsService(),
// this.directionsDisplay= new google.maps.DirectionsRenderer(),
},
mounted() {
// this.mapBuild() //初始化实例之后调用 // this.mapBuild() //初始化实例之后调用
}, },
methods:{ methods: {
getDetailsRoutes(source,destination,map){ getDetailsRoutes(source, destination, map) {
service = new google.maps.DistanceMatrixService(); service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({ service.getDistanceMatrix({
origins: [source], origins: [source],
...@@ -52,7 +61,8 @@ ...@@ -52,7 +61,8 @@
avoidHighways: false, avoidHighways: false,
avoidTolls: false avoidTolls: false
}, function (response, status) { }, function (response, status) {
if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status != "ZERO_RESULTS") { if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status !=
"ZERO_RESULTS") {
var distance = response.rows[0].elements[0].distance.text; var distance = response.rows[0].elements[0].distance.text;
var duration = response.rows[0].elements[0].duration.text; var duration = response.rows[0].elements[0].duration.text;
var dvDistance = document.getElementById("siteinfo_modal_label"); var dvDistance = document.getElementById("siteinfo_modal_label");
...@@ -65,11 +75,14 @@ ...@@ -65,11 +75,14 @@
}) })
}, },
// 地图实例 // 地图实例
mapBuild(){ mapBuild() {
if(this.dataList.length>1){ if (this.dataList.length > 1) {
let lat = parseFloat(this.dataList[0].lat) let lat = parseFloat(this.dataList[0].lat)
let lng = parseFloat(this.dataList[0].lng) let lng = parseFloat(this.dataList[0].lng)
let center = {lng: lng, lat: lat} let center = {
lng: lng,
lat: lat
}
//创建地图实例,zoom是缩放比例 //创建地图实例,zoom是缩放比例
this.map = new google.maps.Map(document.getElementById('map_canvas'), { this.map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 7, zoom: 7,
...@@ -79,41 +92,40 @@ ...@@ -79,41 +92,40 @@
}); });
this.directionsDisplay.setMap(this.map); this.directionsDisplay.setMap(this.map);
this.calcRoute(); this.calcRoute();
} } else {
else{
this.ptcenter = { this.ptcenter = {
        lat: parseFloat(this.dataList[0].lat), lat: parseFloat(this.dataList[0].lat),
        lng: parseFloat(this.dataList[0].lng) lng: parseFloat(this.dataList[0].lng)
      } }
this.ptstart = { this.ptstart = {
lat: parseFloat(this.dataList[0].lat), lat: parseFloat(this.dataList[0].lat),
        lng: parseFloat(this.dataList[0].lng) lng: parseFloat(this.dataList[0].lng)
} }
      this.map = new google.maps.Map(document.getElementById('map_canvas'), { this.map = new google.maps.Map(document.getElementById('map_canvas'), {
        center: this.ptcenter, center: this.ptcenter,
        zoom: 15, zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeId: google.maps.MapTypeId.ROADMAP,
gestureHandling: 'greedy' gestureHandling: 'greedy'
      }) })
var markerStart = new google.maps.Marker({ var markerStart = new google.maps.Marker({
position: this.ptstart position: this.ptstart
}) })
markerStart.setMap(this.map) markerStart.setMap(this.map)
} }
}, },
calcRoute: function() { // 创建路径规划 calcRoute: function () { // 创建路径规划
// 分解数据 获得起 止 以及中间数据 // 分解数据 获得起 止 以及中间数据
let lat = parseFloat(this.dataList[0].lat) let lat = parseFloat(this.dataList[0].lat)
let lng = parseFloat(this.dataList[0].lng) let lng = parseFloat(this.dataList[0].lng)
let elat = parseFloat(this.dataList[this.dataList.length-1].lat) let elat = parseFloat(this.dataList[this.dataList.length - 1].lat)
let elng = parseFloat(this.dataList[this.dataList.length-1].lng) let elng = parseFloat(this.dataList[this.dataList.length - 1].lng)
let _this = this; let _this = this;
let start = lat + ',' + lng; let start = lat + ',' + lng;
let end = elat + ',' + elng; let end = elat + ',' + elng;
let waypoints = []; let waypoints = [];
if (this.dataList.length > 2) { if (this.dataList.length > 2) {
this.dataList.forEach((x, index) => { this.dataList.forEach((x, index) => {
if (index >= 1 && index !== (this.dataList.length-1)) { if (index >= 1 && index !== (this.dataList.length - 1)) {
let obj = { let obj = {
location: x.lat + ',' + x.lng location: x.lat + ',' + x.lng
} }
...@@ -122,15 +134,15 @@ ...@@ -122,15 +134,15 @@
}); });
} }
let request = { // 组装连线数据 let request = { // 组装连线数据
origin:start, // 起 origin: start, // 起
destination:end, // 止 destination: end, // 止
travelMode: google.maps.TravelMode.DRIVING, travelMode: google.maps.TravelMode.DRIVING,
}; };
if (waypoints.length > 0) { if (waypoints.length > 0) {
request.waypoints = waypoints request.waypoints = waypoints
} }
_this.directionsService.route(request, function(result, status) { _this.directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) { if (status == google.maps.DirectionsStatus.OK) {
_this.directionsDisplay.setDirections(result); _this.directionsDisplay.setDirections(result);
} }
...@@ -139,4 +151,3 @@ ...@@ -139,4 +151,3 @@
}, },
} }
</script> </script>
\ No newline at end of file
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