123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <template>
- <div v-show="panel">
- <slot></slot>
- </div>
- </template>
- <script>
- import {createPoint} from '../base/factory.js'
- import {isPoint, getPosition} from '../base/util.js'
- import commonMixin from '../base/mixins/common.js'
- export default {
- name: 'bm-driving',
- mixins: [commonMixin('search')],
- props: {
- location: {
- type: [Object, String]
- },
- start: {
- type: [Object, String]
- },
- end: {
- type: [Object, String]
- },
- startCity: {
- type: [String, Number]
- },
- endCity: {
- type: [String, Number]
- },
- waypoints: {
- type: Array
- },
- policy: {
- type: String
- },
- panel: {
- type: Boolean,
- default: true
- },
- autoViewport: {
- type: Boolean
- },
- selectFirstResult: {
- type: Boolean
- }
- },
- watch: {
- location: {
- handler (val) {
- const {originInstance, map} = this
- originInstance.setLocation(val || map)
- },
- deep: true
- },
- start: {
- handler (val) {
- const {originInstance, end, startCity, endCity, waypoints, BMap, getWaypoints} = this
- originInstance.search(getPosition(BMap, val), getPosition(BMap, end), {
- startCity,
- endCity,
- waypoints: getWaypoints(waypoints)
- })
- },
- deep: true
- },
- end: {
- handler (val) {
- const {originInstance, start, startCity, endCity, waypoints, BMap, getWaypoints} = this
- originInstance.search(getPosition(BMap, start), getPosition(BMap, val), {
- startCity,
- endCity,
- waypoints: getWaypoints(waypoints)
- })
- },
- deep: true
- },
- startCity (val) {
- const {originInstance, start, end, endCity, waypoints, getWaypoints} = this
- originInstance.search(start, end, {
- val,
- endCity,
- waypoints: getWaypoints(waypoints)
- })
- },
- endCity (val) {
- const {originInstance, start, end, startCity, waypoints, getWaypoints} = this
- originInstance.search(start, end, {
- startCity,
- val,
- waypoints: getWaypoints(waypoints)
- })
- },
- waypoints: {
- handler (val) {
- const {originInstance, start, end, startCity, endCity, getWaypoints} = this
- originInstance.search(start, end, {
- startCity,
- endCity,
- waypoints: getWaypoints(val)
- })
- },
- deep: true
- },
- panel () {
- this.reload()
- },
- policy (val) {
- this.reload()
- },
- autoViewport () {
- this.reload()
- },
- selectFirstResult () {
- this.reload()
- },
- highlightMode () {
- this.reload()
- }
- },
- methods: {
- search (start, end, {startCity, endCity, waypoints}) {
- const {originInstance, getWaypoints} = this
- originInstance.search(start, end, {
- startCity,
- endCity,
- waypoints: getWaypoints(waypoints)
- })
- },
- getWaypoints (waypoints) {
- const {BMap} = this
- if (waypoints) {
- return waypoints.map(position => getPosition(BMap, position))
- }
- },
- load () {
- const instance = this
- const {map, BMap, location, policy, selectFirstResult, autoViewport, highlightMode, search, start, end, startCity, endCity, waypoints, originInstance, getWaypoints} = this
- const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
- const route = this.originInstance = new BMap.DrivingRoute(_location, {
- renderOptions: {
- map,
- // panel: panel && this.$el,
- panel: this.$el,
- selectFirstResult,
- autoViewport,
- highlightMode
- },
- policy: global[policy],
- onSearchComplete (e) {
- if (originInstance && originInstance !== route) {
- originInstance.clearResults()
- }
- instance.$emit('searchcomplete', e)
- },
- onMarkersSet (e) {
- instance.$emit('markersset', e)
- },
- onInfoHtmlSet (e) {
- instance.$emit('infohtmlset', e)
- },
- onPolylinesSet (e) {
- instance.$emit('polylinesset', e)
- },
- onResultsHtmlSet (e) {
- instance.$emit('resultshtmlset', e)
- }
- })
- search(getPosition(BMap, start), getPosition(BMap, end), {
- startCity,
- endCity,
- waypoints: getWaypoints(waypoints)
- })
- }
- }
- }
- </script>
|