Mapstraction - 动态绘制多边形 [英] Mapstraction - draw polygon dynamically

查看:153
本文介绍了Mapstraction - 动态绘制多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



JS 代码

  var polyPoint; 
var polyPoints = []
//添加多边形映射
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)

//添加事件侦听器映射
mapstraction.markerChanged.addHandler(function(event,map,marker){
alert '标记移动到:'+ marker.marker.location.lat +','+ marker.marker.location.lon)})
mapstraction.polylineChanged.addHandler(function(event,map,polyline){
alert('Polyline modified:现在它有'+ polyline.polyline.points.length +'vertices')})


解决方案

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



https://github.com/idelab/mxn



我不知道idelab版本是否仍然受支持,我认为OpenLayers API自从最初开发以来就发生了变化,如果您使用正确的版本,那可能是为什么有问题。 p>

我怕在中继版本的Mapstraction中不支持可编辑的地图。主要是因为并不是所有的地图提供者都支持它,所以它作为Mapstraction的一部分将不那么有用。也是因为大多数人不需要它,所以很难证明将其添加到图书馆的努力。



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


In Mapstraction map need to draw a polygon which is editable. So i have tried a example. But polygon is editable mode while it's calling function 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.

JS Code

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:

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.

I'm afraid editable maps are not supported in the trunk version of Mapstraction. Primarily because not all the map providers support it so it would be less useful as part of 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. 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.

这篇关于Mapstraction - 动态绘制多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆