1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>OpenLayers Rotate Features Example</title>
4 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
5 <link rel="stylesheet" href="style.css" type="text/css" />
6 <style type="text/css">
11 <script src="../lib/OpenLayers.js"></script>
12 <script type="text/javascript">
13 var map, pointFeature, lineFeature, polygonFeature;
16 map = new OpenLayers.Map('map');
17 var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
18 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
21 var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
22 style_blue.strokeColor = "blue";
23 style_blue.fillColor = "blue";
25 strokeColor: "#339933",
29 pointerEvents: "visiblePainted"
32 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
34 // create a point feature
35 var point = new OpenLayers.Geometry.Point(-110, 45);
36 pointFeature = new OpenLayers.Feature.Vector(point, null, style_blue);
38 // create a line feature from a list of points
41 for(var p=0; p<5; ++p) {
42 newPoint = new OpenLayers.Geometry.Point(newPoint.x + Math.random(1),
43 newPoint.y + Math.random(1));
44 pointList.push(newPoint);
46 lineFeature = new OpenLayers.Feature.Vector(
47 new OpenLayers.Geometry.LineString(pointList),null,style_green);
49 // create a polygon feature from a linear ring of points
51 for(var p=0; p<6; ++p) {
52 var a = p * (2 * Math.PI) / 7;
53 var r = Math.random(1) + 1;
54 var newPoint = new OpenLayers.Geometry.Point(point.x + (r * Math.cos(a)),
55 point.y + (r * Math.sin(a)));
56 pointList.push(newPoint);
58 pointList.push(pointList[0]);
60 var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
61 polygonFeature = new OpenLayers.Feature.Vector(
62 new OpenLayers.Geometry.Polygon([linearRing]));
65 map.addLayer(vectorLayer);
66 map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
67 vectorLayer.addFeatures([pointFeature, lineFeature, polygonFeature]);
70 var origin = new OpenLayers.Geometry.Point(-111.04, 45.68);
72 strokeColor: "#666666",
76 pointerEvents: "visiblePainted"
78 var center = new OpenLayers.Feature.Vector(origin, null, style);
79 vectorLayer.addFeatures([center]);
80 window.setInterval(function() {rotateFeature(
81 pointFeature, 360 / 20, origin)}, 100);
82 window.setInterval(function() {rotateFeature(
83 lineFeature, 360 / 40, origin)}, 100);
84 window.setInterval(function(){rotateFeature(
85 polygonFeature, -360 / 20, origin)}, 100);
88 function rotateFeature(feature, angle, origin) {
89 feature.geometry.rotate(angle, origin);
90 feature.layer.drawFeature(feature);
94 <body onload="init()">
95 <h1 id="title">Rotate vector features</h1>
100 Details on how to create and rotate vector features programmatically
103 <div id="map" class="smallmap"></div>
104 <div id="docs">This example shows a few features rotating. There is not yet a control
105 built that provides a tool for rotating, but the geometry.rotate method
106 can be accessed to rotate programmatically.</div>