首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mapstraction -动态绘制多边形

Mapstraction -动态绘制多边形
EN

Stack Overflow用户
提问于 2013-07-02 16:43:38
回答 1查看 841关注 0票数 1

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

我已经尝试过了。没有成功。

我如何创建多边形,用户可以编辑它,也可以只保留10个顶点多边形。

JS代码

代码语言:javascript
复制
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')})
EN

回答 1

Stack Overflow用户

发布于 2013-07-03 15:30:14

该示例是针对Mapstraction的idelab fork的,因此您需要确保您使用的是可从此处获得的版本:

https://github.com/idelab/mxn

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

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17421144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档