[Mapbender-commits] r8647 - in trunk/mapbender/http: classes javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jun 6 02:31:16 PDT 2013


Author: armin11
Date: 2013-06-06 02:31:16 -0700 (Thu, 06 Jun 2013)
New Revision: 8647

Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/initWmcObj.php
Log:
Give mapbender back some performance when loading guis ;-)

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2013-06-04 07:32:04 UTC (rev 8646)
+++ trunk/mapbender/http/classes/class_wmc.php	2013-06-06 09:31:16 UTC (rev 8647)
@@ -1023,7 +1023,7 @@
 			}
 		}
 
-		// check if layer IDs exist
+		// check if layer IDs exist TODO: no layerIdArray given!
 		for ($i = 0; $i < count($layerIdArray); $i++) {
 			$currentId = $layerIdArray[$i];
 			if (!is_numeric($this->wmc_layer_id[$currentId])) {
@@ -1067,6 +1067,19 @@
 		}
 	}
 
+	private function incrementLayerLoadCount ($layerIdArray) {
+		$layerIdString = implode(",",$layerIdArray);
+		$sql = "UPDATE layer_load_count SET load_count = load_count+1 WHERE fkey_layer_id in (".$layerIdString.")";
+		$res = db_query($sql);
+		if (!$res) {
+			$e = new mb_exception("class_wmc.php: Could not increment layer load_count of layers in wmc!");
+			return false;
+		} else {
+			$e = new mb_notice("class_wmc.php: Updated load_count of layers in wmc!");
+			return true;
+		}		
+	}
+
 	public function extentToJavaScript() {
 		return $this->mainMap->extentToJavaScript();
 	}
@@ -1142,7 +1155,7 @@
 		// will contain the JS code to create the maps
 		// representing the state stored in this WMC
 		$wmcJsArray = array();
-
+		
 		// set general extension data
 		if (count($this->generalExtensionArray) > 0) {
 			$json = new Mapbender_JSON();
@@ -1152,10 +1165,8 @@
 		// reset WMS data
 		array_push($wmcJsArray, "wms = [];");
 		array_push($wmcJsArray, "wms_layer_count = 0;");
-
 		// add WMS for main map frame
 		$wmsArray = $this->mainMap->getWmsArray();
-
 		// find the WMS in the main map which is equal to the WMS
 		// in the overview map
 		$overviewWmsIndex = null;
@@ -1173,16 +1184,21 @@
 				}
 			}
 		}
-
 		// for all wms...
+		$layerIdArray = array();
 		for ($i = 0; $i < count($wmsArray); $i++) {
 			if (in_array($i, $skipWmsArray)) {
 				continue;
 			}
+			//get all layer_uid from mapObject!
+			$layer = $wmsArray[$i]->objLayer;
+			for ($j = 0; $j < count($layer); $j++) {
+				$layerIdArray[] = (integer)$layer[$j]->layer_uid;
+			}
 			array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
-			$this->incrementLoadCount($wmsArray[$i]);
+			//$this->incrementLoadCount($wmsArray[$i]);
 		}
-
+		//$e = new mb_exception(microtime()."class_wmc.php:toJavaScript(): layerIdArray ".json_encode($layerIdArray));
 		// delete existing map objects...
 		//		array_push($wmcJsArray, "mb_mapObj = [];");
 
@@ -1195,7 +1211,6 @@
 				)
 			);
 		}
-
 		// .. and add main map ..
 		$wmcJsArray = array_merge(
 			$wmcJsArray,
@@ -1203,7 +1218,6 @@
 			"{wms:wms,wmsIndexOverview:null}"
 			)
 		);
-
 		// set visibility of ov map WMS (may be different from main)
 		if ($this->overviewMap !== null) {
 			for ($i = 0; $i < count($ovWmsArray[$wmsIndexOverview]->objLayer); $i++) {
@@ -1220,7 +1234,8 @@
 			array_push($wmcJsArray, "try { Mapbender.modules['".$this->overviewMap->getFrameName().
 				"'].restateLayers(" . $ovWmsArray[$wmsIndexOverview]->wms_id . ");} catch (e) {};");
 		}
-
+		//increment the load count for known layers - TODO: Why here? -layer will be counted more than once!!!!
+		$this->incrementLayerLoadCount(array_unique($layerIdArray));
 		// .. request the map
 		
 		array_push($wmcJsArray, "lock_maprequest = true;");

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2013-06-04 07:32:04 UTC (rev 8646)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2013-06-06 09:31:16 UTC (rev 8647)
@@ -59,9 +59,10 @@
 );
 //
 // Load WMC from session or application
+$e = new mb_notice("javascript/initWmcObj.php: start!");
 //
 $wmc = new wmc();
-$app = Mapbender::session()->get("mb_user_gui");
+$app = Mapbender::session()->get("mb_user_gui"); //if gui was set!
 //$wmcDocSession = Mapbender::session()->get("mb_wmc");
 $wmcDocSession = false;
 //check if wmc filename is in session - TODO only if should be loaded from session not else! (Module loadWMC)
@@ -76,7 +77,7 @@
 	//otherwise create a new wmc from application
 		$e = new mb_notice("trying to load session WMC...");
 		if (!$wmc->createFromXml($wmcDocSession)) {
-			$e = new mb_exception("loading session WMC failed.");
+			$e = new mb_notice("loading session WMC failed.");
 			$e = new mb_notice("creating wmc from app: ".$app);
 			$wmc->createFromApplication($app);
 		}
@@ -90,7 +91,7 @@
 	}
 }
 catch (Exception $e) {
-	$e = new mb_notice("creating wmc from app: " . $app);
+	$e = new mb_exception("initWmcObj.php: ERROR while loading wmc from session - test creating wmc from app: " . $app);
 	$wmc->createFromApplication($app);
 }
 //TODO: if no GET API is given then don't do the following things
@@ -330,19 +331,14 @@
 }
 //TODO test following
 //workaround to have a fully merged WMC for loading
-$e = new mb_notice("initWmcObj.php: export to xml");
 $xml = $wmcGetApi->toXml();
-
 $wmcGetApi = new wmc();
 //new Object with merged layers and other features
-$e = new mb_notice("initWmcObj.php: import from xml");
 $wmcGetApi->createFromXml($xml);
-$e = new mb_notice("initWmcObj.php: import done!");
 //
 // CONSTRAINTS
 //
 $currentUser = new User();
-
 // remove all WMS with no permission
 $e = new mb_notice("initWmcObj.php: get wms without permission");
 $deniedIdsArray = $wmcGetApi->getWmsWithoutPermission($currentUser);
@@ -483,7 +479,6 @@
 $e = new mb_notice("initWmcObj.php: session GML zoom done");
 //overwrite extent of wmc with information from GetApi if given
 $e = new mb_notice("initWmcObj.php: check ZOOM API");
-
 $zoom = $getApi->getZoom();
 $e = new mb_notice("initWmcObj.php: check ZOOM API: ".implode(',',$zoom));
 if (count($zoom) == 4 || count($zoom) == 5) {
@@ -515,7 +510,6 @@
 	count($resultObj["unavailable"]["wms"]) === 0 ||
 	!$isSessionWmcModuleLoaded
 ) {
-	$e = new mb_notice("initWmcObj.php: build js!");
 	//put them into the session to pull them later on
 	Mapbender::session()->set("wmcConstraints", $resultObj);
 //*******************************************************
@@ -531,14 +525,9 @@
 	//$e = new mb_notice("initWmcObj.php: alternate js:".$alternateWMC->toJavaScript());
 	//$e = new mb_notice("initWmcObj.php: alternate js build successfully!");
 //*******************************************************
-	//$e = new mb_notice("initWmcObj.php: wmc to js!");
 	$output = $wmcGetApi->wmsToJavaScript();
-	//output without wms
-	//$output = "";
-	$e = new mb_notice("initWmcObj.php: WMC to js with empty array!");
-	$wmcJs = $wmcGetApi->toJavaScript(array());
+	$wmcJs = $wmcGetApi->toJavaScript(array());//old way - why give an empty array?
 	$wmcJs = implode(";\n",$wmcJs);
-	$e = new mb_notice("initWmcObj.php: extent to js!");
 	$extentJs = $wmcGetApi->extentToJavaScript();
 	$output[] = <<<JS
 		Mapbender.events.afterInit.register(function () {
@@ -549,17 +538,12 @@
 		});
 JS;
 	Mapbender::session()->delete("wmcGetApi", $wmcGetApi);
-	$e = new mb_notice("initWmcObj.php: js have been build!");
 }
 else {
-	$e = new mb_notice("initWmcObj.php: build js!");
 	Mapbender::session()->set("wmcConstraints", $resultObj);
-	$e = new mb_notice("initWmcObj.php: wms to js!");
 	$output = $wmc->wmsToJavaScript();
-	$e = new mb_notice("initWmcObj.php: WMC to js with empty array!");
 	$wmcJs = $wmc->toJavaScript(array());
 	$wmcJs = implode(";\n",$wmcJs);
-	$e = new mb_notice("initWmcObj.php: extent to js!");
 	$extentJs = $wmc->extentToJavaScript();
 	$output[] = <<<JS
 		Mapbender.events.afterInit.register(function () {
@@ -570,15 +554,11 @@
 		});
 JS;
 	Mapbender::session()->set("wmcGetApi", $wmcGetApi);
-	$e = new mb_notice("initWmcObj.php: js have been build!");
 }
-
-$e = new mb_notice("initWmcObj.php: build output string!");
 $outputString = "";
 for ($i = 0; $i < count($output); $i++) {
 	$outputString .= administration::convertOutgoingString($output[$i]);
 }
-
 $wmcFeaturetypeJson = $wmc->featuretypeConfToJavaScript();
 $wfsConfIdString = $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'];
 if($wfsConfIdString != ""){
@@ -592,16 +572,12 @@
 JS;
 }
 $outputString .= $wmcFeaturetypeStr;
-
 $GeoRSSStr = " Mapbender.events.afterInit.register(function () {";
 foreach($inputGeoRSSArray as $inputGeoRSSUrl){
 	$GeoRSSStr .= 'try {$("#mapframe1").georss({url: "'.$inputGeoRSSUrl .'"})} catch(e) {new Mb_warning("GeoRSS module not loaded")}';
 }
 $GeoRSSStr .="}); ";
-
 $outputString .= $GeoRSSStr;
-
-$e = new mb_notice("initWmcObj.php: output string ready!");
 echo $outputString;
 //logit($outputString,"javascript_old.store","w");
 Mapbender::session()->delete("addwms_showWMS");



More information about the Mapbender_commits mailing list