1 <html xmlns="http://www.w3.org/1999/xhtml">
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">
11 map = new OpenLayers.Map('map');
13 var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
14 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
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;
21 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
22 styleMap: new OpenLayers.StyleMap({'default':{
23 strokeColor: "#00FF00",
29 pointerEvents: "visiblePainted",
30 label : "name: ${name}, age: ${age}",
32 fontColor: "${favColor}",
34 fontFamily: "Courier New, monospace",
36 labelAlign: "${align}"
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 = {
51 // create a polygon feature from a linear ring of points
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);
60 pointList.push(pointList[0]);
62 var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
63 var polygonFeature = new OpenLayers.Feature.Vector(
64 new OpenLayers.Geometry.Polygon([linearRing]));
65 polygonFeature.attributes = {
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)
78 new OpenLayers.Geometry.Point(-105, 40)
81 name: "ball-and-chain",
86 var nullFeature = new OpenLayers.Feature.Vector(null);
87 nullFeature.attributes = {
88 name: "toto is some text about the world",
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 ]);
101 <body onload="init()">
102 <h1 id="title">OpenLayers Labeled features example</h1>
103 <div id="tags"></div>
105 Label vector features with a text symbolizer.
107 <div id="map" class="smallmap"></div>
109 This example shows drawing simple vector features with a label