[Mapbender-commits] r4848 - in trunk/mapbender/http: javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Oct 22 04:28:38 EDT 2009


Author: kmq
Date: 2009-10-22 04:28:37 -0400 (Thu, 22 Oct 2009)
New Revision: 4848

Added:
   trunk/mapbender/http/php/mod_wfs_gazetteer_l10n.php
Modified:
   trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
Log:
added translation for WFS gazetteer

Modified: trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php	2009-10-21 14:04:03 UTC (rev 4847)
+++ trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php	2009-10-22 08:28:37 UTC (rev 4848)
@@ -36,6 +36,7 @@
 <script type="text/javascript">
 <?php 
 	include '../include/dyn_js.php';
+	include '../extensions/jquery-1.3.2.min.js';
 	include '../include/dyn_php.php';
 	include(dirname(__FILE__) . "/../../conf/" . $wfs_spatial_request_conf_filename);
 
@@ -113,6 +114,82 @@
 var buttonWfs_x = [];
 var buttonWfs_y = [];
 
+
+
+function isEmpty(obj){
+  for(var j in obj){ if(obj.hasOwnProperty(j)) { return false;}}
+  return true;
+}
+
+// traverses a tree, throwing out
+// all paths whose labels don't
+// match the regular expression in filter
+function filteredCopy(obj,filter){
+  filter = filter || /.*/;
+  obj    = obj    || {};
+ 
+  var deleteStack = []; 
+  var subtree = null;
+  var entry   = null;
+
+  // visit each node, and check it's subtree for 
+  // nodes containing "filter"
+  // if it doesn contain any of those, put the subtree index
+  // on a list
+  for(subtree in obj)
+  {
+    if(obj.hasOwnProperty(subtree))
+    {
+      var type = typeof(obj[subtree]);
+      if(type == "object"){
+        filteredSubtree =  filteredCopy(obj[subtree],filter);
+        if(isEmpty(filteredSubtree))
+        {
+          // empty objects are leafnodes, so if they don't match
+          // we mark for deletion
+          if(!filter.test(subtree))
+          {
+            deleteStack.push(subtree);
+          }
+        }
+      }else if (type == "string") {
+        // strings are leafnodes, so if they don't match our regex
+        // we add them to the list of thing we want removed
+        if(!filter.test(subtree))
+        {
+          deleteStack.push(subtree);
+        }
+      }
+    }
+  }
+  
+  for( entry in deleteStack)
+  {
+    if(deleteStack.hasOwnProperty(entry)) {
+      delete(obj[deleteStack[entry]])
+    }
+  }
+  return obj;
+}
+
+function localizeGazetteer(){
+  
+  // make overlaytree containing only entries to be translated
+  var inObj = $.extend(true,{},global_wfsConfObj);
+  var labels = filteredCopy(inObj,/label$/);
+ 
+  var  req  =  new parent.Mapbender.Ajax.Request({
+      url: "../php/mod_wfs_gazetteer_l10n.php",
+      method: "translateServiceData" ,
+      parameters: {data : labels},
+      callback: function(obj, success, message){
+          resultObj = $.extend(true,global_wfsConfObj,obj);
+          reapplyWFSConfObject(resultObj);
+      }
+  });
+  req.send();
+}
+
 function addButtonWfs(id, isOn, src, title, x, y) {
 	buttonWfs_id.push(id);
 	buttonWfs_on.push(isOn);
@@ -131,6 +208,13 @@
 	init_wfsSpatialRequest();	
 });
 
+parent.Mapbender.events.localize.register(function() {
+    localizeGazetteer();
+});
+
+// FIXME: need this in newStyle
+//parent.eventLocalize.register(localizeGazetteer);
+
 function init_wfsSpatialRequest() {
 		buttonWfs_id = [];
 		buttonWfs_on = [];
@@ -350,9 +434,8 @@
 
 //----------------------------------------------------------------------------------
 
-
 function initModWfsGazetteer() {
-	// empty nodes
+    // empty nodes
 	var nodesToEmpty = ["selectWfsConfForm", "wfsForm", "res", "wfsIcons"];
 	while (nodesToEmpty.length > 0) {
 		var currentId = nodesToEmpty.pop();
@@ -361,8 +444,23 @@
 	}
 	
 	geomArray = new parent.GeometryArray();
+    
+    // Would be much nicer to have
+    // initWFSConf() and reloadWFSConf 
+     parent.mb_ajax_json("../php/mod_wfs_gazetteer_server.php", {command:"getWfsConf",wfsConfIdString:wfsConfIdString}, function(json,status) {
+        reapplyWFSConfObject(json, status);
+        localizeGazetteer();
+    });
+	
+	// creates a Highlight object for the request geometry
+	var styleProperties = {"position":"absolute", "top":"0px", "left":"0px", "z-index":100};
+	requestGeometryHighlight = new parent.Highlight(targetArray, "requestGeometryHighlight", styleProperties, 2);
+	parent.mb_registerSubFunctions("window.frames['" + frameName +"'].requestGeometryHighlight.paint()");
+	
+}
 
-	parent.mb_ajax_json("../php/mod_wfs_gazetteer_server.php", {command:"getWfsConf",wfsConfIdString:wfsConfIdString}, function(json, status) {
+function reapplyWFSConfObject(json,status)
+{
 		global_wfsConfObj = json;
 		var wfsCount = 0;
 		for (var wfsConfId in global_wfsConfObj) {
@@ -383,13 +481,7 @@
 			
 		}
 		parent.mb_setWmcExtensionData({"wfsConfIdString":wfsConfIdString});
-	});
-	
-	// creates a Highlight object for the request geometry
-	var styleProperties = {"position":"absolute", "top":"0px", "left":"0px", "z-index":100};
-	requestGeometryHighlight = new parent.Highlight(targetArray, "requestGeometryHighlight", styleProperties, 2);
-	parent.mb_registerSubFunctions("window.frames['" + frameName +"'].requestGeometryHighlight.paint()");
-	
+
 }
 
 function setWfsInfo() {

Added: trunk/mapbender/http/php/mod_wfs_gazetteer_l10n.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_gazetteer_l10n.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_wfs_gazetteer_l10n.php	2009-10-22 08:28:37 UTC (rev 4848)
@@ -0,0 +1,64 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 507 2006-11-20 10:55:57Z christoph $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require(dirname(__FILE__)."/mb_validateSession.php");
+
+
+// translates all string values in a tree It can find
+function translateTree($tree)
+{
+
+  if(is_object($tree)){
+    foreach($tree as $key => $value )
+    {
+      $tree->$key = translateTree($value);
+    }
+  }else if(is_array($tree)){
+    foreach($tree as $key => $value )
+    {
+      $tree[$key] = translateTree($value);
+    }
+  }else if(is_string($tree)){
+    $tree =  _mb($tree);
+  }
+  return $tree;
+}
+
+$ajaxResponse = new AjaxResponse($_POST);
+
+switch ($ajaxResponse->getMethod()) {
+	case "translateServiceData" :
+		$msg_obj = $ajaxResponse->getParameter("data");
+        
+        $translated_obj = translateTree($msg_obj);
+		
+        $ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult($translated_obj);
+		break;
+	default :
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage(_mb("An unknown error occured."));
+		break;
+}
+
+
+$firephp->log($_SESSION, "SESSION");
+$ajaxResponse->send();
+
+?>



More information about the Mapbender_commits mailing list