respec / leaflet.wfs-t

Leaflet plug-in for WFS Transactional (WFS-T) support
BSD 2-Clause "Simplified" License
42 stars 12 forks source link

leaflet.wfs-t and leaflet.gml

Leaflet plug-in for WFS Transactional (WFS-T) support.

WFS-T is an OGC standard protocol which allows you to add, update and delete features and attributes from a compliant server.

One easy way to use the leaflet.wfs-t plugin is with the Leaflet.Draw plugin. With leaflet.wfs-t the shapes you draw, modify or delete from the map will have their status reflected on your WFS-T server.

Included with leaflet.wfs-t is leaflet.gml which adds a toGML() function to each Leaflet geometry type (although, they're not all implemented yet).

Current Status and Known Bugs

Installing, Testing

Set up a Leaflet map with the Leaflet.Draw plugin.

Add the WFST layer. It currently extends the L.GeoJSON layer so any GeoJSON options should work too.

// A global layers object
layers = {};

// Initialize the WFST layer to store editable layers
// The options object (2nd parameter) has 4 required fields:
// 1) url             : The WFS service URL
// 2) featureNS       : The feature Namespace
// 3) featureType     : The feature Type within the namespace
// 4) primaryKeyField : The primary key field

layers.drawnItems = L.wfst(null,{
    url : 'http://localhost/geoserver/wfsttest/wfs',
    featureNS : 'wfsttest',
    featureType : 'doodles',
    primaryKeyField: 'id',
}).addTo(map);

Point Leaflet.Draw at the wfst layer.

// Initialize the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw({
    edit: {
        featureGroup: layers.drawnItems
    }
});

Add Leaflet.Draw handlers for the draw:created and draw:edited events.

map.on('draw:created', function (e) {
    layers.drawnItems.addLayer(e.layer);
});
map.on('draw:edited', function (e) {
    layers.drawnItems.wfstSave(e.layers);
});