Search code examples
here-apipolyline

HERE MAP add new point in clicked place on polyline


I really beg about help because I'm trying to do some things for a few days, and I really don't know how. I want to do road manipulate by hold and drag . I think I need to start with adding new point in polyline geometry exaclly in the pointer place (or linestring, linstring points and polyline geometry seems to be almost the same). But it seems to be impossible.

Of course, there is no problem with getting coordinates, but adding this new coordinates to polyline or linestring in appropriate place.

There is no code, because every here map methods (pushPoints, setGeopetry) seems to be usless, and give points in the wrong place.


Solution

  • See please this example: https://demo.support.here.com/examples/v3/fleet - you can drag-n-drop there

    and src code of it : https://demo.support.here.com/javascripts/examples/v3/fleet.js

    Search there in the code the variable clipedPolyline and func clipPolyline:

    var clipPolyline = function(polyline, viewportX, viewportY, bboxSize){
            var pleft = viewportX - bboxSize,
            pright = viewportX + bboxSize,
            ptop = viewportY - bboxSize,
            pbottom = viewportY + bboxSize,
            coordLeftTop = map.screenToGeo(pleft, ptop),
            coordRigthBottom = map.screenToGeo(pright, pbottom),
            rect = new H.geo.Rect(coordLeftTop.lat,coordLeftTop.lng,coordRigthBottom.lat,coordRigthBottom.lng),
            clipedPolyline = polyline.clip(rect);
    
            return clipedPolyline;
        };
    

    Read please documentation for method clip on: https://developer.here.com/documentation/maps/3.1.31.0/api_reference/H.map.Polyline.html#clip