Generate default WMC

From MapbenderWiki

Jump to: navigation, search
<?php
	$doc = new DOMDocument('1.0');
	$doc->encoding = CHARSET;
	$doc->preserveWhiteSpace = false;
	$e_view_context = $doc->createElement('ViewContext');
	$e_view_context->setAttribute('version', '1.0.0');
	$e_view_context->setAttribute('id', $_SESSION['mb_user_id'].'_'.time());
	$e_general = $doc->createElement('General');
	$e_window = $doc->createElement('Window');
	$e_bbox = $doc->createElement('BoundingBox');

	$sql = "SELECT e_width, e_height FROM gui_element WHERE fkey_gui_id = $1 AND e_id = 'mapframe1' LIMIT 1";
	$v = array($_SESSION['mb_user_gui']);
	$t = array('s');
	$res = db_prep_query($sql, $v, $t);
	$row = db_fetch_array($res);
	
	if ($row) {
		$window = array("window_width" => $row['e_width'], "window_height" => $row['e_height']);
	}
	else {
		$window = array("window_width" => 515, "window_height" => 485);
	}

	// if the layer preview GUI is loaded...
	if ($_REQUEST['layer_preview'] && $_REQUEST['portal_services']) {

		$sql = "SELECT * FROM layer_epsg WHERE fkey_layer_id = $1 ORDER BY epsg DESC";
		$v = array($_REQUEST['portal_services']);
		$t = array('i');
		$res = db_prep_query($sql, $v, $t);
		$row = db_fetch_array($res);
		// ... the bounding box is the bbox of the layer that is being previewed ...
		if ($row['epsg'] && $row['minx'] && $row['miny'] && $row['maxx'] && $row['maxy']) {
				$srs = array("epsg" => $row['epsg'], "minx" => $row['minx'], "miny" => $row['miny'], "maxx" => $row['maxx'], "maxy" => $row['maxy']);		
		}
		// ... if that layer has no bounding box ...
		else {
			$sql = "SELECT * FROM (SELECT fkey_wms_id FROM layer WHERE layer_id = $1 LIMIT 1) AS w, layer_epsg AS e, layer AS l WHERE l.fkey_wms_id = w.fkey_wms_id AND l.layer_pos = 0 AND l.layer_id = e.fkey_layer_id ORDER BY e.epsg DESC";
			$v = array($_REQUEST['portal_services']);
			$t = array('i');
			$res = db_prep_query($sql, $v, $t);
			$row = db_fetch_array($res);
			// ... take the bbox of the root layer ...
			if ($row['epsg'] && $row['minx'] && $row['miny'] && $row['maxx'] && $row['maxy']) {
				$srs = array("epsg" => $row['epsg'], "minx" => $row['minx'], "miny" => $row['miny'], "maxx" => $row['maxx'], "maxy" => $row['maxy']);		
			}
			// ... if that's not available either, use a hard wired bounding box (extent of RLP)
			else {
				$srs = array("epsg" => "EPSG:31466", "minx" => 2412139.175257732, "miny" => 5365000, "maxx" => 2767860.824742268, "maxy" => 5700000);		
			}
		}
	}
	// .. in general, 
	else {
		$sql = "SELECT fkey_wms_id, gui_wms_epsg FROM gui_wms WHERE fkey_gui_id = $1 ORDER BY gui_wms_position";
		$v = array($_SESSION['mb_user_gui']);
		$t = array('s');
		$res = db_prep_query($sql, $v, $t);
		$row = db_fetch_array($res);
		$wms_id = $row['fkey_wms_id'];
		$gui_wms_epsg = $row['gui_wms_epsg'];
		$sql = "SELECT e.minx, e.miny, e.maxx, e.maxy FROM gui_layer AS g, layer_epsg AS e WHERE g.gui_layer_wms_id = $1 AND e.fkey_layer_id = g.fkey_layer_id AND e.epsg = $2 LIMIT 1";
		$v = array($wms_id, $gui_wms_epsg);
		$t = array('i', 's');
		$res = db_prep_query($sql, $v, $t);
		$row = db_fetch_array($res);
		// ... use the bounding box of the firs WMS in the GUI ...
		if ($row) {
			$srs = array("epsg" => $gui_wms_epsg, "minx" => $row['minx'], "miny" => $row['miny'], "maxx" => $row['maxx'], "maxy" => $row['maxy']);		
		}
		// .. if that WMS has no bbox, use the hard wired bbox of RLP
		else {
			$srs = array("epsg" => "EPSG:31466", "minx" => 2412139.175257732, "miny" => 5365000, "maxx" => 2767860.824742268, "maxy" => 5700000);		
		}
	
	}
	$e_window->setAttribute('width', $window['window_width']);
	$e_window->setAttribute('height', $window['window_height']);
	$e_bbox->setAttribute('SRS', $srs['epsg']); 
	$e_bbox->setAttribute('minx', $srs['minx']); 
	$e_bbox->setAttribute('miny', $srs['miny']);  
	$e_bbox->setAttribute('maxx', $srs['maxx']); 
	$e_bbox->setAttribute('maxy', $srs['maxy']);  
	$e_name = $doc->createElement('Name', 'Mapbender WMC');
	$e_title = $doc->createElement('Title', 'session');
	$e_layerlist = $doc->createElement('LayerList');

	$e_general->appendChild($e_window);
	$e_general->appendChild($e_bbox);
	$e_general->appendChild($e_name);
	$e_general->appendChild($e_title);
	$e_view_context->appendChild($e_general);
	$e_view_context->appendChild($e_layerlist);
	$doc->appendChild($e_view_context);
	$_SESSION['mb_wmc'] = $doc->saveXML();
?>
Views
Personal tools