Google maps api 3 如何在两个顶点之间的某个多段线上添加点?

Google maps api 3 如何在两个顶点之间的某个多段线上添加点?,google-maps-api-3,google-polyline,Google Maps Api 3,Google Polyline,目标是在每个顶点都有一条带有自定义标记的可编辑多段线 正如我所见,MAPAPIv3不允许这样做。因此,我制作了如下可编辑多段线: let polyline = new self.google.maps.Polyline({ strokeColor: '#000000', strokeOpacity: 0.3, strokeWeight: 3, editable: false, path: path, map: self.map }); polyl

目标是在每个顶点都有一条带有自定义标记的可编辑多段线

正如我所见,MAPAPIv3不允许这样做。因此,我制作了如下可编辑多段线:

let polyline = new self.google.maps.Polyline({
    strokeColor: '#000000',
    strokeOpacity: 0.3,
    strokeWeight: 3,
    editable: false,
    path: path,
    map: self.map
});

polyline.binder = new MVCArrayBinder(polyline.getPath());

let markers = [];
for (let i = 0; i < path.length; i++) {
    let marker = this.getBasicMarker(path[i]);
    marker.bindTo('position', polyline.binder, i.toString());
    markers.push(marker);
}
最终多段线现在看起来像这样:。我可以拖动任何现有点。多段线将在拖动点时更新

现在我必须在两个现有顶点之间添加新顶点

这就是我被困的地方


可能还有其他解决方案如何解决该任务?

如果有人面临类似任务,这里是对我的代码的一些修改。这帮助我最终解决了问题

MVCArrayBinder.prototype = new google.maps.MVCObject();
MVCArrayBinder.prototype.get = function (key) {
    if (!isNaN(parseInt(key))) {
        return this.array_.getAt(parseInt(key));
    } else {
        this.array_.get(key);
    }
};

MVCArrayBinder.prototype.set = function (key, val) {
    if (!isNaN(parseInt(key))) {
        this.array_.setAt(parseInt(key), val);
    } else {
        this.array_.set(key, val);
    }
};

MVCArrayBinder.prototype.insertAt = function (key, val) {
    this.array_.insertAt(key, val);
};

为什么不直接将多段线设置为
可编辑:true
,以便使用GUI在多段线上的任何位置添加任何点?因为我需要自定义每个顶点标记。以及?有什么问题吗?编辑你的问题,用一个能说明问题并解释你想要达到的目标的例子。事实上,您的问题过于宽泛和不完整。问题已更新。相关问题:
function MVCArrayBinder(mvcArray) {
    this.array_ = mvcArray;
}

MVCArrayBinder.prototype = new google.maps.MVCObject();
MVCArrayBinder.prototype.get = function (key) {
    if (!isNaN(parseInt(key))) {
        return this.array_.getAt(parseInt(key));
    } else {
        this.array_.get(key);
    }
};

MVCArrayBinder.prototype.set = function (key, val) {
    if (!isNaN(parseInt(key))) {
        this.array_.setAt(parseInt(key), val);
    } else {
        this.array_.set(key, val);
    }
};
MVCArrayBinder.prototype = new google.maps.MVCObject();
MVCArrayBinder.prototype.get = function (key) {
    if (!isNaN(parseInt(key))) {
        return this.array_.getAt(parseInt(key));
    } else {
        this.array_.get(key);
    }
};

MVCArrayBinder.prototype.set = function (key, val) {
    if (!isNaN(parseInt(key))) {
        this.array_.setAt(parseInt(key), val);
    } else {
        this.array_.set(key, val);
    }
};

MVCArrayBinder.prototype.insertAt = function (key, val) {
    this.array_.insertAt(key, val);
};
google.maps.event.addListener(this.activePoly, 'click', function (e) {
    let path = $this.activePoly.getPath(),
        inserted = false;

    // find line segment
    for (let i = 0; i < path.getLength() - 1, !inserted; i++) {
        let tempPoly = new google.maps.Polyline({
            path: [path.getAt(i), path.getAt(i + 1)]
        });

        if (google.maps.geometry.poly.isLocationOnEdge(e.latLng, tempPoly, 10e-2)) {
            $this.activeRoute.binder.insertAt(i + 1, e.latLng);
            inserted = true;

            let marker = $this.getBasicMarker(e.latLng);
            marker.setVisible(true);

            // Add new marker to array
            $this.activeRoute.markers.splice(i + 1, 0, marker);

            // Have to rebind all markers
            $this.activeRoute.markers.forEach((marker, index) => {
                marker.bindTo('position', $this.activeRoute.binder, index.toString());
            });
        }
    }
});
{polyline: polyline, markers: markers, binder: polyline.binder}