/** * EXECUTE QUERY */ function q_execMapQuery() { // use layers with complex queries that are too long to select results // cause maxscaledenom is not used... $oldDatas = array(); for ($i = 0; $i < $this->map->numlayers; $i++) { $qLayer = $this->map->getLayer($i); if ($qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') { $oldDatas[$i] = $qLayer->data; $qLayer->set('data', $qLayer->getMetaData('PM_RESULT_DATASUBSTITION')); } } // Patch from Alessandro Pasotti for fixing problems with result returned $this->map->setSize($this->mapwidth, $this->mapheight); // Set $this->map->extent to values of current map extent // otherwise values of TOLERANCE in map file are not interpreted correctly $this->map->setExtent($this->GEOEXT['minx'], $this->GEOEXT['miny'], $this->GEOEXT['maxx'], $this->GEOEXT['maxy']); $this->map->preparequery(); // query by point if (count($this->imgxy_arr) == 2) { $this->pointQuery = 1; $this->x_pix = $this->imgxy_arr[0]; $this->y_pix = $this->imgxy_arr[1]; $x_geo = $this->minx_geo + $this->x_pix / $this->mapwidth * $this->xdelta_geo; $y_geo = $this->maxy_geo - $this->y_pix / $this->mapheight * $this->ydelta_geo; $XY_geo = ms_newPointObj(); $XY_geo->setXY($x_geo, $y_geo); $searchArea = -1; // ===> USE TOLERANCE IN MAP FILE FOR EACH LAYER <=== // Use '@' to avoid warning if query found nothing $qtype = $this->mode != "iquery" ? MS_MULTIPLE : MS_SINGLE; // MS_MULTIPLE for normal query, MS_SINGLE for iquery @$this->map->queryByPoint($XY_geo, $qtype, $searchArea); PMCommon::freeMsObj($XY_geo); // query by Rectangle } else { $this->pointQuery = 0; $minx_pix = $this->imgxy_arr[0]; $miny_pix = $this->imgxy_arr[1]; $maxx_pix = $this->imgxy_arr[2]; $maxy_pix = $this->imgxy_arr[3]; if ($minx_pix == $maxx_pix) { $maxx_pix = $maxx_pix + 2; } // increase max extent if min==max if ($miny_pix == $maxy_pix) { $maxy_pix = $maxy_pix - 2; } // -- " -- $this->minx_sel_geo = $this->minx_geo + $minx_pix / $this->mapwidth * $this->xdelta_geo; $this->miny_sel_geo = $this->maxy_geo - $maxy_pix / $this->mapheight * $this->ydelta_geo; $this->maxx_sel_geo = $this->minx_geo + $maxx_pix / $this->mapwidth * $this->xdelta_geo; $this->maxy_sel_geo = $this->maxy_geo - $miny_pix / $this->mapheight * $this->ydelta_geo; $selrect = ms_newrectObj(); $selrect->setExtent($this->minx_sel_geo, $this->miny_sel_geo, $this->maxx_sel_geo, $this->maxy_sel_geo); @$this->map->queryByRect($selrect); PMCommon::freeMsObj($selrect); //$queryFile = "d:/webdoc/tmp/qresults.txt"; //$savedq = $this->map->savequery($queryFile); //printDebug($this->map->loadquery($queryFile)); //error_log( } // use layers with complex queries that are too long to select results // cause maxscaledenom is not used... // reset data tag if (count($oldDatas)) { foreach ($oldDatas as $i => $v) { $qLayer = $this->map->getLayer($i); $qLayer->set('data', $v); } } }
/** * EXECUTE QUERY */ public function q_execMapQuery() { //-------------------------------- // Initialize tolerance to 0 //-------------------------------- $msLayers = array(); // query in specified groups only: if (isset($_REQUEST['groups']) && $_REQUEST['groups']) { $msLayers = getLayersByGroupOrLayerName($this->map, $_REQUEST['groups']); // all groups: } else { for ($i = 0; $i < $this->map->numlayers; $i++) { $msLayers[] = $this->map->getLayer($i); } } foreach ($msLayers as $msLayer) { // change tolerance only for buffer zone search. if ($this->queryType == 'object') { $msLayer->set('tolerance', 0); } } // Modified by Thomas RAFFIN (SIRAP) // to test (substitution) // query by point // Modified by Thomas RAFFIN (SIRAP) // use layers with complex queries that are too long to select results // cause maxscaledenom is not used... $oldDatas = array(); for ($i = 0; $i < $this->map->numlayers; $i++) { $qLayer = $this->map->getLayer($i); $layerName = $qLayer->name; if ($qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') { $oldDatas[$layerName] = $qLayer->data; $qLayer->set('data', $qLayer->getMetaData('PM_RESULT_DATASUBSTITION')); } } // few lines from incphp/query/query.php // Patch from Alessandro Pasotti for fixing problems with result returned $this->map->setSize($this->mapwidth, $this->mapheight); // Set $this->map->extent to values of current map extent // otherwise values of TOLERANCE in map file are not interpreted correctly $this->map->setExtent($this->GEOEXT['minx'], $this->GEOEXT['miny'], $this->GEOEXT['maxx'], $this->GEOEXT['maxy']); $this->map->preparequery(); if ($this->queryType == 'object') { if (isset($_SESSION['pluginsConfig']['graphicalqueries']) && isset($_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'])) { $bufferOnlyWithScale = $_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'] == 1; } else { $bufferOnlyWithScale = true; } if (!$bufferOnlyWithScale) { // PMCommon::setGroups($this->map, $this->querygroups, $this->scale, 0, 1); PMCommon::setGroups($this->map, $this->querygroups, 0, 0, 1); } // Search selected object $jsonPMResult = $_SESSION['JSON_Results']; // "[...]" ou "{...}" $PMResult = json_decode($jsonPMResult); // array ou class if ($PMResult) { $objUnion = false; // List layer of selected object $layersWithResult = $PMResult[0]; // be carreful : 0.000000001 is too small !! $smallBuffer = 1.0E-8; $mapProjStr = $this->map->getProjection(); if ($_SESSION['MS_VERSION'] < 6) { $mapProjObj = ms_newprojectionobj($mapProjStr); } else { $mapProjObj = new projectionObj($mapProjStr); } // Loop on layers $layerName = ''; foreach ($layersWithResult as $layerWithResult) { $objUnionLayer = false; // init layer to close the last open one $layer = false; $layerProjObj = false; // Loop on layer objects foreach ($layerWithResult->values as $selectedObject) { // layer name $currentLayerName = $selectedObject[0]->shplink[0]; if ($currentLayerName != $layerName) { if ($layer) { $layer->close(); } $layerName = $currentLayerName; $layer = $this->map->getLayerByName($layerName); $layerProjObj = false; $layerProjStr = $layer->getProjection(); if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) { if ($_SESSION['MS_VERSION'] < 6) { $layerProjObj = ms_newprojectionobj($layerProjStr); } else { $layerProjObj = new projectionObj($layerProjStr); } } $layer->open(); } $shpIndex = $selectedObject[0]->shplink[1]; // Retrieve shape by its index. $objShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $layer, null, $shpIndex, -1); // changed for compatibility with PG layers and MS >= 5.6 // reproject if ($layerProjObj) { $objShape->project($layerProjObj, $mapProjObj); } // Union of the shapes if ($objUnionLayer) { $objUnionLayer = $objShape->union($objUnionLayer); } else { $objUnionLayer = $objShape; } } // End foreach : Loop of the layer // close layer if exists if ($layer) { $layer->close(); } if ($objUnionLayer) { // Line : Buffer to convert Line or Point to Polygon if ($objUnionLayer->type == MS_SHAPE_LINE && isset($_REQUEST['select_buffer']) && $_REQUEST['select_buffer'] > 0 || $objUnionLayer->type == MS_SHAPE_POINT) { $objUnionLayer = $objUnionLayer->buffer($smallBuffer); // if polygon -> the outline is removed to not select contiguous objects } else { if ($objUnionLayer->type == MS_SHAPE_POLYGON && !isset($_REQUEST['select_buffer'])) { $objBoundary = $objUnionLayer->boundary(); $objBoundary = $objBoundary->buffer($smallBuffer); $objUnionLayer = $objUnionLayer->difference($objBoundary); } } } if ($objUnionLayer) { if ($objUnion) { $objUnion = $objUnion->union($objUnionLayer); } else { $objUnion = $objUnionLayer; } } // End if($objUnionLayer) } // End foreach : loop of layers // Buffer -> Buffer zone if (isset($_REQUEST['select_buffer'])) { if ($objUnion) { $objUnion = $objUnion->buffer($_REQUEST['select_buffer']); unset($_REQUEST['select_buffer']); } } if ($objUnion) { // Query @$this->map->queryByShape($objUnion); } } // Query by point } else { if ($this->queryType == 'point') { $tmpPoint = ms_newPointObj(); $tmpPoint->setXYZ($_REQUEST['select_pointX'], $_REQUEST['select_pointY'], 0); if (isset($_REQUEST['select_buffer'])) { @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $_REQUEST['select_buffer']); } else { @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, -1); } PMCommon::freeMsObj($tmpPoint); // query by Shape } else { if ($this->queryType == 'polygon') { //'shape') $poly = $_REQUEST['select_poly']; $tmpLine = ms_newLineObj(); $tmpPoly = explode(',', $poly); foreach ($tmpPoly as $point) { $tmpTab = explode(' ', $point); $tmpLine->addXY($tmpTab[0], $tmpTab[1]); } $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON); $objPoly->add($tmpLine); // Buffer -> Buffer zone if (isset($_REQUEST['select_buffer'])) { $objPoly = $objPoly->buffer($_REQUEST['select_buffer']); unset($_REQUEST['select_buffer']); } @$this->map->queryByShape($objPoly); PMCommon::freeMsObj($tmpLine); PMCommon::freeMsObj($objPoly); // query by PolyLine } else { if ($this->queryType == 'line') { $poly = $_REQUEST['select_line']; $tmpLine = ms_newLineObj(); $tmpPoly = explode(',', $poly); foreach ($tmpPoly as $point) { $tmpTab = explode(' ', $point); $tmpLine->addXY($tmpTab[0], $tmpTab[1]); } // Reduce the polygon to a polyline for ($i = count($tmpPoly) - 1; $i >= 0; $i--) { $tmpTab = explode(' ', $tmpPoly[$i]); $tmpLine->addXY($tmpTab[0], $tmpTab[1]); } $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON); $objPoly->add($tmpLine); // Buffer -> Buffer zone if (isset($_REQUEST['select_buffer'])) { $bufferLocal = $_REQUEST['select_buffer']; if ($bufferLocal < 0) { $bufferLocal = 0; } $objPoly = $objPoly->buffer($bufferLocal); unset($_REQUEST['select_buffer']); } @$this->map->queryByShape($objPoly); PMCommon::freeMsObj($tmpLine); PMCommon::freeMsObj($objPoly); // query by circle } else { if ($this->queryType == 'circle') { $point = $_REQUEST['select_point']; $radius = $_REQUEST['select_radius']; $tmpPoint = ms_newPointObj(); $tmpTab = explode(' ', $point); $tmpPoint->setXYZ($tmpTab[0], $tmpTab[1], 0); if (isset($_REQUEST['select_buffer'])) { @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius + $_REQUEST['select_buffer']); } else { @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius); } PMCommon::freeMsObj($tmpPoint); } } } } } // Modified by Thomas RAFFIN (SIRAP) // use layers with complex queries that are too long to select results // cause maxscaledenom is not used... // reset data tag foreach ($oldDatas as $qLayer => $oldData) { $qLayer = $this->map->getLayerByName($qLayer); $qLayer->set('data', $oldData); } }
protected function drawImages($printType, $imgDPI, $imgFormat, $prefmap) { // CREATE MAP IMAGE AND PASTE SCALEBAR AND REFERENCE MAP switch ($printType) { // HTML OUTPUT case "html": // allow to redefine images drawing $this->map->set("width", $this->mapW); $this->map->set("height", $this->mapH); // $this->map->set("resolution", 96); $images = $this->drawScaleBarAndRefMap($printType, $imgDPI); $sbarImg = $images['sbarImg']; $refImg = $images['refImg']; $this->pmap_setImgFormat(true); $mapImg = $this->map->draw(); // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT if ($this->existsXYLayer) { $this->pmap_drawXYLayer($mapImg); } //$mapImg->pasteImage($sbarImg, 0, 3, $this->mapH-25); //if ($prefmap) $mapImg->pasteImage($refImg, -1); //$this->imgUrlList[] = $mapImg->saveWebImage(); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImg); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $refImg, true); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $sbarImg); PMCommon::freeMsObj($mapImg); break; // PDF OUTPUT // PDF OUTPUT case "pdf": // Increase size and resolution for better print quality (factor set in config.ini -> pdfres) // Note: resolution has to be increased, too, to keep scale dependency of layers $pdfres = $_SESSION["pdfres"]; $this->map->set("width", $this->mapW * $pdfres); $this->map->set("height", $this->mapH * $pdfres); $this->map->set("resolution", 96 * $pdfres); // MS < 6 // Increase Label size according to magnificion for PDF output $this->increaseLabels($pdfres); $images = $this->drawScaleBarAndRefMap($printType, $imgDPI, $pdfres); $sbarImg = $images['sbarImg']; $refImg = $images['refImg']; $this->pmap_setImgFormat(true); $mapImgHR = $this->map->draw(); // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT if ($this->existsXYLayer) { $this->pmap_drawXYLayer($mapImgHR); } /*$this->imgUrlList[] = $mapImgHR->saveWebImage(); $this->imgUrlList[] = $refImg->saveWebImage(); $this->imgUrlList[] = $sbarImg->saveWebImage();*/ $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImgHR); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $refImg, true); //$this->imgUrlList[] = $refImg->saveWebImage(); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $sbarImg); PMCommon::freeMsObj($mapImgHR); break; // DOWNLOAD HIGH RESOLUTION IMAGE // DOWNLOAD HIGH RESOLUTION IMAGE case "dl": // Increase Label size according to DPI $factor = round($imgDPI / 96); $this->increaseLabels($factor); $images = $this->drawScaleBarAndRefMap($printType, $imgDPI); $sbarImg = $images['sbarImg']; $refImg = $images['refImg']; //$this->map->selectOutputFormat("jpeg"); if ($imgFormat) { $this->map->selectOutputFormat($imgFormat); } else { $this->pmap_setImgFormat(true); } $mapImgHR = $this->map->draw(); // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT if ($this->existsXYLayer) { $this->pmap_drawXYLayer($mapImgHR); } // GeoTIFF output if ($imgFormat) { $tmpFileName = str_replace('\\', '/', $this->map->web->imagepath) . substr(SID, 10) . ".tif"; $mapImgHR->saveImage($tmpFileName, $this->map); $this->imgUrlList[] = $tmpFileName; // JPG or PNG output } else { $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImgHR); $legImg = $this->map->drawLegend(); $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $legImg); PMCommon::freeMsObj($legImg); } PMCommon::freeMsObj($mapImgHR); break; } PMCommon::freeMsObj($refImg); PMCommon::freeMsObj($sbarImg); }
/** * Create all legend icons and group/layer */ public function createLegendList() { $legPath = $_SESSION['PM_BASE_DIR'] . "/images/legend/"; $imgLogFile = $legPath . 'createimg.log'; $this->map->selectOutputFormat($_SESSION["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);*/ //return false; foreach ($allLayers as $layName) { $qLayer = $this->map->getLayerByName($layName); // All layers but RASTER or ANNOTATION layers $numclasses = $qLayer->numclasses; if ($numclasses > 0) { $clno = 0; for ($cl = 0; $cl < $numclasses; $cl++) { $class = $qLayer->getClass($cl); if (!$class->keyimage) { $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->red == -1 || $clStyle->outlinecolor->green == -1 || $clStyle->outlinecolor->blue == -1) { #$clStyle->setcolor("outlinecolor", $clStyle->color); $clStyle->outlinecolor->setRGB($clStyle->color->red, $clStyle->color->green, $clStyle->color->blue); } } // bad legend icon (due to symbolscaledenom, unit or attribute size/width binding) // if ($qLayer->type == MS_LAYER_POINT) { // find max size for all styles $maxSymbolSize = 0; $maxSymbolWidth = 0; $numStyles = $class->numstyles; for ($iStyle = 0; $iStyle < $numStyles; $iStyle++) { $style = $class->getStyle($iStyle); if ($style->size > $maxSymbolSize) { $maxSymbolSize = $style->size; } if ($style->width > $maxSymbolWidth) { $maxSymbolWidth = $style->width; } } // reduce all symbol size and set minsize and maxsize to the same value than size for ($iStyle = 0; $iStyle < $numStyles; $iStyle++) { $style = $class->getStyle($iStyle); // Size: // attribute binding: $changeSize = false; $newSize = 0; if ($style->size == -1) { // line widthout size --> MS use symbol defined size, but it's not the good way to do... if ($qLayer->type == MS_LAYER_LINE) { $newSize = 1; $changeSize = true; } else { if ($qLayer->type == MS_LAYER_POLYGON) { $newSize = $_SESSION["icoH"] / 0.8 / 4; $changeSize = true; } else { // $newSize = $_SESSION["icoH"] / 0.8; $changeSize = false; } } // reduce size } else { if ($maxSymbolSize > $_SESSION["icoH"]) { $newSize = $style->size * $_SESSION["icoH"] / $maxSymbolSize; $changeSize = true; } } if ($changeSize) { $style->set('size', $newSize); } // set minsize and maxsize to size $style->set('minsize', $style->size); $style->set('maxsize', $style->size); // Width: // attribute binding: $changeWidth = false; $newWidth = 0; // bad width for MS > 6 if ($_SESSION['MS_VERSION'] >= 6) { if ($qLayer->type == MS_LAYER_LINE) { $maxLineWidth = 4; // max width in pixel for legend $widthLimitFactor = $_SESSION["icoH"] / $maxLineWidth; if ($maxSymbolWidth > $widthLimitFactor) { $maxSymbolWidth = $maxSymbolWidth * $widthLimitFactor; } } } if ($style->width == -1) { // $newWidth = $_SESSION["icoH"]; $changeWidth = false; if ($qLayer->type == MS_LAYER_POLYGON) { $newWidth = $_SESSION["icoH"] / $maxSymbolWidth; $changeWidth = true; } // reduce width } else { if ($maxSymbolWidth > $_SESSION["icoH"]) { $newWidth = $style->width * $_SESSION["icoH"] / $maxSymbolWidth; $changeWidth = true; } } if ($changeWidth) { $style->set('width', $newWidth); } // set minwidth and maxwidth to width $style->set('minwidth', $style->width); $style->set('maxwidth', $style->width); } // set size units in pixel : $qLayer->set('sizeunits', MS_PIXELS); // } $icoImg = $class->createLegendIcon($_SESSION["icoW"], $_SESSION["icoH"]); // needed for ms 3.7 $imgFile = $legPath . $layName . '_i' . $clno . '.' . $_SESSION["imgFormatExt"]; //error_log($imgFile); $icoUrl = $icoImg->saveImage($imgFile); PMCommon::freeMsObj($icoImg); // class->keyimage --> generate icon too } else { if (isset($_SESSION['legendKeyimageRewrite']) && $_SESSION['legendKeyimageRewrite'] == '1') { $imgFile = $legPath . $layName . '_i' . $clno . '.' . $_SESSION['imgFormatExt']; $keyimage = dirname($_SESSION['PM_MAP_FILE']) . '/' . $class->keyimage; if (file_exists($keyimage)) { if (extension_loaded('gd')) { // existing image: $imageInfo = getimagesize($keyimage); $imageType = $imageInfo[2]; $imageWidth = $imageInfo[0]; $imageHeight = $imageInfo[1]; if ($imageType == IMAGETYPE_JPEG) { $image = imagecreatefromjpeg($keyimage); } elseif ($imageType == IMAGETYPE_GIF) { $image = imagecreatefromgif($keyimage); } elseif ($imageType == IMAGETYPE_PNG) { $image = imagecreatefrompng($keyimage); } // new size: $wRedFactor = $imageWidth <= $_SESSION['icoW'] ? 1 : $_SESSION['icoW'] / $imageWidth; $hRedFactor = $imageHeight <= $_SESSION['icoH'] ? 1 : $_SESSION['icoH'] / $imageHeight; $redFactor = min(max($wRedFactor, $hRedFactor), 1); $newWidth = $imageWidth * $redFactor; $newHeight = $imageHeight * $redFactor; //new image: $newImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight); $newFormat = strtolower($_SESSION['imgFormatExt']); switch ($newFormat) { case 'png': imagepng($newImage, $imgFile); break; case 'jpg': case 'jpeg': imagejpeg($newImage, $imgFile); break; case 'gif': imagegif($newImage, $imgFile); break; default: break; } } } } } if ($class->name) { $clno++; } } } else { //error_log("connType: " . $qLayer->connectiontype); if ($qLayer->connectiontype == 7) { //$this->getWmsLegend($qLayer, $layName, $legPath); } } } date_default_timezone_set($_SESSION['defaultTimeZone']); // Required for PHP 5.3 $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); }
/** * DRAW XY LAYER: ADD POINTS FROM DB TO MAP IMAGE */ protected function pmap_drawXYLayer($img) { $grouplist = $_SESSION["grouplist"]; // Loop through groups and layers to find XYLayers foreach ($grouplist as $grp) { $glayerList = $grp->getLayers(); foreach ($glayerList as $glayer) { $XYLayerProperties = $glayer->getXYLayerProperties(); if ($XYLayerProperties) { // XYLayer found, now process $mLayer = $this->map->getLayer($glayer->getLayerIdx()); $mLayerStatus = $mLayer->status; if ($mLayerStatus == MS_ON) { // Check if XYLayer is switched ON $pearDbClass = $_SESSION['pearDbClass']; require_once "{$pearDbClass}.php"; require_once "../query/query.php"; // Check if Layer projection differs from Map projection $changeLayProj = PMCommon::checkProjection($this->map, $mLayer); // Map extent for limiting query if ($changeLayProj) { $me = $this->map->extent; $mapExt = ms_newRectObj(); $mapExt->setExtent($me->minx, $me->miny, $me->maxx, $me->maxy); $mapExt->project($changeLayProj['mapProj'], $changeLayProj['layProj']); } else { $mapExt = $this->map->extent; } $map_xmin = $mapExt->minx; $map_ymin = $mapExt->miny; $map_xmax = $mapExt->maxx; $map_ymax = $mapExt->maxy; if ($changeLayProj) { PMCommon::freeMsObj($mapExt); } // XY Layer Properties $dsn = $XYLayerProperties["dsn"]; $xyTable = $XYLayerProperties["xyTable"]; $x_fld = $XYLayerProperties["x_fld"]; $y_fld = $XYLayerProperties["y_fld"]; $classidx_fld = $XYLayerProperties["classidx_fld"]; $resFldStr = $mLayer->getMetaData("RESULT_FIELDS"); $resFieldList = preg_split('/[\\s,]+/', $resFldStr); // Prepare query if (preg_match("/@/", $xyTable)) { // Check for WHERE filter in table definition $xyList = preg_split('/@/', $xyTable); $whereFilter = $xyList[1]; $xyTable = $xyList[0]; } $sql_SELECT = "SELECT {$x_fld}, {$y_fld}, {$classidx_fld} FROM {$xyTable} "; $sql_WHERE = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . " {$x_fld} >= {$map_xmin} AND {$x_fld} <= {$map_xmax} AND {$y_fld} >= {$map_ymin} AND {$y_fld} <= {$map_ymax}"; $sql = "{$sql_SELECT} {$sql_WHERE}"; pm_logDebug(3, $sql, "P.MAPPER-DEBUG: map.php/pmap_drawXYLayer() - SQL Cmd:"); // init DB class $db = new $pearDbClass(); // Connect to DB $dbh = $db->connect($dsn); if ($db->isError($dbh)) { PMCommon::db_logErrors($dbh); die; } // Execute query $res = $dbh->query($sql); if ($db->isError($res)) { PMCommon::db_logErrors($res); die; } // Draw points on map image while ($xyRow = $res->fetchRow()) { $ptX = $xyRow[0]; $ptY = $xyRow[1]; $clIdx = $xyRow[2]; $xyPoint = ms_newPointObj(); $xyPoint->setXY($ptX, $ptY); $xyPoint->draw($this->map, $mLayer, $img, $clIdx, ""); PMCommon::freeMsObj($xyPoint); } //$res->free(); $dbh->disconnect(); } } } } }
$map = ms_newMapObj($PM_MAP_FILE); //print_r($map); $timer->start(); $jsonFile = "dynlayer_def.txt"; $dynLayers = preg_replace(array("/\\s{2,}/", "/\n/"), array(" ", ""), file_get_contents($jsonFile)); $_SESSION['dynLayers'] = json_decode($dynLayers, true); $dyn = new DynLayer($map, json_encode($_SESSION['dynLayers'])); $dyn->createDynLayers(); //$map->getLayerByName("cities_1")->set("status", MS_ON); $map->getLayerByName("cities_2")->set("status", MS_ON); $map->getLayerByName("countries")->set("status", MS_ON); //print_r($map->getAllLayerNames()); $map->selectOutputFormat("png"); $map_img = $map->draw(); $map_url = $map_img->saveWebImage(); require_once '../../incphp/common.php'; PMCommon::freeMsObj($map_img); #$timer->stop(); #$timer->display(); $map->save("D:/webdoc/tmp/dynlayer.map"); $dynJson = json_decode($dynLayers); $lay1 = $dynJson->newlayers->layerlist->cities_1; unset($dynJson->newlayers->layerlist->cities_1); // = null; $lay1->name = "pippo"; $dynJson->newlayers->layerlist->cities_1 = $lay1; #print_r($dynJson->newlayers->layerlist->cities_2); //print_r($dynJson->newlayers->layerlist); //unset($_SESSION['dynLayers']['cities_2']); //$_SESSION['dynLayers']['cities_2'] = null; //print_r(json_decode(json_encode($_SESSION['dynLayers'])));
/** * Get the option values from a MapServer layer */ protected function getOptionsFromMS($mslayer, $encoding, $keyfield, $showfield, $sort) { $qLayer = $this->map->getLayerByName($mslayer); $query = $qLayer->queryByAttributes($keyfield, "/()/", MS_MULTIPLE); if ($query == MS_SUCCESS) { $qLayer->open(); $numResults = $qLayer->getNumResults(); //error_log($numResults); for ($iRes = 0; $iRes < $numResults; $iRes++) { $qRes = $qLayer->getResult($iRes); $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes); // changed for compatibility with PG layers and MS >= 5.6 $k = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$keyfield]) : $qShape->values[$keyfield]; $v = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$showfield]) : $qShape->values[$showfield]; $ol[$k] = trim($v); // avoid <, >, ... $ol[$k] = htmlentities($ol[$k], ENT_COMPAT, 'UTF-8'); PMCommon::freeMsObj($qShape); } $json = $this->options_array2json($ol, $sort); return $json; } }
/** * draw refmap image */ public function drawRefMap($minx, $miny, $maxx, $maxy, $width, $height, $useAlternatFormatForMS6) { $this->activateLayers(); // do not use RGBA in MS 6 if refmap will be used in mapObj::drawReferenceMap (transparency not supported) if ($useAlternatFormatForMS6 && $this->msVersion >= 6) { $this->internalMap->selectOutputFormat($this->altOutputFormat); } else { $this->internalMap->selectOutputFormat($this->outputFormat); } $this->internalMap->setSize($width, $height); $this->internalMap->setExtent($minx, $miny, $maxx, $maxy); $refMapImg = $this->internalMap->draw(); $this->refMapURL = PMCommon::mapSaveWebImage($this->internalMap, $refMapImg); PMCommon::freeMsObj($refMapImg); $this->refMapImage = str_replace($this->internalMap->web->imageurl, $this->internalMap->web->imagepath, $this->refMapURL); }
/** * Get Suggest records from a MS layer using generic MapScript attribute query * * @return string */ private function msSuggestMatch($searchParams) { $msVersion = $_SESSION['msVersion']; if (!extension_loaded('MapScript')) { dl("php_mapscript{$msVersion}." . PHP_SHLIB_SUFFIX); } $map = $this->map; pm_logDebug(3, $searchParams, "suggest.php->msSuggestMatch()"); $mslayer = $searchParams['mslayer']; $searchfield = $searchParams['searchfield']; $sort = $searchParams['sort']; $encoding = $searchParams['encoding']; $regexleft = $searchParams['regexleft']; $startleft = $searchParams['startleft']; // many dependfields $dependFields = isset($searchParams['dependFields']) && $searchParams['dependFields'] ? $searchParams['dependFields'] : array(); $left = $startleft ? "^" : ""; $qLayer = $map->getLayerByName($mslayer); $qs = ""; // Create search string // many dependfields $qsDependFieldsParts = array(); if ($dependFields) { foreach ($dependFields as $fieldName => $fieldValue) { $depFldName = "dependfldval_{$fieldName}"; $depFldValue = $searchParams[$depFldName]; $depFldValue = trim($depFldValue); if ($depFldValue != '') { $qsDependFieldsParts[] = "( \"[{$fieldName}]\" =~ /{$depFldValue}/ )"; } } } if ($qsDependFieldsParts) { $qs .= ' (' . implode(' AND ', $qsDependFieldsParts) . ') AND '; } if (trim($searchParams['fieldtype']) == "s") { if ($encoding != $this->defCharset) { $this->search = iconv($this->defCharset, $encoding, $this->search); } $searchVal = get_magic_quotes_gpc() ? stripslashes($this->search) : $this->search; if ($this->msVersion >= 6) { $qs .= "( \"[{$searchfield}]\" ~* \"{$regexleft}{$left}{$searchVal}\" )"; } else { $val = preg_replace("/\\w/ie", "'('. strtoupper('\$0') . '|' . strtolower('\$0') .')'", $searchVal); $qs .= "( \"[{$searchfield}]\" =~ /{$regexleft}{$left}{$val}/ )"; } } else { $qs .= "([{$searchfield}] = {$this->search})"; } if ($layFilter = $qLayer->getFilterString()) { $querystring = "( ({$layFilter}) AND ({$qs}) )"; } else { $querystring = "( {$qs} )"; } pm_logDebug(3, $querystring, "MS suggest query string, suggest.php/msSuggestMatch()"); // Query layer $query = @$qLayer->queryByAttributes($searchfield, $querystring, MS_MULTIPLE); if ($query == MS_SUCCESS) { $qLayer->open(); $numResults = $qLayer->getNumResults(); // Return query results for ($iRes = 0; $iRes < $numResults; $iRes++) { $qRes = $qLayer->getResult($iRes); $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes); // changed for compatibility with PG layers and MS >= 5.6 $fldValue = $qShape->values[$searchfield]; if ($encoding != $this->defCharset) { $fldValue = iconv($encoding, $this->defCharset, $fldValue); } $resArray[] = trim($fldValue); PMCommon::freeMsObj($qShape); } $ret = $this->suggest_array2json($resArray, $sort); return $ret; } else { return 0; } }