MapFish Client Protocol Abstraction
Proposal for the implementation of a feature protocol abstraction in MapFish Client.
Note: incidentally this proposal is very similar to OpenLayers Protocol proposal. The Protocol and WFS classes defined below could become part of OpenLayers. If so, MapFish will only include mapfish.Protocol.MapFish, which will inherit from the OpenLayers.Protocol abstract class.
Abstract class
mapfish.Protocol = OpenLayers.Class({ url: null, callbacks: { read: function() {}, create: function() {}, update: function() {}, delete: function() {} }, initialize: function(options) { this.url = options.url; OpenLayers.Util.extend(this.callbacks, options.callbacks); } read: function() { /* abstract method */ }, create: function() { /* abstract method */ }, update: function() { /* abstract method */ }, delete: function() { /* abstract method */ } });
MapFish Protocol class
mapfish.Protocol.mapfish = OpenLayers.Class(mapfish.Protocol, { initialize: function(options) { mapfish.Protocol.prototype.initialize.apply(this, arguments); } read: function() { ... mapfish.Request.GET({ url:this.url, callback: this.callbacks.read, ... }); ... }, create: function(features) { ... var format = OpenLayers.Format.GeoJSON(); var geojson = format.write(features); mapfish.Request.POST({ url: this.url, callback: this.callbacks.create, data: geojson, ... }); ... }, update: function(feature) { ... var format = OpenLayers.Format.GeoJSON(); var geojson = format.write(feature); var url = this.url + '/' + feature.fid; mapfish.Request.PUT({ url: url, callback: this.callbacks.update, data: geojson, ... }); ... }, delete: function(feature) { ... var format = OpenLayers.Format.GeoJSON(); var geojson = format.write(feature); var url = this.url + '/' + feature.fid; mapfish.Request.DELETE({ url: url, callback: this.callbacks.delete, data: geojson, ... }); ... } });
Implementation considerations
Currently, OpenLayers Ajax code doesn't support PUT and DELETE. There's plan to include Tim Schaub's Request code.
In the meantime, I propose to include Tim's code in MapFish. Once it's in OpenLayers we can remove it from MapFish.
Tim's code is made up of two files: lib/OpenLayers/Request.js and lib/OpenLayers/Request/XMLHttpRequest.js.
- lib/OpenLayers/Request.js -> mfbase/mapfish/core/Request.js
- lib/OpenLayers/Request/XMLHttpRequest.js -> mfbase/mapfish/core/Request/XMLHttpRequest.js
The OpenLayers namespace will be changed to mapfish.
WFS/WFS-T Protocol class
mapfish.Protocol.WFS = OpenLayers.Class(mapfish.Protocol, { initialize: function(options) { mapfish.Protocol.prototype.initialize.apply(this, arguments); } read: function() { ... }, create: function() { ... }, update: function() { ... }, delete: function() { ... } });
