I have in my database longitude-latitude verticies from user-defined polygons. My questions is: how do I recreate and display them on a map now? This is quite easy to do with the Google Maps API, but I can't find any documentation or examples on how to do this with OpenLayers. Has anyone had any experience doing this?
+1
A:
After a lot of experimenting, I found out how to do it:
site_style = {
// style_definition
};
for (i in coordinates) {
point = new OpenLayers.Geometry.Point(coordinates[i].lng, coordinates[i].lat);
point.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
site_points.push(point);
}
site_points.push(site_points[0]);
var linear_ring = new OpenLayers.Geometry.LinearRing(site_points);
polygonFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon([linear_ring]), null, site_style);
vectors.addFeatures([polygonFeature]);
Scotty
2010-10-24 05:12:28