简体   繁体   English

mapkit JS:如何绘制多坐标折线

[英]mapkit JS: how to draw polyline with multiple coordinate

I am trying to draw polyline on apple map with mapkit js.我正在尝试使用 mapkit js 在苹果 map 上绘制折线。 Unable to show anything on map.无法在 map 上显示任何内容。

My project is consist of many location on the map. All the markers are there on the map, clicking on the one marker will open the info-window and draw a polyline on the map itself.我的项目由 map 上的许多位置组成。所有标记都在 map 上,单击一个标记将打开信息窗口并在 map 本身上绘制一条折线。

map = new mapkit.Map("map");
function plottrailsCompound(data,map){
    if(data.reststatus.status == "OK"){
        if(annotations){
            map.removeAnnotations(annotations); 
            annotations = [];
        }
        var landmarkAnnotationCallout = {
            calloutElementForAnnotation: function(annotation) {
            var cccDiv = calloutForLandmarkAnnotation(annotation,map);
            return cccDiv;
            },
            calloutAppearanceAnimationForAnnotation: function(annotation) {
            return "scale-and-fadein .4s 0 1 normal cubic-bezier(8, 1, 0, 1.5)";
            }
        };
    }
}
function calloutForLandmarkAnnotation(data,map){
    DrawPolyLine(map);
}
function DrawPolyLine(map){
    var points = [[37.73438, -119.56517], [37.73435, -119.56513], [37.73431, -119.56509]];
    var coords = points.map(function(point) {
        return new mapkit.Coordinate(point[0], point[1]);
    });
    var style = new mapkit.Style({
        lineWidth: 2,
        lineJoin: "round",
        lineDash: [8, 4],
        strokeColor: "#F0F"
    });
    var polyline = new mapkit.PolylineOverlay(coords, { style: style });
    map.addOverlay(polyline);
}

I am drawing my info window in calloutForLandmarkAnnotation , which i am not showing over here.我正在 calloutForLandmarkAnnotation 中绘制我的信息calloutForLandmarkAnnotation ,我没有在这里显示。 DrawPolyLine function has points variable and it has three coordinates but in actual i have more than this. DrawPolyLine有点变量,它有三个坐标,但实际上我有更多。 Some has around 100's of coordinates.有些有大约 100 个坐标。 Please let me know if any other info you guys need to solve this.如果你们需要任何其他信息来解决这个问题,请告诉我。

map.addOverlay() adds the polyline to the map, but to take the user to where you added the polyline, you will need to also call this function: map.addOverlay()将折线添加到 map,但要将用户带到添加折线的位置,您还需要调用此 function:

map.showItems(polyline);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM