【问题标题】:mapkit JS: how to draw polyline with multiple coordinatemapkit JS:如何绘制具有多个坐标的折线
【发布时间】:2021-05-02 10:56:21
【问题描述】:

我正在尝试使用 mapkit js 在苹果地图上绘制折线。无法在地图上显示任何内容。

我的项目由地图上的许多位置组成。所有标记都在地图上,单击一个标记将打开信息窗口并在地图上绘制一条折线。

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);
}

我正在calloutForLandmarkAnnotation 中绘制我的信息窗口,我没有在这里显示。 DrawPolyLine 函数有点变量,它有三个坐标,但实际上我有更多。有些有大约 100 个坐标。如果你们需要任何其他信息来解决这个问题,请告诉我。

【问题讨论】:

    标签: javascript mapkit apple-maps mapkitannotation


    【解决方案1】:

    map.addOverlay() 将折线添加到地图,但要将用户带到您添加折线的位置,您还需要调用此函数:

    map.showItems(polyline);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 2023-03-12
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      相关资源
      最近更新 更多