[OpenLayers-Commits] r2349 - sandbox/vector-2.4/examples
commits at openlayers.org
commits at openlayers.org
Mon Mar 5 17:14:40 EST 2007
Author: tschaub
Date: 2007-03-05 17:14:39 -0500 (Mon, 05 Mar 2007)
New Revision: 2349
Added:
sandbox/vector-2.4/examples/vector-features.html
Log:
example showing simple vector features
Added: sandbox/vector-2.4/examples/vector-features.html
===================================================================
--- sandbox/vector-2.4/examples/vector-features.html (rev 0)
+++ sandbox/vector-2.4/examples/vector-features.html 2007-03-05 22:14:39 UTC (rev 2349)
@@ -0,0 +1,63 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <style type="text/css">
+ #map {
+ width: 800px;
+ height: 475px;
+ border: 1px solid black;
+ }
+ </style>
+ <script src="../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ <!--
+ var map;
+
+ function init(){
+ map = new OpenLayers.Map( $('map') );
+ var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
+ "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
+ map.addLayer(layer);
+ var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
+
+ // create a point feature
+ var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
+ var pointFeature = new OpenLayers.Feature.Vector(vectorLayer, point);
+
+ // create a line feature from a list of points
+ var pointList = [];
+ var newPoint = point;
+ for(var p=0; p<5; ++p) {
+ newPoint = new OpenLayers.Geometry.Point(newPoint.x + Math.random(1),
+ newPoint.y + Math.random(1));
+ pointList.push(newPoint);
+ }
+ var lineFeature = new OpenLayers.Feature.Vector(vectorLayer,
+ new OpenLayers.Geometry.LineString(pointList));
+
+ // create a polygon feature from a linear ring of points
+ var pointList = [];
+ for(var p=0; p<6; ++p) {
+ var a = p * (2 * Math.PI) / 7;
+ var r = Math.random(1) + 1;
+ var newPoint = new OpenLayers.Geometry.Point(point.x + (r * Math.cos(a)),
+ point.y + (r * Math.sin(a)));
+ pointList.push(newPoint);
+ }
+ pointList.push(pointList[0]);
+
+ var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
+ var polygonFeature = new OpenLayers.Feature.Vector(vectorLayer,
+ new OpenLayers.Geometry.Polygon([linearRing]));
+
+
+ map.addLayer(vectorLayer);
+ map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
+ vectorLayer.addFeatures([pointFeature, lineFeature, polygonFeature]);
+ }
+ // -->
+ </script>
+ </head>
+ <body onload="init()">
+ <div id="map"></div>
+ </body>
+</html>
More information about the Commits
mailing list