From: <dco...@us...> - 2009-02-13 13:55:06
|
Revision: 2161 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=2161&view=rev Author: dcorpataux Date: 2009-02-13 13:54:54 +0000 (Fri, 13 Feb 2009) Log Message: ----------- Enhanced and bugfixed digitizing Modified Paths: -------------- sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/MapDrawComponent.js sandbox/geocat.ch/trunk/web/geonetwork/xsl/extent-edit.xsl Modified: sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/MapDrawComponent.js =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/MapDrawComponent.js 2009-02-13 13:53:32 UTC (rev 2160) +++ sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/MapDrawComponent.js 2009-02-13 13:54:54 UTC (rev 2161) @@ -21,6 +21,8 @@ multiFeatures: false, // shall the user draw multiple polygons? activate: false, // activates draw component? + onClearFeatures: function() {}, + /** * Constructor: MapDrawComponent * @@ -55,7 +57,7 @@ var prevCreateFeature = this.control.handler.createFeature; var self = this; this.control.handler.createFeature = function() { - self.vectorLayer.destroyFeatures(); + self.clearFeatures(); return prevCreateFeature.apply(this, arguments); }; } @@ -69,7 +71,7 @@ this.toolbar.add({ iconCls: this.toolbarControlClearIconCls, //toggleGroup: this.toolbarControlToggleGroup, - handler: function() { this.vectorLayer.destroyFeatures() }, + handler: function(button) { this.clearFeatures() }, scope: this }); } @@ -78,15 +80,31 @@ }, + clearFeatures: function() { + this.vectorLayer.destroyFeatures(); + this.onClearFeatures(); + }, + /** * Returns a string representing the feature geometry */ - getFeatureGeom: function(format) { + writeFeature: function(format) { var format = format || 'WKT'; var writer = new OpenLayers.Format[format](); if (!this.vectorLayer.features.length) return null; // Gets the last drawn feature var feature = this.vectorLayer.features[this.vectorLayer.features.length-1]; return writer.write(feature); + }, + + readFeature: function(string, format) { + var format = format || 'WKT'; + var reader = new OpenLayers.Format[format](); + var feature = reader.read(string); + // reader is subject to returning an object or an array depending on the format + if (!feature) return false; + if (feature.length) feature = feature[0]; + this.vectorLayer.addFeatures(feature); + return true; } }); \ No newline at end of file Modified: sandbox/geocat.ch/trunk/web/geonetwork/xsl/extent-edit.xsl =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/xsl/extent-edit.xsl 2009-02-13 13:53:32 UTC (rev 2160) +++ sandbox/geocat.ch/trunk/web/geonetwork/xsl/extent-edit.xsl 2009-02-13 13:54:54 UTC (rev 2161) @@ -14,20 +14,45 @@ <script language="JavaScript1.2" type="text/javascript"> Ext.onReady(initMapComponent) function initMapComponent() { + // Creates map component mapCmp = new MapComponent('olMap', {displayLayertree: false}); drawCmp = new MapDrawComponent(mapCmp.map, { toolbar: mapCmp.toolbar, controlOptions: { title: 'Draw shape', - featureAdded: featureAdded + featureAdded: writeGeometry }, activate: true }); + + // Form behaviour + $('geom').observe('keydown', function() { + oldGeom = $('geom').value; + }); + $('geom').observe('keyup', function() { + if (oldGeom != $('geom').value) { + drawCmp.clearFeatures(); + } + readGeometry(); + }); + Ext.each($('editform').format, function(i) { + i.observe('click', function() { + writeGeometry() + }); + }) + readGeometry(); } - function featureAdded(f) { - var format = Ext.get('WKT').dom.checked ? 'WKT' : 'GML'; - Ext.get('geom').dom.value = drawCmp.getFeatureGeom(format); + function writeGeometry() { + var format = getSelectedFormat(); + Ext.get('geom').dom.value = drawCmp.writeFeature(format); } + function readGeometry() { + drawCmp.clearFeatures(); + drawCmp.readFeature($('geom').value, getSelectedFormat()); + } + function getSelectedFormat() { + return Ext.get('WKT').dom.checked ? 'WKT' : 'GML'; + } </script> <!--<xsl:apply-templates mode="script" select="/"/> @@ -65,11 +90,10 @@ <P> <table> <tr><td>Description:</td><td><input type="text" name="desc" size="50" value="{/root/response/wfs/featureType/feature/desc}"/></td></tr> - <tr><td>Geometry:</td><td><textarea name="geom" id="geom" cols="50" rows="10"><xsl:value-of select="/root/response/wfs/featureType/feature/geom"/></textarea></td> </tr> - <tr><td><INPUT type="radio" name="format" id="WKT" value="WKT" checked="true"/> WKT + <tr><td>Geometry:</td><td><textarea name="geom" id="geom" cols="50" rows="4"><xsl:value-of select="/root/response/wfs/featureType/feature/geom"/></textarea></td> </tr> + <tr><td><INPUT type="submit" value="Send"/> <INPUT type="reset"/></td><td><INPUT type="radio" name="format" id="WKT" value="WKT" checked="checked"/> WKT <INPUT type="radio" name="format" value="GML 2"/> GML 2 <INPUT type="radio" name="format" value="GML 3"/> GML 3</td> </tr> - <tr><td> <INPUT type="submit" value="Send"/> <INPUT type="reset"/></td> </tr> <tr><td colspan="2"><div id="olMap"></div></td></tr> </table> </P> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |