| Platform: | OpenLayers |
| Task: | Build a bounding box polygon and put it on an OpenLayers map |
| Discussion: | Build a bounding box polygon and put it on an OpenLayers map |
| Example: | function BuildBoundingBox(){
var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayer(vectorLayer);
var proj = new OpenLayers.Projection("EPSG:4326");
var style_green = {strokeColor: "#ff3300",strokeOpacity: 1,strokeWidth: 2,fillColor: "#FF9966",fillOpacity: 0.1};
var p1 = new OpenLayers.Geometry.Point(-154,64)
p1.transform(proj, map.getProjectionObject());
var p2 = new OpenLayers.Geometry.Point(-154,67)
p2.transform(proj, map.getProjectionObject());
var p3 = new OpenLayers.Geometry.Point(-150,67)
p3.transform(proj, map.getProjectionObject());
var p4 = new OpenLayers.Geometry.Point(-150,65)
p4.transform(proj, map.getProjectionObject());
var points = [];
points.push(p1);
points.push(p2);
points.push(p3);
points.push(p4);
var poly = new OpenLayers.Geometry.LinearRing(points);
var polygonFeature = new OpenLayers.Feature.Vector(poly, null, style_green);
vectorLayer.addFeatures([polygonFeature]);
} |