1

在 Mapstraction 地图中需要绘制一个可编辑的多边形。所以我尝试了一个例子。但是多边形href="javascript:mapstraction.activateEdition();"在示例中调用函数时是可编辑模式。

我已经尝试过这样做。没有成功。

我如何创建用户可以编辑的多边形,并且这是否可以只保留 10 个顶点的多边形。

JS代码

var polyPoint;
var polyPoints = []
//Adding polygon to map
    polyPoint = new mxn.LatLonPoint(17.447612 , 78.223686)
    polyPoints.push(polyPoint);
    polyPoint = new mxn.LatLonPoint(17.504593 , 78.306084)
    polyPoints.push(polyPoint);
    polyPoint = new mxn.LatLonPoint(17.471193 , 78.417320)
    polyPoints.push(polyPoint);
    polyPoint = new mxn.LatLonPoint(17.414201 , 78.470879)
    polyPoints.push(polyPoint);

    var polygon = new mxn.Polyline(polyPoints);
    polygon.setClosed(true);
    map.addPolyline(polygon)

//Adding event listeners to map
      mapstraction.markerChanged.addHandler(function(event,map,marker){
          alert('Marker moved to: '+marker.marker.location.lat+' , '+marker.marker.location.lon)})
      mapstraction.polylineChanged.addHandler(function(event,map,polyline){
          alert('Polyline modified: Now it has '+polyline.polyline.points.length+' vertices')})
4

1 回答 1

0

该示例适用于 Mapstraction 的 idelab 分支,因此您需要确保使用可以从此处获得的版本:

https://github.com/idelab/mxn

我不确定是否仍然支持 idelab 版本,而且我认为 OpenLayers API 自最初开发以来已经发生了变化,因此,如果您使用的是正确的版本,这可能就是您遇到问题的原因。

恐怕 Mapstraction 的主干版本不支持可编辑的地图。主要是因为不是所有的地图提供者都支持它,所以它作为 Mapstraction 的一部分用处不大。也因为大多数人不需要它,所以很难证明将它添加到库中的努力是合理的。

如果您使用 OpenLayers 并且不需要能够切换提供程序,您应该考虑直接针对 OpenLayers API 进行编程。如果您确实需要能够切换提供商,您应该联系 idelab 存储库 (plopesc) 的所有者并检查它是否支持您的用例。

于 2013-07-03T07:30:13.717 回答