Files
openlayers/examples/rotate-features.html
crschmidt 7da6a3540e Merge the excellent documentation work done during foss4g into trunk. Many
thanks to all the contributors who helped put this together. 
I'm not exactly sure of what's going to happen with this, but for now,
at http://openlayers.org/dev/doc/examples.html you can see links to all the
examples *with descriptions*. Hooray!


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5362 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2007-12-08 14:21:53 +00:00

112 lines
4.3 KiB
HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Rotate Features Example</title>
<style type="text/css">
#map {
width: 500px;
height: 350px;
border: 1px solid #ccc;
}
p {
width: 500px;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, pointFeature, lineFeature, polygonFeature;
function init(){
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style_blue.strokeColor = "blue";
style_blue.fillColor = "blue";
var style_green = {
strokeColor: "#339933",
strokeOpacity: 1,
strokeWidth: 3,
pointRadius: 6,
pointerEvents: "visiblePainted"
};
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
// create a point feature
var point = new OpenLayers.Geometry.Point(-110, 45);
pointFeature = new OpenLayers.Feature.Vector(point, null, style_blue);
// create a line feature from a list of points
var pointList = [];
var newPoint = point;
for(var p=0; p<5; ++p) {
newPoint = new OpenLayers.Geometry.Point(newPoint.x + Math.random(1),
newPoint.y + Math.random(1));
pointList.push(newPoint);
}
lineFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString(pointList),null,style_green);
// create a polygon feature from a linear ring of points
var pointList = [];
for(var p=0; p<6; ++p) {
var a = p * (2 * Math.PI) / 7;
var r = Math.random(1) + 1;
var newPoint = new OpenLayers.Geometry.Point(point.x + (r * Math.cos(a)),
point.y + (r * Math.sin(a)));
pointList.push(newPoint);
}
pointList.push(pointList[0]);
var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
polygonFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon([linearRing]));
map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
vectorLayer.addFeatures([pointFeature, lineFeature, polygonFeature]);
// start rotating
var origin = new OpenLayers.Geometry.Point(-111.04, 45.68);
var style = {
strokeColor: "#666666",
strokeOpacity: 1,
strokeWidth: 1,
pointRadius: 2,
pointerEvents: "visiblePainted"
};
var center = new OpenLayers.Feature.Vector(origin, null, style);
vectorLayer.addFeatures([center]);
window.setInterval(rotateFeature, 100,
pointFeature, 360 / 20, origin);
window.setInterval(rotateFeature, 100,
lineFeature, 360 / 40, origin);
window.setInterval(rotateFeature, 100,
polygonFeature, -360 / 20, origin);
}
function rotateFeature(feature, angle, origin) {
feature.geometry.rotate(angle, origin);
feature.layer.drawFeature(feature);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Rotate vector features</h1>
<div id="tags">
</div>
<p id="shortdesc">
Details on how to create and rotate vector features programmatically
</p>
<div id="map"></div>
<div id="docs">This example shows a few features rotating. There is not yet a control
built that provides a tool for rotating, but the geometry.rotate method
can be accessed to rotate programmatically.</div>
</body>
</html>