Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
891 views
in Technique[技术] by (71.8m points)

javascript - Implementation of dragging route

I did not find any example of draggable routing, an example that had a definite route, and I could click somewhere on the route, drag it and it fit. Could you put some sample code for me to take as a basis?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please have a look at this example:

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 = {


            };

        }

} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...