[OpenLayers-Dev] Add Vector attributes
geojoe
jwolter at wisc.edu
Tue Nov 17 16:51:35 EST 2009
What I really need to know is how to is (1, 2, and 4):
1. Select features from a (PostgreSQL) layer where ownerID = myID
2. Draw the result set as a vector layer with a siteID attribute.
3. Add and enable a drag drop control.
4. After a feature is moved 'onComplete', update the feature geom in the
(PostgreSQL) layer
5. Refresh the layer 'layer.redraw(true)'.
function init() {
...
if( myID>0 ) {
mySiteVectors = new OpenLayers.Layer.Vector("My Sites",
{style: result_style, 'displayInLayerSwitcher': true});
map.addLayer(mySiteVectors);
map_controls = {
drag: new OpenLayers.Control.DragFeature( mySiteVectors,
{ 'onComplete': updateGeom })
};
for(var key in map_controls) {
map.addControl(map_controls[key]);
}
createSiteFeatures(myID);
}
...
}
/* Should be getting info from "all_sites" (PostGres) layer where ownerID =
myID. */
function createSiteFeatures(myId) {
var colors = ["red", "orange", "yellow", "green", "blue", "purple",
"black", "black"];
var features = new Array(20);
var x,y, fill;
var cnt, layers, layer,siteID;
var cosLat = Math.cos(44*Math.PI/180);
var cX = mapExtent[0]; //lower left X google 900913
var cY = mapExtent[1]; //lower left Y
var dY = Math.abs( (mapExtent[3] - mapExtent[1])/2 );
var dX = Math.abs( (mapExtent[2] - mapExtent[0]) ) / cosLat;
layers = map.getLayersByName("My Sites");
if( layers ) {
layer = layers[0];
} else {return false;};
for(var i=0; i<features.length; i++) {
x = cX + (Math.random()*dX);
y = cY + (Math.random()*dY);
siteID = '"'+i+'"';
fill = colors[5];//colors[Math.round((colors.length - 1) *
Math.random())];
features[i] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(x, y),null, {fillColor: fill,
pointRadius: 8, "siteId":siteID}
);
}
layer.addFeatures(features);
layer.setOpacity(0.5);
toggleControl("drag");
return 1;
}
--
View this message in context: http://n2.nabble.com/Add-Vector-attributes-tp4015032p4021549.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
More information about the Dev
mailing list