1、主要涉及类:
OpenLayers.Layer.Vector、OpenLayers.Control.DrawFeature、
OpenLayers.Handler.RegularPolygon
2、方法编写
var polygonControl ;function addPolygonLayer(){ var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer"); map.addLayers([polygonLayer]); polyOptions = {sides: 4}; polygonControl = new OpenLayers.Control.DrawFeature(polygonLayer, OpenLayers.Handler.RegularPolygon,{handlerOptions: polyOptions}); map.addControl(polygonControl); map.setCenter(new OpenLayers.LonLat(0, 0), 3); document.getElementById('activate').checked = true; document.getElementById('deactivate').checked = false; } function setOptions(options) { polygonControl.handler.setOptions(options); }
3、操作选项:
deactivateactivate