[OpenLayers-Commits] r7304 - in sandbox/camptocamp/unhcr: lib lib/OpenLayers lib/OpenLayers/Control lib/OpenLayers/Feature lib/OpenLayers/Format lib/OpenLayers/Format/GML lib/OpenLayers/Lang lib/OpenLayers/Layer lib/OpenLayers/Protocol lib/OpenLayers/Protocol/WFS lib/OpenLayers/Strategy tests tests/Feature tests/Layer
commits at openlayers.org
commits at openlayers.org
Tue Jun 3 04:17:14 EDT 2008
Author: elemoine
Date: 2008-06-03 04:17:13 -0400 (Tue, 03 Jun 2008)
New Revision: 7304
Added:
sandbox/camptocamp/unhcr/lib/OpenLayers/Lang/sv-SE.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/GreedySave.js
Modified:
sandbox/camptocamp/unhcr/lib/OpenLayers.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Control/Permalink.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Feature/Vector.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML/Base.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Google.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Grid.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Vector.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFS/v1_0_0.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFSV.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/Save.js
sandbox/camptocamp/unhcr/lib/OpenLayers/Util.js
sandbox/camptocamp/unhcr/tests/Feature/Vector.html
sandbox/camptocamp/unhcr/tests/Layer/Vector.html
sandbox/camptocamp/unhcr/tests/Util.html
Log:
sync with vector-behavior
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Control/Permalink.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Control/Permalink.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Control/Permalink.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -5,6 +5,7 @@
/**
* @requires OpenLayers/Control.js
+ * @requires OpenLayers/Control/ArgParser.js
*/
/**
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Feature/Vector.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Feature/Vector.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Feature/Vector.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -113,9 +113,10 @@
* {<OpenLayers.Feature.Vector>} An exact clone of this vector feature.
*/
clone: function () {
- return new OpenLayers.Feature.Vector(this.geometry ? this.geometry.clone() : null,
- this.attributes,
- this.style);
+ return new OpenLayers.Feature.Vector(
+ this.geometry ? this.geometry.clone() : null,
+ this.attributes,
+ this.style);
},
/**
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML/Base.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML/Base.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML/Base.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -161,7 +161,7 @@
// GML3
"pos": function(node, obj) {
var str = this.getChildValue(node).replace(
- this.regExes, trimSpace, ""
+ this.regExes.trimSpace, ""
);
var coords = str.split(this.regExes.splitSpace);
var point;
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Format/GML.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -136,7 +136,7 @@
* node - {DOMElement} A GML feature node.
*/
parseFeature: function(node) {
- // only accept on geometry per feature - look for highest "order"
+ // only accept one geometry per feature - look for highest "order"
var order = ["MultiPolygon", "Polygon",
"MultiLineString", "LineString",
"MultiPoint", "Point", "Envelope"];
Copied: sandbox/camptocamp/unhcr/lib/OpenLayers/Lang/sv-SE.js (from rev 7303, sandbox/vector-behavior/lib/OpenLayers/Lang/sv-SE.js)
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Lang/sv-SE.js (rev 0)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Lang/sv-SE.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -0,0 +1,121 @@
+/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
+ * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Lang.js
+ */
+
+/**
+ * Namespace: OpenLayers.Lang["sv-SE"]
+ * Dictionary for swedish (Sweden). Keys for entries are used in calls to
+ * <OpenLayers.Lang.translate>. Entry bodies are normal strings or
+ * strings formatted for use with <OpenLayers.String.format> calls.
+ */
+OpenLayers.Lang["sv-SE"] = {
+
+ 'unhandledRequest': "Ej hanterad fråga retur ${statusText}",
+
+ 'permalink': "Permalänk",
+
+ 'overlays': "Kartlager",
+
+ 'baseLayer': "Bakgrundskarta",
+
+ 'sameProjection':
+ "Översiktskartan fungerar endast när den har samma projektion som huvudkartan",
+
+ 'readNotImplemented': "Läsning ej implementerad.",
+
+ 'writeNotImplemented': "Skrivning ej implementerad.",
+
+ 'noFID': "Kan ej uppdatera feature (objekt) för vilket FID saknas.",
+
+ 'errorLoadingGML': "Fel i laddning av GML-fil ${url}",
+
+ 'browserNotSupported':
+ "Din webbläsare stöder inte vektorvisning. För närvarande stöds följande visning:\n${renderers}",
+
+ 'componentShouldBe': "addFeatures : komponenten skall vara en ${geomType}",
+
+ // console message
+ 'getFeatureError':
+ "getFeatureFromEvent anropad för lager utan utritning. Detta betyder oftast att man " +
+ "raderat ett lager, men inte en hanterare som är knuten till lagret.",
+
+ // console message
+ 'minZoomLevelError':
+ "Egenskapen minZoomLevel är endast avsedd att användas " +
+ "med lager med FixedZoomLevels. Att detta WFS-lager " +
+ "kontrollerar minZoomLevel är en relik från äldre versioner. " +
+ "Vi kan dock inte ta bort det utan att riskera att " +
+ "OL-baserade tillämpningar som använder detta slutar " +
+ "fungera. Därför är det satt som deprecated, minZoomLevel " +
+ "kommer att tas bort i version 3.0. Använd i stället " +
+ "inställning av min/max resolution som beskrivs här: " +
+ "http://trac.openlayers.org/wiki/SettingZoomLevels",
+
+ 'commitSuccess': "WFS-transaktion: LYCKADES ${response}",
+
+ 'commitFailed': "WFS-transaktion: MISSLYCKADES ${response}",
+
+ 'googleWarning':
+ "Google-lagret kunde inte laddas korrekt.<br><br>" +
+ "För att slippa detta meddelande, välj en annan bakgrundskarta " +
+ "i lagerväljaren i övre högra hörnet.<br><br>" +
+ "Sannolikt beror felet på att Google Maps-biblioteket " +
+ "inte är inkluderat på webbsidan eller på att sidan " +
+ "inte anger korrekt API-nyckel för webbplatsen.<br><br>" +
+ "Utvecklare: hjälp för att åtgärda detta, " +
+ "<a href='http://trac.openlayers.org/wiki/Google' " +
+ "target='_blank'>klicka här</a>.",
+
+ 'getLayerWarning':
+ "${layerType}-lagret kunde inte laddas korrekt.<br><br>" +
+ "För att slippa detta meddelande, välj en annan bakgrundskarta " +
+ "i lagerväljaren i övre högra hörnet.<br><br>" +
+ "Sannolikt beror felet på att ${layerLib}-biblioteket " +
+ "inte är inkluderat på webbsidan.<br><br>" +
+ "Utvecklare: hjälp för att åtgärda detta, " +
+ "<a href='http://trac.openlayers.org/wiki/${layerLib}' " +
+ "target='_blank'>klicka här</a>.",
+
+ 'scale': "<strong>Skala</strong> 1 : ${scaleDenom}",
+
+ // console message
+ 'layerAlreadyAdded':
+ "Du försökte lägga till lagret: ${layerName} på kartan, men det har lagts till tidigare",
+
+ // console message
+ 'reprojectDeprecated':
+ "Du använder inställningen 'reproject' på lagret ${layerName}. " +
+ "Denna inställning markerad som deprecated: den var avsedd " +
+ "att användas för att stödja visning av kartdata på kommersiella " +
+ "bakgrundskartor, men nu bör man i stället " +
+ "använda Spherical Mercator-stöd för den funktionaliteten. " +
+ "Mer information finns " +
+ "på http://trac.openlayers.org/wiki/SphericalMercator.",
+
+ // console message
+ 'methodDeprecated':
+ "Denna metod är markerad som deprecated och kommer att tas bort i 3.0. " +
+ "Använd ${newMethod} i stället.",
+
+ // console message
+ 'boundsAddError': "Du måste skicka både x- och y-värde till funktionen add.",
+
+ // console message
+ 'lonlatAddError': "Du måste skicka både lon- och lat-värde till funktionen add.",
+
+ // console message
+ 'pixelAddError': "Du måste skicka både x- och y-värde till funktionen add.",
+
+ // console message
+ 'unsupportedGeometryType': "Stöd saknas för geometritypen: ${geomType}",
+
+ // console message
+ 'pagePositionFailed':
+ "OpenLayers.Util.pagePosition misslyckades: elementet med id ${elemId} kan placeras fel.",
+
+ 'end': ''
+};
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Google.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Google.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Google.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -189,8 +189,27 @@
* evt - {Event}
*/
onMapResize: function() {
- this.mapObject.checkResize();
+ if(this.visibility) {
+ this.mapObject.checkResize();
+ } else {
+ this.windowResized = true;
+ }
},
+
+ /**
+ * Method: display
+ * Hide or show the layer
+ *
+ * Parameters:
+ * display - {Boolean}
+ */
+ display: function(display) {
+ OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments);
+ if(this.div.style.display == "block" && this.windowResized) {
+ this.mapObject.checkResize();
+ this.windowResized = false;
+ }
+ },
/**
* APIMethod: getZoomForExtent
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Grid.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Grid.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -353,7 +353,7 @@
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
Math.max(1, 2 * this.buffer);
- var extent = this.map.getMaxExtent();
+ var extent = this.maxExtent;
var resolution = this.map.getResolution();
var tileLayout = this.calculateGridLayout(bounds, extent, resolution);
@@ -719,7 +719,7 @@
* {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
*/
getTileBounds: function(viewPortPx) {
- var maxExtent = this.map.getMaxExtent();
+ var maxExtent = this.maxExtent;
var resolution = this.getResolution();
var tileMapWidth = resolution * this.tileSize.w;
var tileMapHeight = resolution * this.tileSize.h;
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Vector.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Vector.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Layer/Vector.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -46,7 +46,7 @@
* object passed to listeners will have a *features* property with a
* reference to an array of added features.
* - *beforefeatureremoved* Triggered before a feature is removed. Listeners
- * wll receive an object with a *feature* property referencing the
+ * will receive an object with a *feature* property referencing the
* feature to be removed.
* - *featureremoved* Triggerd after a feature is removed. The event
* object passed to listeners will have a *feature* property with a
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFS/v1_0_0.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -168,7 +168,7 @@
});
if(params.filter){
- this.setPropertyName(params.filter);
+ this.setFilterProperty(params.filter);
var filterNode = this.filterFormat.write(params.filter);
query.appendChild(filterNode);
}
@@ -263,16 +263,16 @@
},
/**
- * Method: setPropertyName
+ * Method: setFilterProperty
* Set the property of each spatial filter.
*
* Parameters:
* filter - {<OpenLayers.Filter>}
*/
- setPropertyName: function(filter) {
+ setFilterProperty: function(filter) {
if (filter.filters) {
for (var i = 0; i < filter.filters.length; i++) {
- this.setProperty(filter.filters[i]);
+ this.setFilterProperty(filter.filters[i]);
}
} else {
var filterType = filter.CLASS_NAME.substring(
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFSV.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFSV.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Protocol/WFSV.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -25,6 +25,20 @@
},
/**
+ * Property: VERSIONING_ATTRIBUTES
+ * {Array} An array of the names of attributes associated with versioning, determined by the
+ * versioning back end, and so not meant to be editable by a user.
+ */
+ VERSIONING_ATTRIBUTES : ["createdBy",
+ "creationDate",
+ "creationVersion",
+ "lastUpdateVersion",
+ "lastUpdatedBy",
+ "lastUpdateDate",
+ "creationMessage",
+ "lastUpdateMessage"],
+
+ /**
* Property: namespaces
* {Object} Namespace dictionary keyed by namespace alias.
*/
@@ -41,6 +55,11 @@
readRequestName: "wfsv:GetVersionedFeature",
/**
+ * Property: wfsvFormat
+ */
+ wfsvFormat : null,
+
+ /**
* Constructor: OpenLayers.Protocol.WFS
* A class for giving layers WFS protocol.
*
@@ -49,17 +68,58 @@
* instance.
*/
initialize: function(options) {
- OpenLayers.Protocol.WFS.v1_0_0.prototype.initialize.apply(this, [options]);
+ OpenLayers.Protocol.WFS.v1_0_0.prototype.initialize.apply(this, [options]);
},
+ setFormat: function(format){
+ OpenLayers.Protocol.WFS.v1_0_0.prototype.setFormat.apply(this, arguments);
+ this.wfsvFormat = new OpenLayers.Format.GML.Base({featureNS : this.format.featureNS});
+ },
+
/**
* APIMethod: destroy
* Clean up the protocol.
*/
destroy: function() {
+ this.wfsvFormat = null;
OpenLayers.Protocol.WFS.v1_0_0.prototype.destroy.apply(this);
},
+ /**
+ * Method: readResponse
+ * Read HTTP response body and return features.
+ * Overriding the base class' readResponse to remove versioning attributes
+ * and put them in a safe place.
+ *
+ * Parameters:
+ * request - {Object} The request object
+ *
+ * Returns:
+ * {Array({<OpenLayers.Feature.Vector>})} or
+ * {<OpenLayers.Feature.Vector>} Array of features or a single feature.
+ */
+ readResponse: function(request) {
+ var features = OpenLayers.Protocol.WFS.v1_0_0.prototype.readResponse.apply(this, [request]);
+
+ for(var i = 0; i < features.length; i++){
+ this.handleVersioningAttributes(features[i]);
+ }
+
+ return features;
+ },
+
+ handleVersioningAttributes : function(feature) {
+ feature.versioning = {};
+
+ for (var i = 0; i < this.VERSIONING_ATTRIBUTES.length; i++) {
+ var key = this.VERSIONING_ATTRIBUTES[i];
+
+ feature.versioning[key] = feature.attributes[key];
+
+ delete feature.attributes[key];
+ }
+ },
+
/**
* getLog
*/
@@ -85,7 +145,7 @@
root.appendChild(query);
var postCallback = function(request){
- var resp = new OpenLayers.Protocol.Response({
+ var resp = new OpenLayers.Protocol.Response({
'features': null
});
if(request.status >= 200 && request.status < 300) {
@@ -141,11 +201,30 @@
root.appendChild(query);
+ var postCallback = function(request){
+ var resp = new OpenLayers.Protocol.Response({
+ 'features': null
+ });
+ if(request.status >= 200 && request.status < 300) {
+ // success
+ resp.features = this.readTransaction(request);
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
+ }
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
+ );
+ }
+
var data = this.format.write(root);
return OpenLayers.Request.POST({
url: this.url,
data: data,
+ callback : postCallback,
+ scope: this
})
},
@@ -158,6 +237,135 @@
}
});
},
-
+
+ /**
+ * APIMethod: readTransaction
+ * Read a set of transactions from a string, and return a list of "features" encoding that data.
+ *
+ * Parameters:
+ * data - {String} or {DOMElement} data to read/parse.
+ *
+ * Returns:
+ * {Array(<OpenLayers.Feature.Vector>)} An array of features.
+ */
+ //TODO: functionalize out some of this code
+ /*
+ * Note: A lot of the work done here looks like the sort of thing that should
+ * be done by a Format class, instead of a Protocol. Perhaps this stuff should
+ * be moved to that kind of Format, which could extend GML and by stored as an
+ * extra, protocol-specific format like the filterFormat on the WFS Protocol.
+ *
+ * It can assume GML formating for now because that is the only format
+ * supported for WFSV.
+ */
+ readTransaction: function(request){
+
+ var data = request.responseXML;
+ if (!data || !data.documentElement) {
+ data = request.responseText;
+ }
+ if (!data || data.length <= 0) {
+ return null;
+ }
+
+ if(typeof data == "string") {
+ data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
+ }
+
+ var features = [];
+
+ this.readInsertNodes(data, features);
+ this.readUpdateNodes(data, features);
+ this.readDeleteNode(data, features);
+
+ return features;
+ },
+
+ readInsertNodes : function(data, features){
+ var insertNodes = this.format.getElementsByTagNameNS(data.documentElement,
+ "*",
+ "Insert");
+
+ for(var i = 0; i < insertNodes.length; i++){
+ var featureNode = this.format.getElementsByTagNameNS(insertNodes[i],this.format.featureNS, this.format.layerName)[0];
+
+ var feature = this.format.parseFeature(featureNode);
+
+ feature.state = OpenLayers.State.INSERT;
+ features.push(feature);
+ }
+ },
+
+ readUpdateNodes : function(data, features){
+ var updateNodes = this.format.getElementsByTagNameNS(data.documentElement,
+ "*",
+ "Update");
+
+ for(var i = 0; i < updateNodes.length; i++){
+ var node = updateNodes[i];
+
+ var feature = new OpenLayers.Feature.Vector(null, {});
+
+ var properties = this.format.getElementsByTagNameNS(node,"*","Property");
+
+ for(var j = 0; j < properties.length; j++){
+
+ var property = properties[j];
+
+ var nameNode = this.format.getElementsByTagNameNS(property,"*","Name")[0];
+ var name = nameNode.textContent;
+
+ var valueNode = this.format.getElementsByTagNameNS(property,"*","Value")[0];
+
+ if(name == this.format.geometryName){
+ var geoNode = this.format.getElementsByTagNameNS(valueNode,this.wfsvFormat.namespaces.gml,"*")[0];
+
+ var foo = {components : []};
+
+ this.wfsvFormat.readSelf.apply(this.wfsvFormat, [geoNode, foo]);
+
+ feature.geometry = foo.components[0];
+ }else{
+ var value = valueNode.textContent;
+ feature.attributes[name] = value;
+ }
+ }
+
+ //give the feature the proper fid
+ var filter = this.format.getElementsByTagNameNS(node,"*","Filter")[0];
+ //anticipate only one featureId here.
+ var featureId = this.format.getElementsByTagNameNS(filter,"*","FeatureId")[0]
+ var fid = this.format.getAttributeNS(featureId,"","fid");
+ feature.fid = fid;
+
+ feature.state = OpenLayers.State.UPDATE;
+
+ features.push(feature)
+ }
+ },
+
+ readDeleteNode : function(data, features){
+ //anticipating only one delete node with several FeatureId nodes within
+ var deleteNode = this.format.getElementsByTagNameNS(data.documentElement,
+ "*",
+ "Delete")[0];
+ var featureIdNodes = this.format.getElementsByTagNameNS(deleteNode,
+ "*",
+ "FeatureId");
+
+ for(var i = 0; i < featureIdNodes.length; i++) {
+ var node = featureIdNodes[i];
+
+ var fid = this.format.getAttributeNS(node,"","fid");
+
+ var feature = new OpenLayers.Feature.Vector(null, {});
+
+ feature.fid = fid;
+ feature.state = OpenLayers.State.DELETE;
+
+ features.push(feature);
+ }
+ },
+
CLASS_NAME: "OpenLayers.Protocol.WFSV"
});
Copied: sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/GreedySave.js (from rev 7303, sandbox/vector-behavior/lib/OpenLayers/Strategy/GreedySave.js)
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/GreedySave.js (rev 0)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/GreedySave.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -0,0 +1,69 @@
+/**
+ * @requires OpenLayers/Strategy/Save.js
+ */
+
+/**
+ * Class: OpenLayers.Strategy.GreedySave
+ * A strategy that commits modifications to all features upon the save() function call.
+ * Unlike the vanilla Save strategy, this strategy will "greedily" read features back
+ * into OpenLayers through the Protocol after they are inserted.
+ *
+ * Use this strategy when information about features that is added to a feature when
+ * it is inserted does not get returned to the save() callback.
+ *
+ * Inherits from:
+ * - OpenLayers.Strategy.Save
+ */
+OpenLayers.Strategy.GreedySave = new OpenLayers.Class(OpenLayers.Strategy.Save, {
+
+ /**
+ * Constructor: OpenLayers.Strategy.Save
+ * Create a new Save strategy.
+ *
+ * Parameters:
+ * options - {Object} Optional object whose properties will be set on the
+ * instance.
+ */
+ initialize: function(options) {
+ OpenLayers.Strategy.Save.prototype.initialize.apply(this, [options]);
+ },
+
+ /**
+ * APIMethod: destroy
+ * Clean up the strategy.
+ */
+ destroy: function() {
+ OpenLayers.Strategy.Save.prototype.destroy.apply(this, arguments);
+ },
+
+ onCommit : function(features,object){
+ var state;
+
+ if (object.success) {
+ //Updates and deletes Deletes
+ this.manageFeatureStates(features);
+
+ var inserts = object.inserts;
+
+ if (inserts[0] != "none") {
+ var fidFilter = new OpenLayers.Filter.FeatureId({fids: inserts});
+
+ params = {
+ filter: fidFilter,
+ srsName: this.layer.projection.getCode()
+ };
+
+ this.layer.protocol.read({
+ params: params,
+ callback: function(resp) {
+ this.remove();
+ this.merge(resp.features);
+ },
+ scope: this
+ });
+ }
+ }
+ },
+
+ CLASS_NAME: "OpenLayers.Strategy.GreedySave"
+});
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/Save.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/Save.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Strategy/Save.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -43,6 +43,10 @@
* Given all features on a layer, determine which ones to remove.
*/
remove: function() {
+ //Not clear how this method should actually be used
+ //since there are both inserts and deletes to be dealt with
+ //at different times?
+
//find all the features with state Insert, and destroy them
var features = [];
@@ -97,17 +101,7 @@
if (object.success) {
//Updates and deletes Deletes
- for (var i = 0; i < features.length; i++) {
- state = features[i].state;
-
- if (state == OpenLayers.State.UPDATE) {
- features[i].state = null;
- }
-
- if (state == OpenLayers.State.DELETE) {
- this.layer.destroyFeatures([features[i]]);
- }
- }
+ this.manageFeatureStates(features);
var inserts = object.inserts;
@@ -124,6 +118,21 @@
}
}
},
+
+ //not a great name for this
+ manageFeatureStates : function(features){
+ for (var i = 0; i < features.length; i++) {
+ state = features[i].state;
+
+ if (state == OpenLayers.State.UPDATE) {
+ features[i].state = null;
+ }
+
+ if (state == OpenLayers.State.DELETE) {
+ this.layer.destroyFeatures([features[i]]);
+ }
+ }
+ },
CLASS_NAME: "OpenLayers.Strategy.Save"
});
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers/Util.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers/Util.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers/Util.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -427,8 +427,9 @@
"relative", border);
if (OpenLayers.Util.alphaHack()) {
-
- div.style.display = "inline-block";
+ if(div.style.display != "none") {
+ div.style.display = "inline-block";
+ }
if (sizing == null) {
sizing = "scale";
}
Modified: sandbox/camptocamp/unhcr/lib/OpenLayers.js
===================================================================
--- sandbox/camptocamp/unhcr/lib/OpenLayers.js 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/lib/OpenLayers.js 2008-06-03 08:17:13 UTC (rev 7304)
@@ -190,6 +190,7 @@
"OpenLayers/Strategy/Composer.js",
"OpenLayers/Strategy/Fixed.js",
"OpenLayers/Strategy/Save.js",
+ "OpenLayers/Strategy/GreedySave.js",
"OpenLayers/Strategy/Autosave.js",
"OpenLayers/Protocol.js",
"OpenLayers/Protocol/HTTP.js",
Modified: sandbox/camptocamp/unhcr/tests/Feature/Vector.html
===================================================================
--- sandbox/camptocamp/unhcr/tests/Feature/Vector.html 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/tests/Feature/Vector.html 2008-06-03 08:17:13 UTC (rev 7304)
@@ -59,7 +59,7 @@
}
function test_Feature_Vector_clone(t) {
- t.plan(5);
+ t.plan(6);
var geometry = new OpenLayers.Geometry.Point(Math.random(),
Math.random());
@@ -79,6 +79,11 @@
"geometry.x property set properly");
t.eq(clone.geometry.y, geometry.y,
"geometry.y property set properly");
+
+ feature = new OpenLayers.Feature.Vector();
+ clone = feature.clone();
+ t.ok(clone instanceof OpenLayers.Feature.Vector,
+ "clone can clone geometry-less features");
}
Modified: sandbox/camptocamp/unhcr/tests/Layer/Vector.html
===================================================================
--- sandbox/camptocamp/unhcr/tests/Layer/Vector.html 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/tests/Layer/Vector.html 2008-06-03 08:17:13 UTC (rev 7304)
@@ -67,7 +67,7 @@
}
function test_Layer_Vector_removeFeatures(t) {
- t.plan(3);
+ t.plan(6);
var layer = new OpenLayers.Layer.Vector(name);
@@ -75,7 +75,7 @@
var pointFeature1 = new OpenLayers.Feature.Vector(layer, point1);
var point2 = new OpenLayers.Geometry.Point(-111.14, 45.78);
var pointFeature2 = new OpenLayers.Feature.Vector(layer, point2);
-
+
layer.addFeatures([pointFeature1, pointFeature2]);
var features = layer.removeFeatures([pointFeature1]);
@@ -88,7 +88,36 @@
t.ok(layer.features.length == 0,
"OpenLayers.Layer.Vector.removeFeatures(layer.features) removes all feature from the features array");
- }
+
+ // 3 tests
+ layer.events.register('beforefeatureremoved', null, function(obj) {
+ t.ok(pointFeature1 == obj.feature,
+ "OpenLayers.Layer.Vector.removeFeatures triggers beforefeatureremoved with correct feature passed to callback");
+ });
+ layer.events.register('featureremoved', null, function(obj) {
+ t.ok(pointFeature1 == obj.feature,
+ "OpenLayers.Layer.Vector.removeFeatures triggers featureremoved with correct feature passed to callback");
+ });
+ layer.events.register('featuresremoved', null, function(obj) {
+ t.ok(pointFeature1 == obj.features[0],
+ "OpenLayers.Layer.Vector.removeFeatures triggers featuresremoved with correct features passed to callback");
+ });
+ layer.addFeatures([pointFeature1]);
+ layer.removeFeatures([pointFeature1]);
+
+ // 0 test
+ layer.events.register('beforefeatureremoved', null, function(obj) {
+ t.fail("OpenLayers.Layer.Vector.removeFeatures triggers beforefeatureremoved while it must not");
+ });
+ layer.events.register('featureremoved', null, function(obj) {
+ t.fail("OpenLayers.Layer.Vector.removeFeatures triggers featureremoved while it must not");
+ });
+ layer.events.register('featuresremoved', null, function(obj) {
+ t.fail("OpenLayers.Layer.Vector.removeFeatures triggers featuresremoved while it must not");
+ });
+ layer.addFeatures([pointFeature1]);
+ layer.removeFeatures([pointFeature1], {silent: true});
+ }
function test_Layer_Vector_drawFeature(t) {
t.plan(4);
Modified: sandbox/camptocamp/unhcr/tests/Util.html
===================================================================
--- sandbox/camptocamp/unhcr/tests/Util.html 2008-06-03 08:03:49 UTC (rev 7303)
+++ sandbox/camptocamp/unhcr/tests/Util.html 2008-06-03 08:17:13 UTC (rev 7304)
@@ -400,7 +400,7 @@
}
function test_Util_modifyAlphaImageDiv(t) {
- t.plan( 19 );
+ t.plan( 20 );
var imageDiv = OpenLayers.Util.createAlphaImageDiv();
@@ -460,8 +460,6 @@
if (OpenLayers.Util.alphaHack()) {
- t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly");
-
var filter = "progid:DXImageTransform.Microsoft" +
".AlphaImageLoader(src='" + img + "', " +
"sizingMethod='" + sizing + "') alpha(opacity=" + opacity *100 + ")";
@@ -476,6 +474,20 @@
t.ok(true, "image filter value not set (not in IE)");
}
+ var imageDiv = OpenLayers.Util.createAlphaImageDiv();
+ var display = "none";
+ imageDiv.style.display = display;
+ OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing, opacity);
+ t.eq(imageDiv.style.display, display, "imageDiv.style.display set correctly, if 'none'");
+
+ var imageDiv = OpenLayers.Util.createAlphaImageDiv();
+ var display = "block";
+ imageDiv.style.display = display;
+ OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing, opacity);
+ t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly, if not 'none'");
+
+
+
var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border, "scale", opacity);
if (OpenLayers.Util.alphaHack()) {
var filter = "progid:DXImageTransform.Microsoft" +
More information about the Commits
mailing list