嗨,我是 openlayers 的新手,我从 openlayers 提供的示例中获取了以下代码,我试图通过单击创建 4 个多边形,然后将每个多边形拖放到一个新位置,这可能吗?
提前感谢您的帮助。
代码:
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var options = {numZoomLevels: 3};
var graphic = new OpenLayers.Layer.Image(
'some title',
'image.png',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(800, 200),
options
);
graphic.events.on({
loadstart: function() {
OpenLayers.Console.log("loadstart");
},
loadend: function() {
OpenLayers.Console.log("loadend");
}
});
var jpl_wms = new OpenLayers.Layer.WMS( "title",
"http://t1.hypercube.telascience.org/cgi-bin/landsat7",
{layers: "landsat7"}, options);
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([graphic, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
shape:
//*************This is what i'm trying to do***************************************************
for (i=0; i<5; i++)
{
new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.RegularPolygon,
{handlerOptions: {radius: 5, sides: 4, snapAngle: 45 }}),
}
drag: new OpenLayers.Control.DragFeature(vectors)
};
for(var key in controls) {
map.addControl(controls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function toggleControl(element) {
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>