Mapstraction - draw polygon dynamically

喜夏-厌秋 提交于 2019-12-13 01:43:41

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/17421144/mapstraction-draw-polygon-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!