]> dev.renevier.net Git - syp.git/blob - openlayers/examples/rotate-features.html
initial commit
[syp.git] / openlayers / examples / rotate-features.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2   <head>
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">
7         p {
8             width: 500px;
9         }
10     </style>
11     <script src="../lib/OpenLayers.js"></script>
12     <script type="text/javascript">
13         var map, pointFeature, lineFeature, polygonFeature;
14
15         function init(){
16             map = new OpenLayers.Map('map');
17             var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
18                     "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
19             map.addLayer(layer);
20             
21             var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
22             style_blue.strokeColor = "blue"; 
23             style_blue.fillColor = "blue"; 
24             var style_green = {
25                 strokeColor: "#339933",
26                 strokeOpacity: 1,
27                 strokeWidth: 3,
28                 pointRadius: 6,
29                 pointerEvents: "visiblePainted"
30             };
31             
32             var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
33             
34             // create a point feature
35             var point = new OpenLayers.Geometry.Point(-110, 45);
36             pointFeature = new OpenLayers.Feature.Vector(point, null, style_blue);
37             
38             // create a line feature from a list of points
39             var pointList = [];
40             var newPoint = point;
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);
45             }
46             lineFeature = new OpenLayers.Feature.Vector(
47                 new OpenLayers.Geometry.LineString(pointList),null,style_green);
48             
49             // create a polygon feature from a linear ring of points
50             var pointList = [];
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);
57             }
58             pointList.push(pointList[0]);
59             
60             var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
61             polygonFeature = new OpenLayers.Feature.Vector(
62                 new OpenLayers.Geometry.Polygon([linearRing]));
63                 
64             
65             map.addLayer(vectorLayer);
66             map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
67             vectorLayer.addFeatures([pointFeature, lineFeature, polygonFeature]);
68             
69             // start rotating
70             var origin = new OpenLayers.Geometry.Point(-111.04, 45.68);
71             var style = {
72                 strokeColor: "#666666",
73                 strokeOpacity: 1,
74                 strokeWidth: 1,
75                 pointRadius: 2,
76                 pointerEvents: "visiblePainted"
77             };
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);
86         }
87
88         function rotateFeature(feature, angle, origin) {
89             feature.geometry.rotate(angle, origin);
90             feature.layer.drawFeature(feature);
91         }
92     </script>
93   </head>
94   <body onload="init()">
95     <h1 id="title">Rotate vector features</h1>
96
97   <div id="tags">
98   </div>
99   <p id="shortdesc">
100       Details on how to create and rotate vector features programmatically
101   </p>
102
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>
107   </body>
108 </html>