我没有找到任何可拖动路线的示例, 一个具有确定路线的示例,我可以单击该路线上的某个位置,将其拖动并适合它。 您能为我提供一些示例代码吗?
答案 0 :(得分:1)
请查看以下示例:
function createDragRoutes(alternatives){
for(var i=0;i<alternatives;i++){
dragRoute[i]=new Object();
dragRoute[i].routeHoverMarker = new H.map.Marker({lat: 50.126237073013314, lng: 8.627775069326162}, {
icon: icon,
visibility: false,
zIndex: 1
});
dragRoute[i].routeHoverMarker.draggable = true;
map.addObject(dragRoute[i].routeHoverMarker);
dragRoute[i].pointermoveOnRouteHoverMarker = function(evt) {
// console.log(currentPolyline.routeNo);
currentPolyline.dispatchEvent(evt);
currentPolyline.setZIndex(zindex++);
};
dragRoute[i].dragstartOnRouteHoverMarker = function (evt) {
//console.log(this);
//console.log("routeHoverMarker dragstart:: ", evt, evt.target, currentPolyline);
currentPolyline.dispatchEvent(evt);
};
dragRoute[i].dragOnRouteHoverMarker = function(evt) {
//console.log(evt.target);
var coord = map.screenToGeo((evt.pointers[0].viewportX), (evt.pointers[0].viewportY + 8));
evt.target.setPosition(coord);
currentPolyline.dispatchEvent(evt);
};
dragRoute[i].dragendOnRouteHoverMarker = function (evt) {
currentPolyline.dispatchEvent(evt);
};
dragRoute[i].routeHoverMarker.addEventListener("pointermove", dragRoute[i].pointermoveOnRouteHoverMarker, false);
dragRoute[i].routeHoverMarker.addEventListener("dragstart", dragRoute[i].dragstartOnRouteHoverMarker, true);
dragRoute[i].routeHoverMarker.addEventListener("drag", dragRoute[i].dragOnRouteHoverMarker, false);
dragRoute[i].routeHoverMarker.addEventListener("dragend", dragRoute[i].dragendOnRouteHoverMarker, false);
dragRoute[i].calculateRouteParams = {
};
}
}