高德地图拖拽marker,重新计算线条path
效果
initLine ( item) {
let { x, y } = item;
let pixel = this . map. lngLatToContainer ( new AMap. LngLat ( x, y) ) ;
var path = [
new AMap. LngLat ( x, y) ,
this . map. containerToLngLat ( new AMap. Pixel ( pixel. x, pixel. y - 70 ) ) ,
] ;
const polyline = new AMap. Polyline ( {
path: path,
... this . polylineStyle,
zIndex: 99999 ,
} ) ;
this . map. add ( polyline) ;
return polyline;
} ,
resetLine ( event) {
let curPosiLngLat = event. target. getPosition ( ) ;
const { info } = event. target. getExtData ( ) ;
let { x, y } = info;
const startLngLat = new AMap. LngLat ( x, y) ;
let endPixel = this . map. lngLatToContainer ( curPosiLngLat) ;
let endOffsetPixel = { x: endPixel. x, y: endPixel. y } ;
const startPixel = this . map. lngLatToContainer ( startLngLat) ;
const midPixel = { } ;
midPixel. x = endPixel. x;
midPixel. y = startPixel. y;
const midLnglat = this . map. containerToLngLat (
new AMap. Pixel ( midPixel. x, midPixel. y)
) ;
let endLngLat = this . map. containerToLngLat (
new AMap. Pixel ( endOffsetPixel. x, endOffsetPixel. y)
) ;
var path = [
startLngLat,
midLnglat,
endLngLat,
] ;
const options = {
path: path,
zIndex: 99999
} ;
const { infoLine } = this . mapCacheList. find (
( item) =>
item[ this . type] === info[ this . type]
) ;
infoLine. setOptions ( options) ;
} ,