/** * 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(); } } } } }
function dumpXYQueryResults() { $pearDbClass = $_SESSION['pearDbClass']; require_once "{$pearDbClass}.php"; $eqr = $_SESSION["equeryRect"]; // XY Layer Properties $XYLayerProperties = $this->glayer->getXYLayerProperties(); if ($XYLayerProperties['noQuery']) { return false; } $dsn = $XYLayerProperties["dsn"]; $xyTable = $XYLayerProperties["xyTable"]; $x_fld = $XYLayerProperties["x_fld"]; $y_fld = $XYLayerProperties["y_fld"]; $classidx_fld = $XYLayerProperties["classidx_fld"]; $oid_fld = $XYLayerProperties["oid_fld"]; $resFieldList = $this->glayer->getResFields(); $resFldStr = join(',', $resFieldList); // Prepare SQL 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}, {$resFldStr} FROM {$xyTable}"; $qr = $this->xyLayQueryList; $changeLayProj = PMCommon::checkProjection($this->map, $this->qLayer); // Map extent for limiting query if ($changeLayProj) { $mapExt = ms_newRectObj(); $mapExt->setExtent($qr["xmin"], $qr["ymin"], $qr["xmax"], $qr["ymax"]); $mapExt->project($changeLayProj['mapProj'], $changeLayProj['layProj']); $qxmin = $mapExt->minx; $qymin = $mapExt->miny; $qxmax = $mapExt->maxx; $qymax = $mapExt->maxy; } else { $qxmin = $qr["xmin"]; $qymin = $qr["ymin"]; $qxmax = $qr["xmax"]; $qymax = $qr["ymax"]; } if ($this->search) { $sql_where = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . $qr; } else { $sql_where = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . " {$x_fld} >= {$qxmin} AND {$x_fld} <= {$qxmax} AND {$y_fld} >= {$qymin} AND {$y_fld} <= {$qymax} "; } $sql = "{$sql_select} {$sql_where}"; pm_logDebug(3, $query, "P.MAPPER-DEBUG: squery.php/dumpXYQueryResults() - 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; } $this->mExtMinx = 999999999; $this->mExtMiny = 999999999; $this->mExtMaxx = -999999999; $this->mExtMaxy = -999999999; // Now print results as JSON $nres = 0; $numrows = $res->numRows(); while ($row = $res->fetchRow(2)) { if ($changeLayProj) { $nP = ms_newpointobj(); $nP->setXY($row["{$x_fld}"], $row["{$y_fld}"]); $nP->project($changeLayProj['layProj'], $changeLayProj['mapProj']); $rx = $nP->x; $ry = $nP->y; } else { $rx = $row["{$x_fld}"]; $ry = $row["{$y_fld}"]; } $buf = $this->pointBuffer; //error_log($buf); $shpMinx = $rx - $buf; $shpMiny = $ry - $buf; $shpMaxx = $rx + $buf; $shpMaxy = $ry + $buf; if ($this->zoomFull) { $this->mExtMinx = min($this->mExtMinx, $shpMinx); $this->mExtMiny = min($this->mExtMiny, $shpMiny); $this->mExtMaxx = max($this->mExtMaxx, $shpMaxx); $this->mExtMaxy = max($this->mExtMaxy, $shpMaxy); } // Link for zoom to feature $qShpIdx = $row["{$oid_fld}"]; $this->resultindexes[] = $row["{$x_fld}"] . "@" . $row["{$y_fld}"]; // Output JSON //$qShpLink = "{\"shplink\": [\"0\",\"0\",\"" . $shpMinx ."+". $shpMiny ."+". $shpMaxx ."+". $shpMaxy ."\,0"]}"; $qShpLink = "{\"shplink\": [\"" . $this->qLayerName . "\",\"" . $qShpIdx . "\",\"" . $shpMinx . "+" . $shpMiny . "+" . $shpMaxx . "+" . $shpMaxy . "\"" . ($this->zoomFull ? ",1" : ",0") . "]}"; if ($nres > 0) { $this->qStr .= ", "; } // Add shape link $this->qStr .= "[" . $qShpLink; // Add 'normal' field values foreach ($resFieldList as $fn) { $this->qStr .= $this->printFieldValues($fn, $row["{$fn}"]); } $this->qStr .= "]"; $nres++; // Stop query if result records exceed limit set in config.ini if ($nres > $this->limitResult) { break; } } $this->numResults = $nres; $res->free(); $dbh->disconnect(); }