地图绘制-动态绘制多边形

Mapstraction - draw polygon dynamically

本文关键字:绘制 多边形 动态 地图      更新时间:2023-09-26

在地图中,地图需要绘制一个可编辑的多边形。所以我尝试了一个例子。但多边形在调用函数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')})

这个例子是针对Mapstraction的idelab分支的,所以你需要确保你使用的是可以从这里获得的版本:

https://github.com/idelab/mxn

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

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

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