1 <html xmlns="http://www.w3.org/1999/xhtml">
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">
11 <script src="../lib/OpenLayers.js"></script>
12 <script type="text/javascript">
13 var map, vectorLayer, 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 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]);
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);
81 <body onload="init()">
82 <h3 id="title">Resize Features Programatically</h3>
84 Demonstration of how to use the geometry resize methods to
85 change feature sizes programatically.
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>.