private function readConfig($jsonConfFile) { $admin = new administration(); $mbjson = new Mapbender_JSON(); $jsonStr = file_get_contents(dirname(__FILE__) . "/../" . $jsonConfFile); if ($jsonStr == false) { $e = new mb_exception("mbPdfFactory: config file could not be read."); die("config not found."); } $jsonConf = $mbjson->decode($admin->char_encode($jsonStr)); return $jsonConf; }
public function decorate() { $mmPerPt = 0.3527; $this->pdf->objPdf->setTextColor(0, 0, 0); $this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size); $currentX = $this->conf->x_ul; $currentY = $this->conf->y_ul; $json = new Mapbender_JSON(); $wmsLegendArray = $json->decode($_POST["legend_url"]); if (!is_array($wmsLegendArray)) { //TODO: error message return; } for ($i = 0; $i < count($wmsLegendArray); $i++) { $layerLegendObj = $wmsLegendArray[$i]; if (!is_object($layerLegendObj)) { continue; } foreach ($layerLegendObj as $title => $layerLegendArray) { if (!is_array($layerLegendArray)) { continue; } // Title $titleFontSize = $this->conf->font_size + 1; $this->pdf->objPdf->setFont($this->conf->font_family, "", $titleFontSize); $this->pdf->objPdf->Text($currentX, $currentY, html_entity_decode(utf8_decode($title))); // $currentY += $mmPerPt * $this->conf->font_size; $currentY += $titleFontSize; $this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size); for ($j = 0; $j < count($layerLegendArray); $j++) { // Legend $currentLegendObj = $layerLegendArray[$j]; $this->pdf->objPdf->Text($currentX, $currentY, html_entity_decode(utf8_decode($currentLegendObj->title))); //$currentY += $mmPerPt * $this->conf->font_size; $currentY += $this->conf->font_size; // store current legend image temporarily $legendFilename = TMPDIR . "/legend_" . substr(md5(uniqid(rand())), 0, 7) . ".png"; $saveLegend = new SaveLegend($currentLegendObj->legendUrl, $legendFilename); list($width, $height) = getimagesize($legendFilename); $width = $width / $this->pdf->objPdf->k; $height = $height / $this->pdf->objPdf->k; try { $this->pdf->objPdf->Image($legendFilename, $currentX, $currentY - 3.5, $width * $this->conf->scale); } catch (Exception $E) { $e = new mb_exception("Can't write Legend Image to pdf: " . $E->getmessage); } $currentY += $height * $this->conf->scale; } $currentY += 5; } } $this->pdf->unlink($legendFilename); }
$jsArray = $wmc->toJavaScript(); if ($jsArray) { $resultObj["javascript"] = $jsArray; $ajaxResponse->setResult($resultObj); $ajaxResponse->setSuccess(true); } else { $ajaxResponse->setMessage(_mb("WMC could not be loaded.")); $ajaxResponse->setSuccess(false); } break; // merges data with WMC and loads it (returns array of JS code) // merges data with WMC and loads it (returns array of JS code) case "mergeWmc": // generate a WMC for the current client state $currentWmc = new wmc(); $currentWmc->createFromJs($json->decode($ajaxResponse->getParameter("mapObject")), $ajaxResponse->getParameter("generalTitle"), $ajaxResponse->getParameter("extensionData")); // get the desired WMC from the database $wmcId = $ajaxResponse->getParameter("id"); $wmcXml = wmc::getDocument($wmcId); // merge the two WMCs $currentWmc->merge($wmcXml); // load the merged WMC $jsArray = $currentWmc->toJavaScript(); if (is_array($jsArray) && count($jsArray) > 0) { $resultObj["javascript"] = $jsArray; $ajaxResponse->setResult($resultObj); $ajaxResponse->setSuccess(true); } else { $ajaxResponse->setMessage(_mb("WMC could not be merged.")); $ajaxResponse->setSuccess(false); }
<?php require_once dirname(__FILE__) . "/../classes/class_json.php"; $json = new Mapbender_JSON(); $queryObj = $json->decode($_REQUEST['queryObj']); if ($queryObj->sessionName && $queryObj->sessionId) { session_name($queryObj->sessionName); session_id($queryObj->sessionId); session_start(); session_write_close(); } require_once dirname(__FILE__) . "/../classes/class_user.php"; require_once dirname(__FILE__) . "/../classes/class_administration.php"; /** * encodes and delivers the data * * @param object the un-encoded object */ function sendOutput($out) { global $json; $output = $json->encode($out); header("Content-Type: text/x-json"); echo $output; } $resultObj = array(); $data = array(); $e = new mb_notice("command: " . $queryObj->command); $user = new User(); switch ($queryObj->command) { case 'delete':
<?php require_once dirname(__FILE__) . "/../php/mb_validateSession.php"; require_once dirname(__FILE__) . "/../classes/class_administration.php"; require_once dirname(__FILE__) . "/../classes/class_wfs.php"; require_once dirname(__FILE__) . "/../classes/class_json.php"; require_once dirname(__FILE__) . "/../classes/class_universal_wfs_factory.php"; $json = new Mapbender_JSON(); $obj = $json->decode($_REQUEST['obj']); //workflow: switch ($obj->action) { case 'getServices': $obj->services = getServices($obj); sendOutput($obj); break; case 'getWfsConfData': $obj->wfsConf = getWfsConfData($obj->wfs); sendOutput($obj); break; case 'getGuis': $obj->id = getGuis($obj); sendOutput($obj); break; case 'getAssignedConfs': $obj->assignedConfs = getAssignedConfs($obj); sendOutput($obj); break; case 'getUpdateUrl': $obj->url = getUpdateUrl($obj); sendOutput($obj); break;
public function updateKml($kmlId, $placemarkId, $geoJSON) { $kmlFromDb = $this->getKmlDocumentFromDB($kmlId); if ($kmlFromDb !== NULL) { // load the KML from the database in the DOM object $kmlDoc_DOM = new DOMDocument("1.0"); $kmlDoc_DOM->encoding = CHARSET; $kmlDoc_DOM->preserveWhiteSpace = false; $kmlDoc_DOM->loadXML($kmlFromDb); //load the geoJSON $json = new Mapbender_JSON(); $geoObj = $json->decode($geoJSON); // construct an array that holds all metadata of the placemark $metadataObj = $geoObj->properties; // construct an array that holds all geometries of the placemark $geometryObj = $geoObj->geometry; $geometryType = $geometryObj->type; if ($geometryType == "GeometryCollection") { $geometryArray = $geometryObj->geometries; } else { if ($geometryType == "Point" || $geometryType == "LineString" || $geometryType == "Polygon") { $geometryArray = array($geometryObj); } else { $e = new mb_exception("class_kml: Invalid geometry type " . $geometryType); return false; } } // // apply the changes // $currentPlacemarkArray = $kmlDoc_DOM->getElementsByTagName("Placemark"); $currentPlacemark = $currentPlacemarkArray->item($placemarkId); if ($currentPlacemark) { $metadataUpdateSuccessful = $this->updateMetadata($currentPlacemark, $metadataObj); $geometryUpdateSuccessful = $this->updateGeometries($currentPlacemark, $geometryArray); } else { $e = new mb_exception("class_kml.php: updateKml: placemark " . $placemarkId . " not found in KML " . $kmlId . "."); return false; } if ($metadataUpdateSuccessful && $geometryUpdateSuccessful) { $updatedKml = $kmlDoc_DOM->saveXML(); $this->updateInDb($updatedKml, $kmlId); } else { if (!$metadataUpdateSuccessful) { $e = new mb_exception("class_kml: Updating the metadata failed, no database update."); } if (!$geometryUpdateSuccessful) { $e = new mb_exception("class_kml: Updating the geometries failed, no database update."); } return false; } } else { $e = new mb_exception("class_kml: No KML found in database, no database update. " . db_error()); return false; } return true; }
public function parseGeoJSON($geoJSON, $kmlId) { // $e = new mb_notice("GEOJSON: " . $geoJSON); $json = new Mapbender_JSON(); $geometryFromGeoJSON = $json->decode($geoJSON); $id = 0; if (gettype($geometryFromGeoJSON) == "object" && $geometryFromGeoJSON->type == "FeatureCollection") { if ($geometryFromGeoJSON->crs->type == "EPSG" && $geometryFromGeoJSON->crs->properties->code) { $epsg = $geometryFromGeoJSON->crs->properties->code; } // create Placemarks for ($i = 0; $i < count($geometryFromGeoJSON->features); $i++) { $e = new mb_notice("parsing plm #" . $i . "...length of placemarkArray: " . count($this->placemarkArray)); $feature = $geometryFromGeoJSON->features[$i]; if (gettype($feature) == "object" && $feature->type == "Feature") { if ($feature->geometry->crs->type == "EPSG") { $epsg = $feature->geometry->crs->properties->code; } if (!$epsg) { $e = new mb_notice("EPSG is not set! Aborting...(" . $epsg . ")"); } $geometry = $feature->geometry; $currentGeometry = false; //TODO: missing Polygon and MultiGeometry switch ($geometry->type) { case "LineString": $coordinateList = ""; for ($j = 0; $j < count($geometry->coordinates); $j++) { if ($j > 0) { $coordinateList .= " "; } $coordinateList .= implode(",", $geometry->coordinates[$j]); } $currentGeometry = new KMLLine($coordinateList, $epsg); break; case "Point": $coordinateList = implode(",", $geometry->coordinates); $currentGeometry = new KMLPoint($coordinateList, $epsg); break; } if ($currentGeometry) { $currentPlacemark = new KMLPlacemark($currentGeometry); if (gettype($feature->properties) == "object") { foreach ($feature->properties as $key => $value) { $currentPlacemark->setProperty($key, $value); } $currentPlacemark->setProperty("Mapbender:kml", true); $currentPlacemark->setProperty("Mapbender:name", "unknown"); $currentPlacemark->setProperty("Mapbender:id", $kmlId); $currentPlacemark->setProperty("Mapbender:placemarkId", $id); $e = new mb_notice("adding to placemarkArray (current length: " . count($this->placemarkArray) . ")"); array_push($this->placemarkArray, $currentPlacemark); $e = new mb_notice("added...new length: " . count($this->placemarkArray)); $id++; } } } } } return true; }
require_once dirname(__FILE__) . "/../classes/class_json.php"; require_once dirname(__FILE__) . "/../classes/class_lzw_decompress.php"; $ajaxResponse = new AjaxResponse($_POST); if ($ajaxResponse->getMethod() != "saveWMC") { $ajaxResponse->setSuccess(false); $ajaxResponse->setMessage("method invalid"); $ajaxResponse->send(); exit; } $json = new Mapbender_JSON(); // get data from POST and SESSION $userId = Mapbender::session()->get("mb_user_id"); $mapObject = $ajaxResponse->getParameter('mapObject'); $lzwCompressed = $ajaxResponse->getParameter('lzwCompressed'); $saveInSession = $ajaxResponse->getParameter('saveInSession'); $extensionData = $json->decode($ajaxResponse->getParameter('extensionData')); $attributes = $ajaxResponse->getParameter('attributes'); $overwrite = $ajaxResponse->getParameter('overwrite'); $overwrite = $overwrite == "1" ? true : false; //for debugging, write mapObject to file if ($lzwCompressed == 'true') { //$e = new mb_exception('mod_savewmc_server.php: mapObject: '.implode(',',$mapObject)); $mapObject = lzw_decompress($mapObject); //$e = new mb_exception('mod_savewmc_server.php: mapObject uncompressed: '.$mapObject); //$filename = TMPDIR."/formerly_compressed_json.txt";//will be set to new one cause ? } else { //$filename = TMPDIR."/formerly_uncompressed_json.txt";//will be set to new one cause ? } //file_put_contents($filename, $mapObject); //$e = new mb_exception('mod_savewmc_server.php: mapObject is here ;-)'); $mapObject = $json->decode($mapObject);
/** * Creates a GML object from a GeoJSON (http://www.geojson.org) String * * @return Gml * @param $geoJson String */ public function createFromGeoJson($geoJson, $gml) { $json = new Mapbender_JSON(); $jsonObj = $json->decode($geoJson); // check if valid feature collection if (strtoupper($jsonObj->type) != "FEATURECOLLECTION" || !is_array($jsonObj->features)) { $e = new mb_exception("Not a valid GeoJSON Feature Collection: " . $geoJson); return null; } $gml->featureCollection = new FeatureCollection(); foreach ($jsonObj->features as $currentFeature) { $feature = new Feature(); if (!is_object($currentFeature->crs) || $currentFeature->crs->type !== "name") { $e = new mb_exception("Feature doesn't have a SRS."); return null; } $srs = $currentFeature->crs->properties->name; // set geometry if (is_object($currentFeature->geometry)) { $currentGeometry = $currentFeature->geometry; switch (strtoupper($currentGeometry->type)) { case "POLYGON": $geometry = new GMLPolygon(); for ($i = 0; $i < count($currentGeometry->coordinates); $i++) { $currentRing = $currentGeometry->coordinates[$i]; foreach ($currentRing as $coords) { if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $coords; } else { list($x, $y) = $coords; } // exterior ring if (0 == $i) { $geometry->addPoint($x, $y); } else { $geometry->addPointToRing($i, $x, $y); } } } break; case "POINT": $geometry = new GMLPoint(); if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $currentGeometry->coordinates; } else { list($x, $y) = $currentGeometry->coordinates; } $geometry->setPoint($x, $y); break; case "MULTIPOINT": $geometry = new GMLMultiPoint(); for ($i = 0; $i < count($currentGeometry->coordinates); $i++) { $currentPoint = $currentGeometry->coordinates[$i]; if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $currentPoint; } else { list($x, $y) = $currentPoint; } $geometry->addPoint($x, $y); } break; case "LINESTRING": $geometry = new GMLLine(); for ($i = 0; $i < count($currentGeometry->coordinates); $i++) { $currentLinePoint = $currentGeometry->coordinates[$i]; if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $currentLinePoint; } else { list($x, $y) = $currentLinePoint; } $geometry->addPoint($x, $y); } break; case "MULTIPOLYGON": $geometry = new GMLMultiPolygon(); for ($i = 0; $i < count($currentGeometry->coordinates); $i++) { $currentPolygon = $currentGeometry->coordinates[$i]; for ($j = 0; $j < count($currentPolygon); $j++) { $currentRing = $currentPolygon[$j]; foreach ($currentRing as $coords) { if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $coords; } else { list($x, $y) = $coords; } // exterior ring if (0 == $j) { $geometry->addPoint($x, $y, $i); } else { $geometry->addPointToRing($i, $j - 1, $x, $y); } } } } break; case "MULTILINESTRING": // not tested! $geometry = new GMLMultiLine(); for ($i = 0; $i < count($currentGeometry->coordinates); $i++) { $currentLine = $currentGeometry->coordinates[$i]; foreach ($currentLine as $currentLinePoint) { if (in_array($srs, $geometry->latLonSrs)) { list($y, $x) = $currentLinePoint; } else { list($x, $y) = $currentLinePoint; } $geometry->addPoint($x, $y, $i); } } break; case "GEOMETRYCOLLECTION": $e = new mb_exception($currentGeometry->type . " are not supported!"); return null; break; default: $e = new mb_exception($currentGeometry->type . " is not a valid geometry type"); return null; break; } // add the geometry to the feature $geometry->srs = $srs; $feature->geometry = $geometry; } else { $e = new mb_exception("This feature does not have a geometry."); return null; } // set fid and properties if (is_object($currentFeature->properties)) { foreach ($currentFeature->properties as $pName => $pValue) { if ("fid" == $pName) { $feature->fid = $pValue; } else { $feature->properties[$pName] = $pValue; } } } $gml->featureCollection->addFeature($feature); } return $gml; }