Преглед на файлове

Merge branch 'feature-wfs-t' of biuro.biall-net.pl:plabudda/se into feature-wfs-t

Marek Strzała преди 11 години
родител
ревизия
85cda4d60a

+ 35 - 29
SE/se-lib/TableAjax.php

@@ -887,7 +887,8 @@ class TableAjax extends ViewAjax {
 								case "geom":
 									cellCnt.html('<i class="cell-mapfld icon-map-marker"></i>');
 									cellCnt.on('click', {recordID: cellID, fieldValue: val}, function(e) {
-										console.log('clicked:', e.data.recordID, 'val:', e.data.fieldValue);
+										priv.mapEditorShow();
+										_mapEditor.TableAjaxMapSelectRecord(e.data.recordID, e.data.fieldValue);
 									});
 									break;
 							}
@@ -1525,38 +1526,43 @@ class TableAjax extends ViewAjax {
 			_mapEditorDialog.dialog("destroy");
 		}
 
+		priv.mapEditorShow = function() {
+			priv.options.mapEditor = true;
+			_mapEditorWrap.show();
+			_mapEditor.TableAjaxMap({
+				wpsUrl: 'http://biuro.biall-net.pl/wps',
+				wfsUrl: 'http://biuro.biall-net.pl/wps',
+				layerName: '<?php echo $this->getLabelHtml(); ?>',
+				onfeatureselect: function() {
+					// this.selectedFeatures
+					console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
+				},
+				onfeatureselect: function() {
+					console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
+				}
+			});
+
+			_mapEditorDialog = _mapEditorWrap.dialog({
+				width: 540,
+				minWidth: 400,
+				minHeight: 300,
+				resizeStop: function(){
+					_mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
+				},
+				dragStop: function(){
+					_mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
+				}
+			});
+			_mapEditorWrap.bind('dialogclose', function(e) {
+				priv.options.mapEditor = false;
+			});
+		}
+
 		priv.mapEditorChanged = function(e) {
 			console.log('mapEditorChanged option(',priv.options.mapEditor,') e:', e);
 			priv.options.mapEditor = !priv.options.mapEditor;
 			if (priv.options.mapEditor) {
-				_mapEditorWrap.show();
-				_mapEditor.TableAjaxMap({
-					wpsUrl: 'http://biuro.biall-net.pl/wps',
-					wfsUrl: 'http://biuro.biall-net.pl/wps',
-					layerName: '<?php echo $this->getLabelHtml(); ?>',
-					onfeatureselect: function() {
-						// this.selectedFeatures
-						console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
-					},
-					onfeatureselect: function() {
-						console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
-					}
-				});
-
-				_mapEditorDialog = _mapEditorWrap.dialog({
-					width: 540,
-					minWidth: 400,
-					minHeight: 300,
-					resizeStop: function(){
-						_mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
-					},
-					dragStop: function(){
-						_mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
-					}
-				});
-				_mapEditorWrap.bind('dialogclose', function(e) {
-					priv.options.mapEditor = false;
-				});
+				priv.mapEditorShow();
 			}
 			else {
 				priv.mapEditorHide();

+ 259 - 12
SE/se-lib/TableAjaxMap.php

@@ -33,6 +33,10 @@ class TableAjaxMap {
 .TableAjaxMap { width:100%; height:<?php echo $this->_height; ?>px; }
 .olControlEditingToolbar .olControlModifyFeatureItemInactive { background-image:url(stuff/open-layers/theme/default/img/draw_point_off.png); }
 .olControlEditingToolbar .olControlModifyFeatureItemActive   { background-image:url(stuff/open-layers/theme/default/img/draw_point_on.png); }
+.olControlEditingToolbar .olControlRefreshItemInactive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_off.png); }
+.olControlEditingToolbar .olControlRefreshItemActive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_on.png); }
+.olControlEditingToolbar .olControlSaveItemInactive { background-image: url(stuff/open-layers/theme/default/img/save_features_off.png); }
+.olControlEditingToolbar .olControlSaveItemActive { background-image: url(stuff/open-layers/theme/default/img/save_features_on.png); }
 .olControlLayerSwitcher .layersDiv { border-radius:10px 0 0 10px; opacity:0.75; filter:alpha(opacity=75); }
 .notsupported { color:red; }
 .TableAjaxMap .layersDiv input { margin:0; }
@@ -96,6 +100,9 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			_nodeAbstract = $('<p></p>');
 			_nodeInput = $('<div></div>');
 			_nodeOutput = $('<div></div>');
+			_selectedFeature = null;
+			_selectedRecordId = 0;
+
 			var div = $('<div></div>');
 			div.append(_nodeProcesses);
 			div.append(_nodeAbstract);
@@ -139,6 +146,59 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 					featureType: "restricted",
 					geometryName: "the_geom",
 					schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
+				}),
+				styleMap: new OpenLayers.StyleMap({
+					'default': new OpenLayers.Style(null, {
+						rules: [
+							new OpenLayers.Rule({
+								symbolizer: {
+									stroke: true,
+									fill: true,
+									fillColor: "#90EE90",
+									strokeColor: "#90EE90",
+								}
+							})
+							, new OpenLayers.Rule({
+								symbolizer: {
+									stroke: true,
+									fill: true,
+									fillColor: "#ee9900",
+									strokeColor: "#ee9900",
+								},
+								filter: new OpenLayers.Filter.Comparison({
+									type: OpenLayers.Filter.Comparison.GREATER_THAN,
+									property: "recordId",
+									value: 0
+								})
+							})
+							, new OpenLayers.Rule({
+								symbolizer: {
+									stroke: true,
+									fill: true,
+									fillColor: "#ff0000",
+									strokeColor: "#ff0000",
+								},
+								filter: new OpenLayers.Filter.Comparison({
+									type: OpenLayers.Filter.Comparison.GREATER_THAN,
+									property: "_newRecordId",
+									value: 0
+								})
+							})
+							, new OpenLayers.Rule({
+								symbolizer: {
+									stroke: true,
+									fill: true,
+									fillColor: "#ff0000",
+									strokeColor: "#ff0000",
+								},
+								filter: new OpenLayers.Filter.Comparison({
+									type: OpenLayers.Filter.Comparison.GREATER_THAN,
+									property: "_modified",
+									value: 0
+								})
+							})
+						]
+					})
 				})
 			});
 
@@ -157,28 +217,101 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 					}
 				}
 			});
+			_layer.events.on({
+				'beforefeaturemodified': function(e) {
+					console.log('Event: beforefeaturemodified modified(', e.feature.attributes._modified, ')', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
+					// NOTE: beforefeaturemodified from new node is fired before afterfeaturemodified from old node when click from one shape to enother
+					priv.checkSelectedFeatureModifications('before');
+					priv.setSelectedFeature(e.feature);
+				},
+				'featuremodified': function(e) {
+					console.log('Event: featuremodified modified(', e.feature.attributes._modified, ') ', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
+					_selectedFeature.attributes._modified = 1;
+				},
+				'afterfeaturemodified': function(e) {
+					console.log('Event: afterfeaturemodified fid('+e.feature.fid+'/'+(_selectedFeature ? _selectedFeature.fid : 'null')+') modified(', e.feature.attributes._modified, ') ', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
+					if (_selectedFeature && _selectedFeature.fid != e.feature.fid) {
+						console.log('Event: afterfeaturemodified pomiń check!');
+					} else {
+						priv.checkSelectedFeatureModifications('after');
+						priv.setSelectedFeature(null);
+					}
+				}
+			});
+
 
 			var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
-			toolbar.addControls([new OpenLayers.Control.ModifyFeature(_layer, {
-				title: "Select feature"
-			})]);
 			toolbar.addControls([
-				new OpenLayers.Control.SelectFeature(
-				_layer,
-				{
-					clickout: false, toggle: false,
-					multiple: false, hover: false,
+				new OpenLayers.Control.ModifyFeature(_layer, {
+					title: "Edytuj"
+					, mode: OpenLayers.Control.ModifyFeature.DRAG | OpenLayers.Control.ModifyFeature.RESHAPE
+				})
+			]);
+			toolbar.addControls([
+				new OpenLayers.Control.SelectFeature(_layer, {
+					title: "Select Test",
+					clickout: false,
+					toggle: false,
+					multiple: false,
+					hover: false,
 					toggleKey: "ctrlKey", // ctrl key removes from selection
 					multipleKey: "shiftKey", // shift key adds to selection
 					box: true
 				})
 			]);
+			toolbar.addControls([
+				new OpenLayers.Control.Button({
+					title: "Refresh",
+					displayClass: "olControlRefresh",
+					trigger: function() {
+						_layer.refresh({force: true});
+					}
+				})
+			]);
+			toolbar.addControls([
+				new OpenLayers.Control.Button({
+					title: "Test mark as recordId 999",
+					displayClass: "olControlSave",
+					trigger: function() {
+						if (_selectedFeature) {
+							if (!_selectedRecordId) {
+								alert('Select Record from table');
+							}
+							else {
+								_selectedFeature.attributes['tblId'] = <?php echo $this->_zasobID; ?>;
+								_selectedFeature.attributes['recordId'] = _selectedRecordId;
+							}
+						}
+						else {
+							alert('Select feature')
+						}
+					}
+				})
+			]);
 
 			var extent = new OpenLayers.Bounds(
 				2035059.4410645328, 7200979.560689885, 2113330.958028555, 7279251.0776539035
 			);
 
-			var gphy =  new OpenLayers.Layer.OSM("Mapa");
+			var gphy =  new OpenLayers.Layer.OSM("Mapa", null, {
+				resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
+					19567.87923828125, 9783.939619140625, 4891.9698095703125,
+					2445.9849047851562, 1222.9924523925781, 611.4962261962891,
+					305.74811309814453, 152.87405654907226, 76.43702827453613,
+					38.218514137268066, 19.109257068634033, 9.554628534317017,
+					4.777314267158508, 2.388657133579254, 1.194328566789627,
+					0.5971642833948135, 0.25, 0.1, 0.05],
+				serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
+					19567.87923828125, 9783.939619140625,
+					4891.9698095703125, 2445.9849047851562,
+					1222.9924523925781, 611.4962261962891,
+					305.74811309814453, 152.87405654907226,
+					76.43702827453613, 38.218514137268066,
+					19.109257068634033, 9.554628534317017,
+					4.777314267158508, 2.388657133579254,
+					1.194328566789627, 0.5971642833948135],
+				transitionEffect: 'resize'
+			});
 
 			_map = new OpenLayers.Map(_nodeMapId, {
 				projection: new OpenLayers.Projection("EPSG:900913"),
@@ -194,9 +327,76 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 				],
 				layers: [gphy,_layer]
 			});
+
 			_map.zoomToMaxExtent();
 		};
 
+		priv.updateState = function() {
+			// TODO: update state view
+			//console.log('updateState: _selectedFeature:', _selectedFeature, ' _selectedRecordId:', _selectedRecordId);
+			if (_selectedFeature || _selectedRecordId) {
+				
+			} else {
+				
+			}
+		};
+
+		priv.setSelectedFeature = function(feature) {
+			_selectedFeature = feature;
+			priv.updateState();
+		};
+
+		priv.setSelectedRecordId = function(id) {
+			_selectedRecordId = id;
+			priv.updateState();
+		};
+
+		priv.getSelectedRecordId = function() {
+			return _selectedRecordId;
+		};
+
+		priv.isSelectedRecordId = function() {
+			return _selectedRecordId > 0;
+		};
+
+		priv.isSelectedFeature = function() {
+			return !!_selectedFeature;
+		};
+
+		priv.cancelSelectedFeatureModifications = function() {
+			if (!_selectedFeature) return false;
+			if (_selectedFeature.attributes._newRecordId) {
+				delete _selectedFeature.attributes._newRecordId;
+			}
+			if (_selectedFeature.attributes._modified) {
+				delete _selectedFeature.attributes._modified;
+			}
+		};
+
+		priv.isSelectedFeatureModified = function() {
+			if (!_selectedFeature) return false;
+			if (_selectedFeature.attributes) {
+				if (_selectedFeature.attributes._newRecordId) {
+					return true;
+				}
+				if (_selectedFeature.attributes._modified) {
+					return true;
+				}
+			}
+		};
+
+		priv.checkSelectedFeatureModifications = function(when) {
+			if (priv.isSelectedFeatureModified()) {
+				if (confirm('Anulować zmiany wprowadzone dla zaznaczonego elementu?' + when)) {
+					priv.cancelSelectedFeatureModifications();
+					_layer.refresh({force:true});
+				}
+				else {
+					// _layer.refresh();
+				}
+			}
+		};
+
 		// using OpenLayers.Format.WPSCapabilities to read the capabilities
 		priv.getCapabilities = function() {
 			OpenLayers.Request.GET({
@@ -502,6 +702,32 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			_map.updateSize();
 		};
 
+		publ.zoomToExtent = function(extent) {
+			var extentBounds = OpenLayers.Geometry.fromWKT(extent).getBounds();
+			_map.zoomToExtent(extentBounds);
+		};
+
+		publ.selectRecord = function(recordId, extent) {
+			if (priv.isSelectedRecordId()) {
+				if (priv.getSelectedRecordId() != recordId) {
+					if (priv.isSelectedFeature()) {
+						if (confirm('Aktualnie przypisany rekord to ' + priv.getSelectedRecordId() + ' czy zmienić na ' + recordId + '?')) {
+							priv.setSelectedRecordId(recordId);
+						}
+					} else {
+						priv.setSelectedRecordId(recordId);
+						publ.zoomToExtent(extent);
+					}
+				} else {
+					publ.zoomToExtent(extent);
+				}
+			}
+			else {
+				priv.setSelectedRecordId(recordId);
+				publ.zoomToExtent(extent);
+			}
+		};
+
 		publ.init = function(options) {
 			if (priv.options.debug) console.log('TableAjaxMap initialization...', options);
 			//merge supplied options with defaults
@@ -515,15 +741,36 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 	$.fn.TableAjaxMapUpdateSize = function(options) {
 		options = options || {};
 		return this.each(function() {
-			options.id = this;
-			if ($(this).data('TableAjaxMap')) {
-				var tblAjaxMap = $(this).data('TableAjaxMap');
+			var tblAjaxMap = $(this).data('TableAjaxMap');
+			if (tblAjaxMap) {
 				tblAjaxMap.updateSize();
 			}
 		});
 		return this;
 	};
 
+	$.fn.TableAjaxMapZoomToExtent = function(extent) {
+		if (!extent) return;
+		return this.each(function() {
+			var tblAjaxMap = $(this).data('TableAjaxMap');
+			if (tblAjaxMap) {
+				tblAjaxMap.zoomToExtent(extent);
+			}
+		});
+		return this;
+	};
+
+	$.fn.TableAjaxMapSelectRecord = function(recordId, extent) {
+		if (!recordId) return;
+		return this.each(function() {
+			var tblAjaxMap = $(this).data('TableAjaxMap');
+			if (tblAjaxMap) {
+				tblAjaxMap.selectRecord(recordId, extent);
+			}
+		});
+		return this;
+	};
+
 	$.fn.TableAjaxMap = function(options) {
 		options = options || {};
 		return this.each(function() {

BIN
SE/stuff/open-layers/theme/default/img/draw_point_off.png


BIN
SE/stuff/open-layers/theme/default/img/draw_point_on.png


BIN
SE/stuff/open-layers/theme/default/img/refresh_feature_off.png


BIN
SE/stuff/open-layers/theme/default/img/refresh_feature_on.png