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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Apr 23 22:54:16 PDT 2019


Author: armin11
Date: 2019-04-23 22:54:16 -0700 (Tue, 23 Apr 2019)
New Revision: 10112

Modified:
   trunk/mapbender/http/javascripts/mod_featureInfo.php
   trunk/mapbender/http/plugins/kmlTree.php
   trunk/mapbender/http/plugins/mb_digitize_widget.php
Log:
New option to integrate wms getfeature info and selection of digitized objects - thanx to federal german state hesse ;-)

Modified: trunk/mapbender/http/javascripts/mod_featureInfo.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_featureInfo.php	2019-04-18 14:44:40 UTC (rev 10111)
+++ trunk/mapbender/http/javascripts/mod_featureInfo.php	2019-04-24 05:54:16 UTC (rev 10112)
@@ -21,6 +21,8 @@
 include '../include/dyn_js.php';
 //defaults for element vars
 ?>
+// <script>
+
 var ignoreWms = typeof ignoreWms === "undefined" ? [] : ignoreWms;
 
 if(typeof(featureInfoLayerPopup)==='undefined')
@@ -31,15 +33,18 @@
 	var featureInfoPopupWidth = '270';
 if(typeof(featureInfoPopupPosition)==='undefined')
 	var featureInfoPopupPosition = 'center';
-var reverseInfo = typeof reverseInfo === "undefined" ? "false" : reverseInfo;
-if(typeof(featureInfoLayerPreselect)==='undefined' || featureInfoLayerPreselect == 'false')
+if(typeof(reverseInfo)==='undefined' || reverseInfo === 'false')
+    var reverseInfo = false;
+if(typeof(featureInfoLayerPreselect)==='undefined' || featureInfoLayerPreselect === 'false')
 	var featureInfoLayerPreselect = false;
 if(typeof(featureInfoDrawClick)==='undefined')
 	var featureInfoDrawClick = false;
 if(typeof(featureInfoCircleColor)==='undefined')
 	var featureInfoCircleColor = '#ff0000';
-if(typeof(featureInfoCollectLayers)==='undefined' || featureInfoCollectLayers == 'false')
+if(typeof(featureInfoCollectLayers)==='undefined' || featureInfoCollectLayers === 'false')
 	var featureInfoCollectLayers = false;
+if (typeof(featureInfoShowKmlTreeInfo) === 'undefined' || featureInfoShowKmlTreeInfo === 'false')
+	var featureInfoShowKmlTreeInfo = false;
 
 var mod_featureInfo_elName = "<?php echo $e_id;?>";
 var mod_featureInfo_frameName = "";
@@ -126,8 +131,158 @@
 			.css("cursor", "default");
 	}
 }
+
+function makeDialog($content, title, dialogPosition, offset) {
+    dialogPosition = dialogPosition || featureInfoPopupPosition;
+    if(featureInfoPopupPosition.length === 2 && !isNaN(featureInfoPopupPosition[0]) && !isNaN(featureInfoPopupPosition[1])) {
+        offset = offset || 0;
+        var dialogPosition = [];
+        dialogPosition[0] = featureInfoPopupPosition[0] + offset;
+        dialogPosition[1] = featureInfoPopupPosition[1] + offset;
+    }
+    return $content.dialog({
+        bgiframe: true,
+        autoOpen: true,
+        modal: false,
+        title: title,
+        width: parseInt(featureInfoPopupWidth, 10),
+        height: parseInt(featureInfoPopupHeight, 10),
+        position: dialogPosition,
+        buttons: {
+            "Ok": function() {
+                if (standingHighlightFeatureInfo !== null) { 
+                    standingHighlightFeatureInfo.clean();
+                }
+                $(this).dialog('close').remove();
+            }
+        }
+    }).parent().css({ position:"fixed" });
+}
+
+function featureInfoDialog(request, dialogPosition, offset) {
+    var title = "<?php echo _mb("Information");?>";
+    var $iframe = $("<iframe>")
+            .attr("frameborder", 0)
+            .attr("height", "100%")
+            .attr("width", "100%")
+            .attr("id", "featureInfo")
+            .attr("title", title)
+            .attr("src", request)
+    return makeDialog($("<div>").append($iframe), title, dialogPosition, offset);
+}
+
+function ownDataDialog(ownData, dialogPosition, offset) {
+    var $box = $('<div>').html(ownData.content);
+    return makeDialog($box,
+            "<?php echo _mb("Information");?>", dialogPosition, offset);
+}
+
+function featureInfoWindow(request) {
+    return window.open(request, "" , "width="+featureInfoPopupWidth+",height="+featureInfoPopupHeight+",scrollbars=yes,resizable=yes");
+}
+
+function ownDataWindow(ownData) {
+    var w = featureInfoWindow("");
+    var $body = $(w.document.body);
+    $body.html(ownData.content);
+}
+
+function makeListLine(url, title, legendurls, onclick) {
+    var $row = $("<tr>");
+    var $title = $("<td>")
+        .attr("valign", "top")
+        .appendTo($row);
+    var $link = $("<a>")
+        .css("text-decoration", "underline")
+        .attr("href", url)
+        .attr("target", "_blank")
+        .html(title)
+        .appendTo($title);    
+    if (onclick) {
+        $link.bind('click', onclick);
+    }
+    var $legend = $("<td>")
+        .appendTo($row);
+    if (legendurls.length === 0) {
+        legendurls = [""];
+    }
+    legendurls.forEach(function (legendurl) {
+        $("<img>")
+            .attr("src", legendurl)
+            .attr("alt", "<?php echo _mb("No legend available");?>")
+            .appendTo($legend);
+        $("<br/>") 
+            .appendTo($legend);
+    });
+        
+    return $row;
+}
+
+function makeFeatureInfoListLine(url, title, legendurls) {
+    return makeListLine(url, title, legendurls)
+}
+
+function makeOwnDataListLine(ownData) {
+    return makeListLine("#", ownData.title, [], function (e) {
+        ownDataWindow(ownData)
+        e.preventDefault();
+    });
+}
+
+function featureInfoListDialog(urls, ownDataInfos) {
+    var $featureInfoList = $("<table>")
+            .attr("border", 1);
+    
+    if (reverseInfo) {
+        urls.reverse();
+        ownDataInfos.reverse();
+        
+        ownDataInfos.forEach(function (ownDataInfo) {
+            $featureInfoList.append(makeOwnDataListLine(ownDataInfo));
+        });
+    }
+    
+    for(var i=0; i < urls.length; i++){
+        var $line;
+        if (featureInfoCollectLayers) { 
+            $line = makeFeatureInfoListLine(urls[i].request, urls[i].title, urls[i].legendurl.split(","));
+        } else {
+            if (urls[i].inBbox) {
+                if (urls[i].legendurl !== "empty" ) {
+                    $line = makeFeatureInfoListLine(urls[i].request, urls[i].title, [urls[i].legendurl]);
+                } else {
+                    $line = makeFeatureInfoListLine(urls[i].request, urls[i].title, [""]);
+                }
+            }
+        }
+        if ($line) {
+            $featureInfoList.append($line);
+        }
+    }
+    
+    if (!reverseInfo) {
+        ownDataInfos.forEach(function (ownDataInfo) {
+            $featureInfoList.append(makeOwnDataListLine(ownDataInfo));
+        });
+    }
+
+    makeDialog($("<div id='featureInfo_preselect'></div>").append($featureInfoList),
+        "<?php echo _mb("Please choose a requestable Layer");?>");
+}
+
 function mod_featureInfo_event(e){
+    var urls;
 	var point = mod_featureInfo_mapObj.getMousePosition(e);
+    //calculate realworld position
+    var realWorldPoint = Mapbender.modules[options.target].convertPixelToReal(point);
+    var ownDataInfos = [];
+    if (featureInfoShowKmlTreeInfo) {
+        if (Mapbender.modules.kmlTree === undefined) {
+            console.error('kmltree module is needed if element_var \'featureInfoShowKmlTreeInfo\' is set to true')
+        }
+        var kmlTree = Mapbender.modules.kmlTree;
+        ownDataInfos = kmlTree.getFeatureInfos(e);
+    }
 	if (featureInfoDrawClick) {
 		var map = Mapbender.modules[options.target];
 		if(standingHighlightFeatureInfo !== null){ 
@@ -139,24 +294,24 @@
 				{"position":"absolute", "top":"0px", "left":"0px", "z-index":100}, 
 				2);
 		}
-		//calculate realworld position
-		realWorldPoint = Mapbender.modules[options.target].convertPixelToReal(point);
 		//get coordinates from point
 		var ga = new GeometryArray();
 		//TODO set current epsg!
 		ga.importPoint({
 			coordinates:[realWorldPoint.x,realWorldPoint.y,null]
-		},Mapbender.modules[options.target].getSRS())
+		}, Mapbender.modules[options.target].getSRS())
 		var m = ga.get(-1,-1);
 		standingHighlightFeatureInfo.add(m, featureInfoCircleColor);
 		standingHighlightFeatureInfo.paint();
 		map.setMapRequest();
 	}
-	eventBeforeFeatureInfo.trigger({"fName":mod_featureInfo_target});
-	//TODO that code should go to featureInfo Redirect module
+	eventBeforeFeatureInfo.trigger({ "fName": mod_featureInfo_target });
 	if(document.getElementById("FeatureInfoRedirect")){
+        //TODO this code should go to featureInfo Redirect module
+        //FIXME this does not work for multiple urls
+        //FIXME this does not work for kmlTree
 		//fill the frames
-		for(var i=0; i<mod_featureInfo_mapObj.wms.length; i++){
+		for(var i=0; i < mod_featureInfo_mapObj.wms.length; i++){
 			var req = mod_featureInfo_mapObj.wms[i].getFeatureInfoRequest(mod_featureInfo_mapObj, point);
 			if(req)
 				window.frames.FeatureInfoRedirect.document.getElementById(mod_featureInfo_mapObj.wms[i].wms_id).src = req;
@@ -167,139 +322,64 @@
 		if (featureInfoLayerPreselect) {
 			$("#featureInfo_preselect").remove();
 			//build list of possible featureInfo requests
-			urls = mod_featureInfo_mapObj.getFeatureInfoRequestsForLayers(point, ignoreWms, Mapbender.modules[options.target].getSRS(), realWorldPoint, featureInfoCollectLayers);
-			if (urls.length == 0 || typeof urls.length =='undefined') {
+			urls = mod_featureInfo_mapObj.getFeatureInfoRequestsForLayers(point, ignoreWms, Mapbender.modules[options.target].getSRS(), realWorldPoint, featureInfoCollectLayers) || [];
+            var length = urls.length + ownDataInfos.length;
+			if (length === 0) {
 				alert("<?php echo _mb("Please enable some layer to be requestable");?>!");
 				return false;
 			}
-			if (urls.length == 1) {
+			if (length === 1) {
 				//don't show interims window!
 				//open featureInfo directly
-				if(featureInfoLayerPopup == 'true'){
-					$("<div><iframe frameborder='0' height='100%' width='100%' id='featureInfo' title='<?php echo _mb("Information");?>' src='" + urls[0].request + "'></iframe></div>").dialog({
-						bgiframe: true,
-						autoOpen: true,
-						modal: false,
-						title: '<?php echo _mb("Information");?>',
-						width:parseInt(featureInfoPopupWidth, 10),
-						height:parseInt(featureInfoPopupHeight, 10),
-						position:dialogPosition,
-						buttons: {
-							"Ok": function(){
-								$(this).dialog('close').remove();
-							}
-						}
-					}).parent().css({position:"fixed"});
+				if (featureInfoLayerPopup){
+                    if (urls.length === 1) {
+                        featureInfoDialog(urls[0].request);
+                    } else {
+                        ownDataDialog(ownDataInfos[0]);
+                    }
 					return false;
 				} else {
-					window.open(urls[0].request, "" , "width="+featureInfoPopupWidth+",height="+featureInfoPopupHeight+",scrollbars=yes,resizable=yes");
+                    if (urls.length === 1) {
+                        featureInfoWindow(urls[0].request);
+                    } else {
+                        ownDataWindow(ownDataInfos[0]);
+                    }
 					return false;
 				}
 			}
-			featureInfoList = "<table border='1'>";
-			if (reverseInfo == "true") {
-				for(var i=0;i<urls.length;i++){
-					if (featureInfoCollectLayers) { 
-						featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td>";
-						//get legend urls if available
-						var legend = urls[i].legendurl.split(",");
-						for(var k=0;k<legend.length;k++){
-							featureInfoList +="<img src='"+legend[k]+"' alt='<?php echo _mb("No legend available");?>!'/><br>";
-						}
-						featureInfoList += "</td></tr>";
-					} else {
-						if (urls[i].inBbox) {
-							if (urls[i].legendurl !== "empty" ) {
-								featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td><img src='"+urls[i].legendurl+"' alt='<?php echo _mb("No legend available");?>!'/></td></tr>";
-							} else {
-								featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td><img src='' alt='<?php echo _mb("No legend available");?>!'/></td></tr>";
-							}
-						}
-
-					}
-				}
-			} else {
-				for(var i=urls.length-1; i>=0; i--){
-					if (featureInfoCollectLayers) { 
-						featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td>";
-						//get legend urls if available
-						var legend = urls[i].legendurl.split(",");
-						for(var k=0;k<legend.length;k++){
-							featureInfoList +="<img src='"+legend[k]+"' alt='<?php echo _mb("No legend available");?>!'/><br>";
-						}
-						featureInfoList += "</td></tr>";
-					} else {
-						if (urls[i].inBbox) {
-							if (urls[i].legendurl !== "empty" ) {
-								featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td><img src='"+urls[i].legendurl+"' alt='<?php echo _mb("No legend available");?>!'/></td></tr>";
-							} else {
-								featureInfoList += "<tr><td valign='top'><a style='text-decoration:  underline' href='"+urls[i].request+"' target='_blank'>"+urls[i].title+"</a></td><td><img src='' alt='<?php echo _mb("No legend available");?>!'/></td></tr>";
-							}
-						}
-					}
-				}
-			}
-			featureInfoList += "</table>";
-			$("<div id='featureInfo_preselect'></div>").dialog({
-				bgiframe: true,
-				autoOpen: true,
-				modal: false,
-				title: '<?php echo _mb("Please choose a requestable Layer");?>',
-				width:parseInt(featureInfoPopupWidth, 10),
-				height:parseInt(featureInfoPopupHeight, 10),
-				position:dialogPosition,
-				buttons: {
-					"Close": function(){
-						if(standingHighlightFeatureInfo !== null){ 
-							standingHighlightFeatureInfo.clean();
-						}
-						$(this).dialog('close').remove();
-					}
-				}
-			}).parent().css({position:"fixed"});
-			$("#featureInfo_preselect").append(featureInfoList);
+			featureInfoListDialog(urls, ownDataInfos);
 		} else {
-			urls = mod_featureInfo_mapObj.getFeatureInfoRequests(point, ignoreWms);
-			if(urls){
-				for(var i=0;i<urls.length;i++){ //To change order : var i=urls.length-1; i>=0; i--
+			urls = mod_featureInfo_mapObj.getFeatureInfoRequests(point, ignoreWms) || [];
+            var length = urls.length + ownDataInfos.length;
+			if (length > 0){
+				for (var i=0; i < urls.length; i++){
 					//TODO: also rewind the LAYERS parameter for a single WMS FeatureInfo REQUEST if needed?
-					var cnt = i;
-					if (reverseInfo == 'true') {
+					if (reverseInfo) {
 						if (typeof(urls[i]) !== "undefined") {
 							urls[i] = changeURLValueOrder(urls[i], 'LAYERS');
 						}
 					}
-					if(featureInfoPopupPosition.length == 2 && !isNaN(featureInfoPopupPosition[0]) && !isNaN(featureInfoPopupPosition[1])) {
-						var dialogPosition = [];
-						dialogPosition[0] = featureInfoPopupPosition[0]+cnt*25;
-						dialogPosition[1] = featureInfoPopupPosition[1]+cnt*25;
+					if(featureInfoLayerPopup){
+                        featureInfoDialog(urls[i], dialogPosition, i * 25);
 					}
 					else {
-						var dialogPosition = featureInfoPopupPosition;
+                        featureInfoWindow(urls[i]);
+                    }
+				}
+                
+                for(var i=0; i < ownDataInfos.length; i++){
+					if(featureInfoLayerPopup === 'true'){
+                        ownDataDialog(ownDataInfos[i], dialogPosition, (urls.length + i) * 25);
 					}
-					if(featureInfoLayerPopup == 'true'){
-						$("<div><iframe frameborder='0' height='100%' width='100%' id='featureInfo_"+ i + "' title='<?php echo _mb("Information");?>' src='" + urls[i] + "'></iframe></div>").dialog({
-							bgiframe: true,
-							autoOpen: true,
-							modal: false,
-							title: '<?php echo _mb("Information");?>',
-							width:parseInt(featureInfoPopupWidth, 10),
-							height:parseInt(featureInfoPopupHeight, 10),
-							position:dialogPosition,
-							buttons: {
-								"Ok": function(){
-									$(this).dialog('close').remove();
-								}
-							}
-						}).parent().css({position:"fixed"});
-					}
-					else
-						window.open(urls[i], "" , "width="+featureInfoPopupWidth+",height="+featureInfoPopupHeight+",scrollbars=yes,resizable=yes");		
-				} //end for
-			} //end if urls
-			else
+					else {
+                        ownDataWindow(ownDataInfos[i]);
+                    }
+				}
+			}
+			else {
 				alert(unescape("Please select a layer! \n Bitte waehlen Sie eine Ebene zur Abfrage aus!"));
+            }
 		}
-		setFeatureInfoRequest(mod_featureInfo_target,point.x,point.y);
+		setFeatureInfoRequest(mod_featureInfo_target, point.x, point.y);
 	}
 }

Modified: trunk/mapbender/http/plugins/kmlTree.php
===================================================================
--- trunk/mapbender/http/plugins/kmlTree.php	2019-04-18 14:44:40 UTC (rev 10111)
+++ trunk/mapbender/http/plugins/kmlTree.php	2019-04-24 05:54:16 UTC (rev 10112)
@@ -329,7 +329,7 @@
                                                 isPublic = data;
                                                 if (isPublic == 1){
 
-                        							alert('To publicate a WMC is not allowed for the Guest-User!'+
+                        							alert('The Guest-User is not allowed to publish a WMC!'+
                         							      'If you want to use this function, please create an account.');
                         							return false;
                                                 }
@@ -868,6 +868,47 @@
         }
         return data;
     };
+    //  'area', 'boundary-length', 'track-length'
+    var featureInfoFilter = ['title', 'marker-size', 'marker-symbol', 'marker-color',
+        'marker-offset-x', 'marker-offset-y', 'stroke', 'stroke-opacity',
+        'stroke-width', 'fill', 'fill-opacity'];
+    
+    function escapeHTML(text) {
+        return text
+                .replace(/&/g, '&')
+                .replace(/</g, '<')
+                .replace(/>/g, '>')
+                .replace(/"/g, '"')
+                .replace(/'/g, '&#x27;')
+                .replace(/\//g, '&#x2F;');
+    }
+    
+    function createFeatureInfoContent(props) {
+        var $table = $("<table>")
+                .attr("border", 1);
+        for (var key in props) {
+            if (props.hasOwnProperty(key) && featureInfoFilter.indexOf(key) < 0) {
+                $table
+                    .append($("<tr>")
+                        .append($("<td>").html(escapeHTML(key)))
+                        .append($("<td>").html(escapeHTML(props[key]))))
+            }
+        }
+        return $table.attr('outerHTML');
+    }
+    
+    this.getFeatureInfos = function (click) {
+        var map = Mapbender.modules.mapframe1;
+        var kml = $('#mapframe1').data('kml');
+        return kml.findFeaturesAtClick(click)
+            .map(function (locator) {
+                var kmlLayer = map.kmls[locator.url];
+                return {
+                    title: kmlLayer.data.title,
+                    content: createFeatureInfoContent(kmlLayer.data.features[locator.id].properties)
+                }
+            });
+    };  
 };
 
 Mapbender.events.init.register(function() {

Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2019-04-18 14:44:40 UTC (rev 10111)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2019-04-24 05:54:16 UTC (rev 10112)
@@ -282,6 +282,7 @@
             $('#kmlTree li.kmltree-selected').removeClass('kmltree-selected');
             attributesDialog.dialog('close');
             editStyleDialog.dialog('close');
+
         });
         copyDialog = $(copyHtml);
         copyDialog.dialog({
@@ -497,9 +498,6 @@
                 editStyleDialog.find('input[name="marker-symbol"]').val('icon-' + v + '-24');
             }
         });
-        var cls = $('.digitize-style-predefined .selected-icon i').attr('class');
-        $('.digitize-style-predefined input[name="marker-symbol"]').val(cls);
-        editStyleDialog.find('input').change();
 
         editStyleDialog.find('form input').bind('click', function() {
             editStyleDialog.find('.digitize-style-' + $(this).val()).css('display', 'block').siblings('table').css('display', 'none');
@@ -507,16 +505,14 @@
 
         editStyleDialog.find('button[name="digitize-reset-style"]').bind('click', function() {
             if(ispoint) {
-                editStyleDialog.find('form').css('display', 'block');
-                editStyleDialog.find('.digitize-style-custom').css('display', 'none');
-                editStyleDialog.find('.digitize-style-predefined').css('display', 'block');
+                editStyleDialog.find('.digitize-style-custom,form').css('display', 'block');
+                editStyleDialog.find('.digitize-style-predefined').css('display', 'none');
+                editStyleDialog.find('input[value="custom"]').attr('checked', 'checked');
                 editStyleDialog.find('.digitize-style-custom input[name="marker-symbol"]').val('../img/marker/red.png');
                 editStyleDialog.find('.digitize-style-custom input[name="marker-size"]').val(20);
                 editStyleDialog.find('.digitize-style-predefined input[name="marker-symbol"]').val('icon-airfield-24');
-                $('.digitize-style-predefined .selected-icon i').attr('class', 'icon-airfield-24');
                 editStyleDialog.find('.digitize-style-predefined input[name="marker-size"]').val('medium');
                 editStyleDialog.find('.digitize-style-predefined input[name="marker-color"]').spectrum('set', 'white');
-                editStyleDialog.find('input').change();
             }
             editStyleDialog.find('input[name="stroke"]').spectrum('set', '#555555');
             editStyleDialog.find('.opacity-slider').slider('value', 100);
@@ -533,10 +529,6 @@
         return;
     }
 
-    if($(this).attr('name').match(/marker-type/) && !$(this).get(0).checked) {
-        return;
-    }
-
     if($(this).attr('name') === 'stroke-width') {
         var val = $(this).val();
         if(!(!isNaN(parseFloat(val)) && isFinite(val)) || $(this).val() <= 0) {



More information about the Mapbender_commits mailing list