]> dev.renevier.net Git - syp.git/blob - openlayers/examples/resize-features.html
reset openlayers directory to its original state at the end of build.sh
[syp.git] / openlayers / examples / resize-features.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2   <head>
3     <title>OpenLayers Resize 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, vectorLayer, 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             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         }
70
71         var origin = new OpenLayers.Geometry.Point(-111.04, 45.68);
72         function resizeFeatures(scale) {
73             pointFeature.geometry.resize(scale, origin);
74             lineFeature.geometry.resize(scale, origin);
75             polygonFeature.geometry.resize(scale, origin);
76             vectorLayer.redraw();
77         }
78
79     </script>
80   </head>
81   <body onload="init()">
82     <h3 id="title">Resize Features Programatically</h3>
83     <p id="shortdesc">
84       Demonstration of how to use the geometry resize methods to
85       change feature sizes programatically.
86     </p>  
87     <div id="map" class="smallmap"></div>
88     <p>This example demonstrates how features can be resized.  There is not yet
89     a control built that provides a tool for resizing, but the geometry.resize
90     method can be accessed to resize programmatically.</p>
91     <p>Make the features <a href="javascript: resizeFeatures(1.5);">bigger</a>
92     or <a href="javascript: resizeFeatures(1 / 1.5);">smaller</a>.
93   </body>
94 </html>