[Mapbender-commits] r8451 - in trunk/mapbender/http: javascripts plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 10 04:30:44 PDT 2012


Author: armin11
Date: 2012-08-10 04:30:43 -0700 (Fri, 10 Aug 2012)
New Revision: 8451

Modified:
   trunk/mapbender/http/javascripts/mb_downloadFeedClient.js
   trunk/mapbender/http/plugins/mb_downloadFeedClient.php
   trunk/mapbender/http/plugins/mb_downloadFeedServer.php
Log:
Some more functions for atom feed client

Modified: trunk/mapbender/http/javascripts/mb_downloadFeedClient.js
===================================================================
--- trunk/mapbender/http/javascripts/mb_downloadFeedClient.js	2012-08-08 15:19:06 UTC (rev 8450)
+++ trunk/mapbender/http/javascripts/mb_downloadFeedClient.js	2012-08-10 11:30:43 UTC (rev 8451)
@@ -1,4 +1,4 @@
-var mapframe_dataset_list, mapframe_file_list, datasetSelect, file_list, bboxDataset, bboxFiles, formats;
+var mapframe_dataset_list, mapframe_file_list, datasetSelect, file_list, bboxDataset, bboxFiles, formats, sf;
 
         function updateFormats() {
             var in_options = {
@@ -57,69 +57,58 @@
                 "http://www.gdi-rp-dienste2.rlp.de/cgi-bin/mapserv.fcgi?map=/data/umn/geoportal/karte_rp/rheinland-pfalz-gesamt2.map&", {layers: 'ATKIS-Praes'}, {singleTile: true});
 	var wms2 = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                 "http://www.gdi-rp-dienste2.rlp.de/cgi-bin/mapserv.fcgi?map=/data/umn/geoportal/karte_rp/rheinland-pfalz-gesamt2.map&", {layers: 'ATKIS-Praes'}, {singleTile: true});
-
-
-
+	//Vector layer for the georss polygons of the service feed - maybe more than one 
 	bboxDataset = new OpenLayers.Layer.Vector("Dataset bounding boxes");
-
+	//Vector layer for the georss polygons of one single data feed entry - maybe more than one if the dataset is tiled into different sections 
 	bboxFiles = new OpenLayers.Layer.Vector("File bounding boxes");
 
 	mapframe_dataset_list.addLayers([wms1, bboxDataset]);
-
 	mapframe_dataset_list.addControl(new OpenLayers.Control.MousePosition());
 
-	//mapframe_dataset_list.addControl(new OpenLayers.Control.EditingToolbar(bboxDataset));
-
 	mapframe_file_list.addLayers([wms2, bboxFiles]);
 	mapframe_file_list.addControl(new OpenLayers.Control.MousePosition());
-	//mapframe_file_list.addControl(new OpenLayers.Control.EditingToolbar(bboxFiles));
 
-	var options = {
-		hover: true,
-	}
-
 	updateFormats();
+	//initialize mapframes
 	mapframe_dataset_list.setCenter(new OpenLayers.LonLat(7, 50), 7);
 	mapframe_file_list.setCenter(new OpenLayers.LonLat(7, 50), 7);
-
+	//start parsing when no empty string was found in input for url
+	if ($('#download_feed_url').val() != "") {
+		method =  "getServiceFeedObjectFromUrl";
+        	data = $("#download_feed_url").val();
+		//call server by ajax function
+		callServer(data,method);
+	}
+	//initialize button for load service feed - the first feed will be parsed.
 	$(document).ready(function(e) {
     		$('#download_feed_button').click(function() {
 			method =  "getServiceFeedObjectFromUrl";
         		data = $("#download_feed_url").val();
-			//data = data.serialize();
+			//call server by ajax function
 			callServer(data,method);
     		});
 	});
-	/*$(document).ready(function(e) {
-    		$('#download_feed_button').click(function() {
-			method =  "getDatasetFeedObjectFromUrl";
-        		data = $("#download_feed_url").val();
-			//data = data.serialize();
-			callServer(data,method);
-    		});
-	});*/
-
 }
-
-
-function callServer(data,method) {
+//central function to call server by ajax, result is a featureCollection which is generated by mapbenders server component
+function callServer(data,method,id) {
+	if (id === undefined) id = 0;
 	$.ajax({
   		url: '../plugins/mb_downloadFeedServer.php',
   		type: "post",
-		async: false,
-		data: {url: data, method: method },
+		async: false, //cause reading the first feed may take longer than the second
+		data: {url: data, method: method , id: id},
        		dataType: "json",
   		success: function(result) {
 			if (method == "getServiceFeedObjectFromUrl") {
+				//draw georss polygons from service feed 
 				drawMetadataPolygons(result);
+				//show datasets in a dropdown list
 				showDatasetList(result);
-			//alert(result);
 			}
 			if (method == "getDatasetFeedObjectFromUrl") {
-				//fill dataset feed
-				//alert("got result");
-				showDatasetEntryList(result);
-				//alert(result);
+				//function to draw bboxes of single link to data tile and the corresponding list of tiles 
+				showDatasetEntryList(result, id);
+				
 			}
 			
  		}
@@ -127,63 +116,36 @@
 	return false;
 }
 
-function showDatasetEntryList(featureCollection) {
-	if (featureCollection == null) {
-		alert("No parseable content found");
-		return false;
-	}
-	//if (typeof(datasetSelect) !== 'undefined'){
-	$('#dataset_representation_select').remove();
-	//}
-	//delete old entries
-	var datasetEntrySelect =  $(document.createElement('select')).appendTo('#dataset_representation_list');
-	datasetEntrySelect.attr({'id':'dataset_representation_select'});
-	var selectROptions = "";
-	for(var i=0; i<featureCollection.features.length; ++i) {
-		selectROptions = selectROptions+"<option value='"+featureCollection.features[i].properties.datasetFeedLink+"' url='"+featureCollection.features[i].properties.datasetFeedLink+"'>"+featureCollection.features[i].properties.title+"</option>";
-
-		//var datasetSelectOption =  $(document.createElement('option')).appendTo(datasetSelect);
-		//datasetSelectOption.attr({'value':featureCollection.features[i].id});
-	}
-	datasetEntrySelect.append(selectROptions);
-	fillSectionList(featureCollection, 0)
-	$('#dataset_representation_select').bind('change', function() {
-    		//var $this = $(this);
-		//method =  "getDatasetLinkFromUrl";
-        	//data = $this.val();
-		alert("list changed");
-		//callServer(data,method);
-	});
-
-}
-
 function showDatasetList(featureCollection) {
 	if (featureCollection == null) {
 		alert("No parseable content found");
 		return false;
 	}
-	//if (typeof(datasetSelect) !== 'undefined'){
+	//remove old dataset select option
 	$('#dataset_select').remove();
-	//}
+	//delete identifier anchor
+	$('#dataset_identifier_link').remove();
 	//delete old entries
 	var datasetSelect =  $(document.createElement('select')).appendTo('#dataset_list');
 	datasetSelect.attr({'id':'dataset_select'});
 	var selectOptions = "";
+	//iterate over all single features which con be identified with the entries of the inspire service feed 
 	for(var i=0; i<featureCollection.features.length; ++i) {
 		//fill in first title, rights and abstract in fields
 //alert(featureCollection.features[i].properties.title);//$('#dataset_title').value = "";
 		if (i == 0) {
 			$('#dataset_title').val(featureCollection.features[i].properties.title);
 			$('#dataset_rights').val(featureCollection.features[i].properties.rights);
-			//$('#dataset_title').val() = featureCollection.features[i].properties.title;
+			$('#dataset_abstract').val(featureCollection.features[i].properties.summary);
+			//add identifier anchor
+			identifierAnchor =  $(document.createElement('a')).appendTo('#dataset_identifier');
+			identifierAnchor.attr({'id':'dataset_identifier_link'});
+			identifierAnchor.attr({'href':featureCollection.features[i].properties.metadataLink});
+			identifierAnchor.text(featureCollection.features[i].properties.namespace+"#"+featureCollection.features[i].properties.code);
 		}
 		selectOptions = selectOptions+"<option value='"+featureCollection.features[i].properties.datasetFeedLink+"' url='"+featureCollection.features[i].properties.datasetFeedLink+"'>"+featureCollection.features[i].properties.title+"</option>";
-
-		//var datasetSelectOption =  $(document.createElement('option')).appendTo(datasetSelect);
-		//datasetSelectOption.attr({'value':featureCollection.features[i].id});
 	}
 	datasetSelect.append(selectOptions);
-	
 	$('#dataset_select').bind('change', function() {
     		var $this = $(this);
 		method =  "getDatasetFeedObjectFromUrl";
@@ -191,63 +153,77 @@
 		callServer(data,method);
 	});
 	method =  "getDatasetFeedObjectFromUrl";
-	//call second feed with first entry
+	//call second feed with first entry for default
         data = featureCollection.features[0].properties.datasetFeedLink;
-	//data = data.serialize();
-	callServer(data,method);
+	datasetFeedObject = callServer(data,method);
+	
+}
 
+function showDatasetEntryList(featureCollection, id) {
+	if (id === undefined) id = 0;
+	if (featureCollection == null) {
+		alert("No parseable content found");
+		return false;
+	}
+	//remove select element for the different possible representations (formats, crs, ...)
+	$('#dataset_representation_select').remove();
+	//generate new select element 
+	var datasetEntrySelect =  $(document.createElement('select')).appendTo('#dataset_representation_list');
+	datasetEntrySelect.attr({'id':'dataset_representation_select'});
+	//initialize options
+	var selectROptions = "";
+	//iterate over all possible representations, which are modeled as entries in the dataset feed (here features of the featureCollection)
+	for(var i=0; i<featureCollection.features.length; ++i) {
+		selectROptions = selectROptions+"<option value='"+featureCollection.features[i].properties.datasetFeedLink+"' url='"+featureCollection.features[i].properties.datasetFeedLink+"'>"+featureCollection.features[i].properties.title+"</option>";
+	}
+	datasetEntrySelect.append(selectROptions);
+	fillSectionList(featureCollection, id);
+	$('#dataset_representation_select').bind('change', function() {
+    		//var $this = $(this);
+		//method =  "getDatasetLinkFromUrl";
+        	//data = $this.val(); TODO
+		alert("list changed");
+		//callServer(data,method);
+	});
 }
 
-
 function fillSectionList(featureCollection, k) {
-		//fill graphic
-		//generate features from link list
 		bboxFiles.removeAllFeatures();
 		$('#section_option').remove();
 		//delete old entries
 		//datasetFileSelect =  $(document.createElement('select')).appendTo('#section_select');
 		//datasetFileSelect.attr({'id':'section_file_list'});
 		//datasetFileSelect.attr({'multiple':'multiple'});
-		selectFOptions = "";
-		
-		
-
+		//initialize option string
+		var selectFOptions = "";
                 for (var i = 0; i < featureCollection.features[k].properties.entry[k].link.length; i++) {
                 	ext = featureCollection.features[k].properties.entry[k].link[i]['@attributes'].bbox;
-			
 			extArrayNew = new Array();
-			//extArray = new Array();
-			//alert(extArray[1]);
 			extArray = ext.split(",");
-			
+			//sort array to lat lon
 			extArrayNew[0] = extArray[1];
 			extArrayNew[1] = extArray[0];
 			extArrayNew[2] = extArray[3];
 			extArrayNew[3] = extArray[2];
-
                 	bound = OpenLayers.Bounds.fromArray(extArrayNew);
 			attributes = {id: i, url:featureCollection.features[k].properties.entry[k].link[i]['@attributes'].href};
                 	box = new OpenLayers.Feature.Vector(bound.toGeometry(),attributes);
                 	bboxFiles.addFeatures(box);
-			selectFOptions = selectFOptions+"<option value='"+i+"' url='"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].href+"' title='"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].title+"' onclick='highlightFeatureIndexById("+i+");'>"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].title+"</option>";
-
-			//var datasetSelectOption =  $(document.createElement('option')).appendTo(datasetSelect);
-			//datasetSelectOption.attr({'value':featureCollection.features[i].id});
-			
+			selectFOptions = selectFOptions+"<option value='"+i+"' url='"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].href+"' title='"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].title+"' onclick='highlightFeatureIndexById("+i+");'>"+featureCollection.features[k].properties.entry[k].link[i]['@attributes'].title+"</option>";	
                	}
 		//count features of bboxFiles
 		//bboxFiles if not available show error message
-		selectFOptionsObject = $('#section_file_list').append(selectFOptions);
-		selectFOptionsObject.attr({'id':'section_option'});
+		selectFObject = $(document.createElement('select')).appendTo('#section_list');
+		selectFObject.attr({'id':'section_option'});
+		selectFObject.attr({'multiple':'multiple'});
+		//add options 
+		selectFOptionsObject = $('#section_option').append(selectFOptions);
 		selectFOptionsObject.attr({'width': 300});
 		bound = bboxFiles.getDataExtent();
 		mapframe_file_list.zoomToExtent(bound);
-               // map.addLayers([ol_wms, boxes]);
-              //  map.addControl(new OpenLayers.Control.LayerSwitcher());
 		bboxFiles.events.on({
    			featureselected: function(event) {
         			var feature = event.feature;
-        			//var area = feature.geometry.getArea();
         			var id = feature.attributes.id;
 				var url = feature.attributes.url;
 				$('#section_option option').removeAttr('selected')
@@ -259,20 +235,13 @@
 				} else {
 					alert("un-checked");
 				}
-				alert(url);*/
-        			//var output = "Building: " + id + " Area: " + area.toFixed(2);
-        			//document.getElementById("output-id").innerHTML = output;
-				
+				alert(url);*/				
     			}
 		});
 		
                 sf = new OpenLayers.Control.SelectFeature(bboxFiles);
                 mapframe_file_list.addControl(sf);
                 sf.activate();
-		
-			
-		
-
 }
 
 function drawMetadataPolygons(featureCollection) {
@@ -298,15 +267,15 @@
 }
 
 function highlightFeatureIndexById(id) {
-	var features = bboxFiles.features;
+	features = bboxFiles.features;
 	for(var i=0; i<features.length; ++i) {
 		if(features[i].attributes.id == id) {
 			index = i;
 			break;
 		}
 	}
-	//unselect all
-	sf.unselect(bboxFiles.selectedFeatures[0]);
+	//unselect all if one is selected 
+	sf.unselectAll();
 	sf.select(bboxFiles.features[index]);
 	window.open(bboxFiles.features[index].attributes.url,'download_window');
 }

Modified: trunk/mapbender/http/plugins/mb_downloadFeedClient.php
===================================================================
--- trunk/mapbender/http/plugins/mb_downloadFeedClient.php	2012-08-08 15:19:06 UTC (rev 8450)
+++ trunk/mapbender/http/plugins/mb_downloadFeedClient.php	2012-08-10 11:30:43 UTC (rev 8451)
@@ -2,10 +2,23 @@
 	//http://localhost/mapbender_trunk/plugins/mb_downloadFeedClient.php
 	require_once dirname(__FILE__) . "/../../core/globalSettings.php";
 	require_once dirname(__FILE__) . "/../classes/class_user.php";
+
+if (isset($_REQUEST['url']) & $_REQUEST['url'] != "") {
+	//validate to iso date format YYYY-MM-DD
+	$testMatch = $_REQUEST["url"];
+	$pattern = '/^http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'url: <b>'.$testMatch.'</b> is not a valid url.<br/>'; 
+		die(); 		
+ 	}
+	$url = urldecode($testMatch);
+	$testMatch = NULL;	
+}
+
 ?>
 <html>
 <head>
-<title>INSPIRE ATOM Feed Client</title> 
+<title>INSPIRE ATOM Feed Client - Prototype</title> 
 <meta name="description" content="INSPIRE ATOM Feed Client" xml:lang="en" />
 <meta name="keywords" content="INSPIRE SDI GDI Download" xml:lang="en" />	
 <meta http-equiv="cache-control" content="no-cache">
@@ -41,8 +54,7 @@
 		top: 0;
 		left: 0;
 		width: 325px;
-            	height: 225px;
-            	
+            	height: 225px;	
 	}
         #input {
             width: 512px;
@@ -77,11 +89,11 @@
 </head>
 <body onload="init()">
 <fieldset>
-	<legend><?php echo _mb("INSPIRE Download Service ATOM Feed Client");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Client to download INSPIRE data on an easy way.");?>'}" src="../img/questionmark.png" alt="" /></legend>
+	<legend><?php echo _mb("INSPIRE Download Service ATOM Feed Client - Prototype");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Client to download INSPIRE data on an easy way.");?>'}" src="../img/questionmark.png" alt="" /></legend>
 	<p>    
 		<form id="service_feed_form">
 		<label for="download_feed_url"><?php echo _mb("ATOM Feed url");?></label>
-		<input name="download_feed_url" id="download_feed_url" class="required"/><input type="button" title="Get Feed" id="download_feed_button" value="Get Feed Content"/>
+		<input name="download_feed_url" id="download_feed_url" class="required" <?php if (isset($url)) {echo " value=\"".$url."\"";} else { echo " value=\"";}?>/><input type="button" title="Get Feed" id="download_feed_button" value="Get Feed Content"/>
 		</form>
 	</p>
 	<fieldset>
@@ -101,8 +113,12 @@
 		<input readonly="readonly" name="dataset_title" id="dataset_title"/>
 	</p>
 	<p>
-		<label for="resource_identifier"><?php echo _mb("Resource identifier");?>:</label>
-		<input readonly="readonly" name="resource_identifier" id="resource_identifier"/>
+		<label for="dataset_abstract"><?php echo _mb("Dataset abstract");?>:</label>
+		<input type="text" readonly="readonly" name="dataset_abstract" id="dataset_abstract" width="250px" height="20px"/>
+	</p>	
+	<p>
+		<!--<label for="resource_identifier"><?php echo _mb("Resource identifier");?>:</label>-->
+		<div id="dataset_identifier"><?php echo _mb("Resource identifier");?>:</div>
 	</p>
 	<p>
 		<label for="dataset_rights"><?php echo _mb("Rights");?>:</label>
@@ -116,23 +132,15 @@
 </fieldset>
 <fieldset>
 	<legend><?php echo _mb("Files");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Files which can be downloaded");?>'}" src="../img/questionmark.png" alt="" /></legend>
-	<div>
-		<input id="multi_select" type="checkbox" disabled><?php echo _mb("Select multiple tiles");?></input><br>
-		<label for="mapframe_file_list"><?php echo _mb("Position of files (if available)");?>:</label>
-		<!--<input type="list" id="file_list"/>-->
-		
-		<div id="mapframe_file_list"></div>
-		<label for="section_list"><?php echo _mb("List of files");?>:</label>
-		<div id="section_list">
-			
-			<select id="section_file_list" multiple='multiple'></div>
-
-			
-
-		</div>
-		
-	</div>
-	<input type="button" title="Download selected files" value="Download selection"/>
+	
+	<input id="multi_select" type="checkbox" disabled><?php echo _mb("Select multiple tiles");?></input><br>
+	<label for="mapframe_file_list"><?php echo _mb("Position of files (if available)");?>:</label>
+	<!--<input type="list" id="file_list"/>-->
+	<div id="mapframe_file_list"></div>
+	<label for="section_list"><?php echo _mb("List of files");?>:</label>
+	<div id="section_list"></div>
+	<!--<select id="section_file_list" multiple='multiple'>-->
+	<!--<input type="button" title="Download selected files" value="Download selection"/>-->
 </fieldset>
 </body>
 </html>

Modified: trunk/mapbender/http/plugins/mb_downloadFeedServer.php
===================================================================
--- trunk/mapbender/http/plugins/mb_downloadFeedServer.php	2012-08-08 15:19:06 UTC (rev 8450)
+++ trunk/mapbender/http/plugins/mb_downloadFeedServer.php	2012-08-10 11:30:43 UTC (rev 8451)
@@ -83,6 +83,12 @@
 
 			$title = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:title');
 			$rights = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:rights');
+			$summary = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:summary');
+			$date = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:date');
+			$code = $feedXML->xpath('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_code');
+			
+			$namespace = $feedXML->xpath('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_namespace');
+			
 			$bbox = $feedXML->xpath('/defaultns:feed/defaultns:entry/georss:polygon');
 			$metadataLink = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'describedby\')]/@href');
 			$datasetFeedLink = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'alternate\')]/@href');
@@ -94,13 +100,21 @@
 				$feature->fid = $uuid;	
 				$titleArray = (array)$title[$i];
 				$rightsArray = (array)$rights[$i];
+				$summaryArray = (array)$summary[$i];
+				$dateArray = (array)$date[$i];
+				$codeArray = (array)$code[$i];
+				$namespaceArray = (array)$namespace[$i];
 				$bboxArray = (array)$bbox[$i];
 				$mdLinkArray = (array)$metadataLink[$i];
 				$mdLinkArray = $mdLinkArray["@attributes"];
 				$dsLinkArray = (array)$datasetFeedLink[$i];
 				$dsLinkArray = $dsLinkArray["@attributes"];
 				$feature->properties["title"] = $titleArray[0];
+				$feature->properties["summary"] = $summaryArray[0];
 				$feature->properties["rights"] = $rightsArray[0];
+				$feature->properties["date"] = $dateArray[0];
+				$feature->properties["code"] = $codeArray[0];
+				$feature->properties["namespace"] = $namespaceArray[0];
 				$feature->properties["metadataLink"] = $mdLinkArray["href"];
 				$feature->properties["datasetFeedLink"] = $dsLinkArray["href"];
 				$feature->geometry = new geoRSSPolygon();



More information about the Mapbender_commits mailing list