git-svn-id: http://svn.openlayers.org/trunk/openlayers@3369 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
80 lines
3.1 KiB
HTML
80 lines
3.1 KiB
HTML
<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 style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
|
|
style_blue.strokeColor = "blue";
|
|
style_blue.fillColor = "blue";
|
|
var style_green = {
|
|
strokeColor: "#00FF00",
|
|
strokeOpacity: 1,
|
|
strokeWidth: 3,
|
|
pointRadius: 6,
|
|
pointerEvents: "visiblePainted"
|
|
};
|
|
|
|
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(point,null,style_blue);
|
|
|
|
// 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(
|
|
new OpenLayers.Geometry.LineString(pointList),null,style_green);
|
|
|
|
// 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(
|
|
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>
|
|
<p>This example shows drawing simple vector features -- point, line, polygon
|
|
in different styles, created 'manually', by constructing the entire style
|
|
object, via 'copy', extending the default style object, and by
|
|
inheriting the default style from the layer.</p>
|
|
</body>
|
|
</html>
|