简体   繁体   English

Mapstraction-动态绘制多边形

[英]Mapstraction - draw polygon dynamically

In Mapstraction map need to draw a polygon which is editable. 在Mapstraction地图中,需要绘制一个可编辑的多边形。 So i have tried a example . 所以我试了一个例子 But polygon is editable mode while it's calling function href="javascript:mapstraction.activateEdition();" 但是,多边形在调用函数href="javascript:mapstraction.activateEdition();"是可编辑模式href="javascript:mapstraction.activateEdition();" in example. 例如。

I have tried to do that. 我已经尝试过了。 Didn't get succeed. 没有成功。

How do i create polygon which user can edit it and also is this possible to keep only 10 vertices polygon. 我如何创建多边形,用户可以对其进行编辑,这也可能仅保留10个顶点。

JS Code 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')})

That example is for the idelab fork of Mapstraction so you need to ensure you're using that version which you can get from here: 该示例用于Mapstraction的idelab分支,因此您需要确保使用的是可从此处获得的版本:

https://github.com/idelab/mxn https://github.com/idelab/mxn

I'm not sure whether the idelab version is still supported and I think OpenLayers API has changed since it was initially developed so, if you are using the correct version, that could be why you're having problems. 我不确定idelab版本是否仍受支持,并且我认为OpenLayers API自最初开发以来就发生了变化,因此,如果使用正确的版本,这可能就是您遇到问题的原因。

I'm afraid editable maps are not supported in the trunk version of Mapstraction. 恐怕Mapstraction的主干版本不支持可编辑地图。 Primarily because not all the map providers support it so it would be less useful as part of Mapstraction. 主要是因为并非所有的地图提供程序都支持它,所以作为Mapstraction的一部分它的用处将减少。 Also because most people don't require it so its difficult to justify the effort of adding it to the library. 同样因为大多数人不需要它,所以很难证明将其添加到库中的努力是合理的。

If you are using OpenLayers and don't need to be able to switch provider you should consider programming directly against the OpenLayers API. 如果您使用的是OpenLayers,并且不需要切换提供程序,则应考虑直接根据OpenLayers API进行编程。 If you do need to be able to switch provider you should contact the owner of the idelab repo (plopesc) and check whether it supports your use case. 如果确实需要切换提供者,则应联系idelab存储库(plopesc)的所有者,并检查其是否支持您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM