]> dev.renevier.net Git - syp.git/blob - openlayers/examples/vector-features-with-text.html
initial commit
[syp.git] / openlayers / examples / vector-features-with-text.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2   <head>
3     <title>OpenLayers Labeled 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     <script src="../lib/OpenLayers.js"></script>
7     <script type="text/javascript">
8         var map;
9
10         function init(){
11             map = new OpenLayers.Map('map');
12             
13             var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
14                     "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
15             map.addLayer(layer);
16             
17             // allow testing of specific renderers via "?renderer=Canvas", etc
18             var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
19             renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
20             
21             var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
22                 styleMap: new OpenLayers.StyleMap({'default':{
23                     strokeColor: "#00FF00",
24                     strokeOpacity: 1,
25                     strokeWidth: 3,
26                     fillColor: "#FF5500",
27                     fillOpacity: 0.5,
28                     pointRadius: 6,
29                     pointerEvents: "visiblePainted",
30                     label : "name: ${name}, age: ${age}",
31                     
32                     fontColor: "${favColor}",
33                     fontSize: "12px",
34                     fontFamily: "Courier New, monospace",
35                     fontWeight: "bold",
36                     labelAlign: "${align}"
37                 }}),
38                 renderers: renderer
39             });
40             
41             // create a point feature
42             var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
43             var pointFeature = new OpenLayers.Feature.Vector(point);
44             pointFeature.attributes = {
45                 name: "toto",
46                 age: 20,
47                 favColor: 'red',
48                 align: "cm"
49             };
50             
51             // create a polygon feature from a linear ring of points
52             var pointList = [];
53             for(var p=0; p<6; ++p) {
54                 var a = p * (2 * Math.PI) / 7;
55                 var r = Math.random(1) + 1;
56                 var newPoint = new OpenLayers.Geometry.Point(point.x + 5 + (r * Math.cos(a)),
57                                                              point.y + 5 + (r * Math.sin(a)));
58                 pointList.push(newPoint);
59             }
60             pointList.push(pointList[0]);
61             
62             var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
63             var polygonFeature = new OpenLayers.Feature.Vector(
64                 new OpenLayers.Geometry.Polygon([linearRing]));
65             polygonFeature.attributes = {
66                 name: "dude",
67                 age: 21,
68                 favColor: 'purple',
69                 align: 'lb'
70             };
71             
72             multiFeature = new OpenLayers.Feature.Vector(
73                 new OpenLayers.Geometry.Collection([
74                     new OpenLayers.Geometry.LineString([
75                         new OpenLayers.Geometry.Point(-105,40),
76                         new OpenLayers.Geometry.Point(-95,45)
77                     ]),
78                     new OpenLayers.Geometry.Point(-105, 40)
79                 ]),
80                 {
81                     name: "ball-and-chain",
82                     age: 30,
83                     favColor: 'black',
84                     align: 'rt'
85                 });
86             var nullFeature = new OpenLayers.Feature.Vector(null);
87             nullFeature.attributes = {
88                 name: "toto is some text about the world",
89                 age: 20,
90                 favColor: 'red',
91                 align: "cm"
92             };
93             
94             map.addLayer(vectorLayer);
95             vectorLayer.drawFeature(multiFeature);
96             map.setCenter(new OpenLayers.LonLat(point.x, point.y), 3);
97             vectorLayer.addFeatures([pointFeature, polygonFeature, multiFeature, nullFeature ]);
98         }
99     </script>
100   </head>
101   <body onload="init()">
102     <h1 id="title">OpenLayers Labeled features example</h1>
103     <div id="tags"></div>
104     <p id="shortdesc">
105         Label vector features with a text symbolizer.
106     </p>
107     <div id="map" class="smallmap"></div>
108     <div id="docs">
109     This example shows drawing simple vector features with a label
110     </div>
111   </body>
112 </html>