map = $map; $this->mapFile = $mapFile; $this->ini = $ini; $this->gLanguage = $gLanguage; $this->_initExtParams(); $this->_initConfig(); $this->_initGroups(); $this->_initQuery(); $this->_initLegend(); $this->_initDataPath(); } /** * Get external parameters via URL (eg from links) * */ function _initExtParams() { if (isset($_GET['me'])) { $ext = explode(',', $_GET['me']); $_SESSION['zoom_extparams'] = $ext; } if (isset($_GET['up'])) { //$_SESSION['ul'] = $_GET['ul']; $pointList = explode("@@@", $_GET['up']); foreach($pointList as $p) { $upnt = explode("@@", $p); $url_points[] = $upnt; } $_SESSION['url_points'] = $url_points; } } /** * Check INI settings for errors */ function _initConfig() { /*** Test if resolution tag is set ***/ if ($this->map->resolution != "96") { error_log ("P.MAPPER-ERROR: RESOLUTION tag not set to 96. This value is needed for proper function of PDF print.", 0); } /*** LAYERS ***/ // Test for groups with blanks $gList = $this->map->getAllGroupNames(); foreach ($gList as $gr) { if (preg_match('/\s/', $gr)) { error_log ("P.MAPPER-ERROR: Group '$gr' defined in the map file has blanks in its name. This is not possible for the p.mapper application. Remove blanks or substitute with e.g. '_'.", 0); } } // Test for layers with blanks $gList = $this->map->getAllLayerNames(); foreach ($gList as $ly) { if (preg_match('/\s/', $ly)) { error_log ("P.MAPPER-ERROR: Layer '$ly' defined in the map file has blanks in its name. This is not possible for the p.mapper application. Remove blanks or substitute with e.g. '_'.", 0); } } /*** Enable map pan with right mouse button pressed ***/ $_SESSION['enableRightMousePan'] = $this->ini['enableRightMousePan']; /*** PDF print resolution ***/ if (isset($this->ini["pdfres"])) { $pdfres = $this->ini["pdfres"]; } else { $pdfres = 1.5; } $_SESSION["pdfres"] = $pdfres; $_SESSION['pmapper'] = $this->ini['pmapper']; if (isset($this->ini['dpiLevels'])) { $_SESSION['dpiLevels'] = $this->ini['dpiLevels']; } } /** * Initialize p.mapper-related groups/layers */ function _initGroups() { /*** LAYERS DEFINED MANUALLY *** displayed in TOC in this order without definition, the order from map file will be taken */ $mapGrps = $this->map->getAllGroupNames(); $mapLays = $this->map->getAllLayerNames(); $GrpLay = array_merge($mapGrps, $mapLays); if (isset($this->ini["allGroups"])) { $allGroups = preg_split('/[\s,]+/', $this->ini["allGroups"]); // Check for errors foreach ($allGroups as $g) { if (!in_array($g, $GrpLay) ) { error_log ("P.MAPPER-ERROR: Layer/Group '$g' not existing. Check '/config/config.ini' file definition for section 'allGroups'.", 0); } } } else { $allGroups = $this->map->getAllGroupNames(); } $_SESSION["allGroups"] = $allGroups; /*** LAYERS SWITCHED ON BY DEFAULT *** default groups, visible at start without definition, ALL groups will be set visible */ // Check if layers are set externally via URL if (isset($_GET['dg'])) { $defGroupsGET = explode(',', $_GET['dg']); $defGroups = array(); foreach ($defGroupsGET as $gG) { if (in_array($gG, $allGroups)) { $defGroups[] = $gG; } } // if no valid layers supplied, take first from ini if (count($defGroups) < 1) $defGroups = array($allGroups[0]); // Else take them from config.ini settings } elseif (isset($this->ini["defGroups"])) { $defGroups = preg_split('/[\s,]+/', $this->ini["defGroups"]); // Check for errors foreach ($defGroups as $g) { if (!in_array($g, $GrpLay )) { error_log ("P.MAPPER-ERROR: Layer/Group '$g' not existing. Check '/config/config.ini' file definition for section 'defGroups'.", 0); $defGroups = $allGroups; //$this->map->getAllGroupNames(); } } // Else take all } else { $defGroups = array(); //$allGroups; } $_SESSION["defGroups"] = $defGroups; /*** LAYERS DISABLING EACH OTHER ***/ if (isset($this->ini['mutualDisableList'])) { $mutualDisableList = preg_split('/[\s,]+/', $this->ini['mutualDisableList']); foreach ($mutualDisableList as $mg) { if (!in_array($mg, $allGroups )) { error_log ("P.MAPPER-ERROR: Layer/Group '$mg' not existing. Check '/config/config.ini' file definition for section 'mutualDisableList'.", 0); $mutualDisableList = array(); } } } else { $mutualDisableList = array(); } $_SESSION['mutualDisableList'] = $mutualDisableList; /*** LAYERS CAUSING MAP TO SWITCH TO ALTERNATIVE IMAGE FORMAT ***/ if (isset($this->ini['altImgFormatLayers'])) { $altImgFormatLayers = preg_split('/[\s,]+/', $this->ini['altImgFormatLayers']); foreach ($altImgFormatLayers as $mg) { if (!in_array($mg, $allGroups )) { error_log ("P.MAPPER-ERROR: Layer/Group '$mg' not existing. Check '/config/config.ini' file definition for section 'mutualDisableList'.", 0); $altImgFormatLayers = 0; } } } else { $altImgFormatLayers = 0; } $_SESSION['altImgFormatLayers'] = $altImgFormatLayers; /*** Specify GROUP objects ***/ require_once($_SESSION['PM_INCPHP'] . "/initgroups.php"); $iG = new Init_groups($this->map, $allGroups, $this->gLanguage, $this->ini['map2unicode']); } /** * Settings for identify/search/select * */ function _initQuery() { // Limit for results of selection with select tool $_SESSION["limitResult"] = $this->ini["limitResult"]; //Defines if SELECT function causes feature highlight $_SESSION["highlightSelected"] = $this->ini["highlightSelected"]; // Highlight color for identify/search zoom in if (isset($this->ini["highlightColor"])) { $_SESSION["highlightColor"] = $this->ini["highlightColor"]; } else { $_SESSION["highlightColor"] = "0, 255, 255"; // set to a default } // Auto Zoom $autoZoom = $this->ini["autoZoom"]; if (!preg_match ("/search|nquery|off/i", $autoZoom )) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'autoZoom'. Can only be 'search', 'nquery' or 'off'", 0); $autoZoom = "off"; // set to a default } $_SESSION["autoZoom"] = $autoZoom; // Zoom All Button $zoomAll = $this->ini["zoomAll"]; if (!preg_match ("/search|nquery|off/i", $zoomAll )) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'zoomAll'. Can only be 'search', 'nquery' or 'off'", 0); $zoomAll = "off"; // set to a default } $_SESSION["zoomAll"] = $zoomAll; // Automatically sort result tables of queries $_SESSION['alignQueryResults'] = $this->ini['alignQueryResults']; // WINDOW DESIGN: Query results (identify/search) in separate WINDOW or FRAME $infoWin = $this->ini["infoWin"]; if (!preg_match ("/window|frame/", $infoWin)) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'infoWin'. Must be either 'window' or 'frame'", 0); $infoWin = "window"; // set to a default } $_SESSION["infoWin"] = $infoWin; $_SESSION["layerAutoRefresh"] = $this->ini["layerAutoRefresh"]; $_SESSION["pointBuffer"] = $this->ini["pointBuffer"]; } /** * Settings for legend/TOC * */ function _initLegend() { // Style of CATEGORIES $catStyle = strtolower($this->ini["catStyle"]); if (!preg_match ("/flat|tree|Off/i", $catStyle)) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'tocStyle'. Must be either 'flat', 'tree' or 'Off'", 0); $catStyle = "Off"; // set to a default } $_SESSION["catStyle"] = $catStyle; // Style of GROUPS $grpStyle = strtolower($this->ini["grpStyle"]); if (!preg_match ("/flat|tree|combi/i", $grpStyle)) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'grpStyle'. Must be either 'flat', 'tree' or 'combi'", 0); $grpStyle = "flat"; // set to a default } $_SESSION["grpStyle"] = $grpStyle; // Style of LEGEND $legStyle = trim(strtolower($this->ini["legStyle"])); if (!preg_match ("/^(attached|swap|popup)$/i", $legStyle)) { error_log ("P.MAPPER-ERROR: Wrong entry in '/config/config.ini' file for section 'legStyle'. Must be either attached, swap, or popup", 0); $legStyle = "attached"; // set to a default } $_SESSION["legStyle"] = $legStyle; // LAYERS UPDATED ACCORDING TO SCALE $_SESSION["scaleLayers"] = $this->ini["scaleLayers"]; // Use categories to thematically group layers $_SESSION["useCategories"] = $this->ini["useCategories"]; // ICON SIZE AND FORMAT if (isset($this->ini["icoW"]) && isset($this->ini["icoH"])) { $icoW = $this->ini["icoW"]; // Width in pixels $icoH = $this->ini["icoH"]; // Height in pixels } else { $icoW = 18; $icoH = 14; } $_SESSION["icoW"] = $icoW; $_SESSION["icoH"] = $icoH; // Image Format if (isset($this->ini["imgFormat"])) { $imgFormat = $this->ini["imgFormat"]; } else { $imgFormat = "jpeg"; } $_SESSION["imgFormat"] = $imgFormat; $_SESSION["altImgFormat"] = $this->ini["altImgFormat"]; /*** WRITES LEGEND ICONS ***/ // Check if images have to be created // => if map file is newer than last written log file $writeNew = 0; $pwd = str_replace('\\', '/', getcwd()); $legPath = "$pwd/images/legend/"; $imgLogFile = $legPath.'createimg.log'; if (!is_file($imgLogFile)) { $writeNew = 1; } else { $mapfile_mtime = filemtime($this->mapFile); $imglogfile_mtime = filemtime($imgLogFile); if ($mapfile_mtime > $imglogfile_mtime) { $writeNew = 1; } } // If necessary re-create legend icons if ($writeNew == 1) { $this->map->selectOutputFormat($imgFormat); $allLayers = $this->map->getAllLayerNames(); // Define background image for legend icons $icoBGLayer = ms_newLayerObj($this->map); $icoBGLayer->set("type", 2); // Add class $bgClass = ms_newClassObj($icoBGLayer); $bgClStyle = ms_newStyleObj($bgClass); $bgClStyle->color->setRGB(255, 255, 255); $bgClStyle->outlinecolor->setRGB(180, 180, 180); foreach ($allLayers as $layName) { $qLayer = $this->map->getLayerByName($layName); // All layers but RASTER or ANNOTATION layers //if ($qLayer->type < 3) { $numclasses = $qLayer->numclasses; if ($numclasses > 0) { for ($cl=0; $cl < $numclasses; $cl++) { $class = $qLayer->getClass($cl); $clname = ($numclasses < 2 ? "" : $class->name); $clStyle = ms_newStyleObj($class); // Set outline for line themes to background color if ($qLayer->type == 1) { #$clStyle->setcolor("outlinecolor", 180, 180, 180); #$clStyle->outlinecolor->setRGB(180, 180, 180); } // set outline to main color if no outline defined (workaround for a bug in the icon creation) if ($qLayer->type == 2) { if ($clStyle->outlinecolor < 1) { #$clStyle->setcolor("outlinecolor", $clStyle->color); $clStyle->outlinecolor->setRGB($clStyle->color); } } $icoImg = $class->createLegendIcon($icoW, $icoH); // needed for ms 3.7 $imgFile = $legPath.$layName.'_i'.$cl . '.'.$_SESSION["imgFormat"]; $icoUrl = $icoImg->saveImage($imgFile); $icoImg->free(); } } //} } $today = getdate(); $datestr = $today['hours'].':'.$today['minutes'].':'.$today['seconds'].'; '.$today['mday'].'/'.$today['month'].'/'.$today['year']; $logStr = "Created legend icons newly on: $datestr"; $imgLogFileFH = fopen ($imgLogFile, 'w+'); fwrite($imgLogFileFH, $logStr); fclose($imgLogFileFH); } } /** * Get absolute data path from map file * */ function _initDataPath() { $shapepath = trim($this->map->shapepath); // absolute path in map file if ($shapepath{0} == "/" || $shapepath{1} == ":") { $_SESSION['datapath'] = str_replace('\\', '/', $shapepath); // relative path in map file, get absolute as combination of shapepath and map file location } else { $_SESSION['datapath'] = str_replace('\\', '/', realpath(dirname($_SESSION['PM_MAP_FILE']) . "/" . $shapepath) ); } } /** * FUNCTION TO RETURN URL FOR MAPFRAME * used for starting application with pre-defined extent * extent read from shape features */ function getMapInitURL($map, $zoomLayer, $zoomQuery) { $qLayer = $this->map->getLayerByName($zoomLayer); // Query parameters $queryList = split('@', $zoomQuery); $queryField = $queryList[0]; $queryFieldType = $queryList[1]; //$queryValue = "/^" . $queryList[2] ."$/"; $queryValue = $queryList[2]; $highlFeature = $queryList[3]; $setMaxExtent = $queryList[4]; // Modify filter for PostGIS & Oracle layers if ($qLayer->connectiontype == 6 || $qLayer->connectiontype == 8) { $q = $queryFieldType == 1 ? "'" : ""; $queryValue = "$queryField = $q$queryValue$q"; //error_log($queryValue); } // Query layer @$qLayer->queryByAttributes($queryField, $queryValue, MS_MULTIPLE); $numResults = $qLayer->getNumResults(); $qLayer->open(); // Return query results (SINGLE FEATURE): shape index and feature extent /* $qRes = $qLayer->getResult(0); $qShape = $qLayer->getShape($qRes->tileindex,$qRes->shapeindex); $qShpIdx = $qShape->index; $qShpBounds = $qShape->bounds; */ // Check if layer has different projection than map // if yes, re-project extent from layer to map projection $mapProjStr = $this->map->getProjection(); $qLayerProjStr = $qLayer->getProjection(); if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) { $mapProjObj = ms_newprojectionobj($mapProjStr); $qLayerProjObj = ms_newprojectionobj($qLayerProjStr); //$qShpBounds->project($this->qLayerProjObj, $this->mapProjObj); $reprojectShape = 1; } // initial max/min values $mExtMinx = 999999999; $mExtMiny = 999999999; $mExtMaxx = -999999999; $mExtMaxy = -999999999; // Return query results: shape index and feature extent for ($iRes=0; $iRes < $numResults; $iRes++) { $qRes = $qLayer->getResult($iRes); $qShape = $qLayer->getShape($qRes->tileindex,$qRes->shapeindex); $qShpIdx = $qShape->index; $qShpBounds = $qShape->bounds; if ($reprojectShape) { $qShpBounds->project($qLayerProjObj, $mapProjObj); } $shpMinx = $qShpBounds->minx; $shpMiny = $qShpBounds->miny; $shpMaxx = $qShpBounds->maxx; $shpMaxy = $qShpBounds->maxy; // Get max/min values of ALL features $mExtMinx = min($mExtMinx, $shpMinx); $mExtMiny = min($mExtMiny, $shpMiny); $mExtMaxx = max($mExtMaxx, $shpMaxx); $mExtMaxy = max($mExtMaxy, $shpMaxy); } // Apply buffer (in units of features) //$buffer = 20000; // <<<<<<<<<<<<<<<<<<<<<< ADAPT VALUE <<<<<<<<<<<<<<<<< $buffer = 0.05 * ((($mExtMaxx - $mExtMinx) + ($mExtMaxy - $mExtMiny)) / 2); $mExtMinx -= $buffer; $mExtMiny -= $buffer; $mExtMaxx += $buffer; $mExtMaxy += $buffer; $roundFact = ($map->units != 5 ? 0 : 6); $shpMinx = round($mExtMinx, $roundFact); $shpMiny = round($mExtMiny, $roundFact); $shpMaxx = round($mExtMaxx, $roundFact); $shpMaxy = round($mExtMaxy, $roundFact); $ext = array ($shpMinx, $shpMiny, $shpMaxx, $shpMaxy); $_SESSION['zoom_extparams'] = $ext; // Set Max Extent for map if ($setMaxExtent) { $mapMaxExt['minx'] = $shpMinx; $mapMaxExt['miny'] = $shpMiny; $mapMaxExt['maxx'] = $shpMaxx; $mapMaxExt['maxy'] = $shpMaxy; $_SESSION['mapMaxExt'] = $mapMaxExt; } // Add highlight feature if defined in URL parameters if ($highlFeature) { $resultlayers[$zoomLayer] = array($qShpIdx); $_SESSION["resultlayers"] = $resultlayers; } // Return URL $searchString = "&mode=map&zoom_type=zoomextent&extent=" . $shpMinx ."+". $shpMiny ."+". $shpMaxx ."+". $shpMaxy . ($highlFeature ? "&resultlayer=$zoomLayer+$qShpIdx" : ""); $mapInitURL = "map.phtml?$searchString"; return $mapInitURL; } /** * Calculate max scale for slider max settings (JS variable s1) * works only for units dd or meters */ function returnMaxScale($map, $mapheight) { $initExtent = $this->map->extent; $y_dgeo = $initExtent->maxy - $initExtent->miny; $scrRes = $this->map->resolution; $this->mapUnits = $this->map->units; $y_dgeo_m = ($this->mapUnits == 5 ? $y_dgeo * 111120 : $y_dgeo); $maxScale = ($y_dgeo_m / $mapheight) / (0.0254 / $scrRes); return round($maxScale); } function returnXYGeoDimensions() { //$initExtent = $this->map->extent; if (isset($_SESSION['mapMaxExt'])) { $me = $_SESSION['mapMaxExt']; $initExtent = ms_newrectObj(); $initExtent->setextent($me["minx"],$me["miny"],$me["maxx"],$me["maxy"]); } else { $initExtent = $this->map->extent; } $dgeo['x'] = $initExtent->maxx - $initExtent->minx; $dgeo['y'] = $initExtent->maxy - $initExtent->miny; $dgeo['c'] = $this->map->units == 5 ? 111120 : 1; return $dgeo; } } ?>