[OpenLayers-Users] Create Objects from Database
gabriel
gpetricek at gmail.com
Fri Mar 22 04:13:26 PDT 2013
Hi,
if you want only read data from database try this:
new layer = new ol.Layer.Vector("vehicle",
{
strategies: [new o.Strategy.BBOX()],
protocol: new o.Protocol.WFS
({
url:<url to your mapserver>,
featureType:"<name of the table you want to add>",
featureNS:"<namespace>",
geometryName:"<geometry name, default is the_geom>",
version:"1.1.0" // version of WFS
})
});
map. addLayer(layer);
Ofcourse, this example works with mapserver (MapServer, Geoserver....)
If you want to add new obects into table you must create saveStrategy object
and add it to layer.
For example:
var saveStrategy = new ol.StrategySave();
var layer = new ol.Layer.Vector("name",{
strategies: [new o.Strategy.BBOX(), saveStrategy],
....
});
Then you need to create for example button to save new geometry.
var button = document.getElementById("button_save");
button.onclick = function() {
saveStrategy.save();
}
This process will save only geometry into table. If you want to add
attributes too you should do something like this:
var layer = new ol.Layer.Vector("name", {
strategies:.....,
protocol({.....}),
eventListener:{
beforefeatureadded:function(e)
{
e.feature.attributes.buffer = window.prompt("add buffer value");
}
}
}) ;
thats only example.
There is another
:http://openlayers.org/dev/examples/wfs-protocol-transactions.html
Last thing, you need to create draw control, to draw vectors(polygon, point,
line).
Look this http://openlayers.org/dev/examples/draw-feature.html
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Create-Objects-from-Database-tp5042303p5042317.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list