[Mapbender-commits] r9842 - in trunk/mapbender: conf http/classes http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 11 08:11:01 PST 2018


Author: armin11
Date: 2018-01-11 08:11:01 -0800 (Thu, 11 Jan 2018)
New Revision: 9842

Added:
   trunk/mapbender/http/php/mod_getSymbolFromRepository.php
Modified:
   trunk/mapbender/conf/geoJsonSimpleStyle.json
   trunk/mapbender/http/classes/class_kml_ows.php
   trunk/mapbender/http/php/mod_GetPublishedData.php
Log:
New options for geojson2kml export module

Modified: trunk/mapbender/conf/geoJsonSimpleStyle.json
===================================================================
--- trunk/mapbender/conf/geoJsonSimpleStyle.json	2018-01-11 14:36:11 UTC (rev 9841)
+++ trunk/mapbender/conf/geoJsonSimpleStyle.json	2018-01-11 16:11:01 UTC (rev 9842)
@@ -3,7 +3,7 @@
 		"simple_style_spec_attributes":
 			["title","description","marker-size","marker-symbol","marker-color"],
 		"simple_style_spec_defaults":
-			["dummy title","dummy description","medium","","7e7e7e"],
+			["dummy title","dummy description","medium","marker","#7e7e7e"],
 		"mapbender_extensions":
 			["marker-type"],
 		"mapbender_extensions_default":
@@ -23,7 +23,7 @@
 		"simple_style_spec_attributes":
 			["title","description","stroke","stroke-opacity","stroke-width","fill","fill-opacity"],
 		"simple_style_spec_defaults":
-			["dummy title","dummy description","#555555",1.0,2,"5555557",0.6],
+			["dummy title","dummy description","#555555",1.0,2,"#555557",0.6],
 		"mapbender_extensions":
 			[],
 		"mapbender_extensions_default":

Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php	2018-01-11 14:36:11 UTC (rev 9841)
+++ trunk/mapbender/http/classes/class_kml_ows.php	2018-01-11 16:11:01 UTC (rev 9842)
@@ -283,6 +283,7 @@
 							$currentPropertiesSimpleStyle[$attributeValue] = $value;
 						}
 						//build style part
+						//points don't have a color, cause the color is part of the icon in simplestyle-spec
 						$hash = md5('point'.$currentPropertiesSimpleStyle['marker-size'].$currentPropertiesSimpleStyle['marker-symbol'].$currentPropertiesSimpleStyle['marker-color']);
 						if (!in_array($hash, $styleHashArray)) {
 							//generate style part
@@ -306,8 +307,15 @@
 									$symbol = $makiUrl.$currentPropertiesSimpleStyle['marker-symbol']."-15.svg";
 									break;
 							}							
-							
-							$e_hrefText = $doc->createTextNode($symbol);
+							//alternative for local maki icons
+							$symbolUrl = MAPBENDER_PATH."/php/mod_getSymbolFromRepository.php?";
+							$symbolUrl .= "marker-symbol=".$currentPropertiesSimpleStyle['marker-symbol']."&";
+							$symbolUrl .= "marker-size=".$currentPropertiesSimpleStyle['marker-size']."&";
+							$symbolUrl .= "marker-color=".$currentPropertiesSimpleStyle['marker-color'];
+							//with mod_rewrite
+							$symbolUrl = MAPBENDER_PATH."/../icons/maki/".ltrim($currentPropertiesSimpleStyle['marker-color'],'#')."/".$currentPropertiesSimpleStyle['marker-size']."/".$currentPropertiesSimpleStyle['marker-symbol'].".png";
+
+							$e_hrefText = $doc->createTextNode($symbolUrl);
 							$e_href->appendChild($e_hrefText);
 							$e_Icon->appendChild($e_href);
 							$e_IconStyle->appendChild($e_Icon);
@@ -347,6 +355,10 @@
 						}
 						//build style part
 						$hash = md5('linestring'.$currentPropertiesSimpleStyle['stroke'].$currentPropertiesSimpleStyle['stroke-opacity'].$currentPropertiesSimpleStyle['stroke-width']);
+
+						//map html hex color to kml color code
+						$colorKml = $this->htmlColor2kmlColor($currentPropertiesSimpleStyle['stroke'], $currentPropertiesSimpleStyle['stroke-opacity']); 
+						
 						if (!in_array($hash, $styleHashArray)) {
 							//generate style part
 							$e_Style = $doc->createElement("Style");
@@ -354,7 +366,7 @@
 							$e_LineStyle = $doc->createElement("LineStyle");
 
 							$e_color = $doc->createElement("color");
-							$e_colorText = $doc->createTextNode($currentPropertiesSimpleStyle['stroke']);
+							$e_colorText = $doc->createTextNode($colorKml);
 							$e_color->appendChild($e_colorText);
 							$e_LineStyle->appendChild($e_color);
 
@@ -386,6 +398,9 @@
 						}
 						//build style part
 						$hash = md5('polygon'.$currentPropertiesSimpleStyle['stroke'].$currentPropertiesSimpleStyle['stroke-opacity'].$currentPropertiesSimpleStyle['stroke-width']);
+
+						$colorKml = $this->htmlColor2kmlColor($currentPropertiesSimpleStyle['stroke'], $currentPropertiesSimpleStyle['stroke-opacity']); 
+						$colorKmlFill = $this->htmlColor2kmlColor($currentPropertiesSimpleStyle['fill'], $currentPropertiesSimpleStyle['fill-opacity']); 
 						if (!in_array($hash, $styleHashArray)) {
 							//generate style part
 							$e_Style = $doc->createElement("Style");
@@ -393,7 +408,7 @@
 							$e_LineStyle = $doc->createElement("LineStyle");
 
 							$e_color = $doc->createElement("color");
-							$e_colorText = $doc->createTextNode($currentPropertiesSimpleStyle['stroke']);
+							$e_colorText = $doc->createTextNode($colorKml);
 							$e_color->appendChild($e_colorText);
 							$e_LineStyle->appendChild($e_color);
 
@@ -408,7 +423,7 @@
 							//<PolyStyle><color>7fff44ff</color></PolyStyle>
 							$e_PolyStyle = $doc->createElement("PolyStyle");
 							$e_color = $doc->createElement("color");
-							$e_colorText = $doc->createTextNode($currentPropertiesSimpleStyle['fill']);
+							$e_colorText = $doc->createTextNode($colorKmlFill);
 							$e_color->appendChild($e_colorText);
 							$e_PolyStyle->appendChild($e_color);
 							$e_Style->appendChild($e_PolyStyle);
@@ -462,6 +477,29 @@
 	}
 
 	/**
+	 * @return KML color code from HTML color code and opacity values.
+	 * https://stackoverflow.com/questions/15202079/convert-hex-color-to-rgb-values-in-php
+	 * https://stackoverflow.com/questions/13034702/google-maps-kml-8-digit-hex-code
+	 * https://developers.google.com/kml/documentation/kmlreference#color
+	 */
+	private function htmlColor2kmlColor($hex, $alpha) {
+   		$hex = str_replace('#', '', $hex);
+   		$length = strlen($hex);
+   		$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
+   		$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
+   		$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
+   		if ( $alpha ) {
+      			$rgb['a'] = ceil($alpha * 255);
+   		}
+			$e = new mb_exception("alpha: ".$rgb['a']."hex: ".dechex($rgb['a']));
+			$e = new mb_exception("r: ".$rgb['r']."hex: ".dechex($rgb['r']));
+			$e = new mb_exception("g: ".$rgb['g']."hex: ".dechex($rgb['g']));
+			$e = new mb_exception("b: ".$rgb['b']."hex: ".dechex($rgb['b']));
+		//encode to kml:
+		return dechex($rgb['a']).dechex($rgb['b']).dechex($rgb['g']).dechex($rgb['r']);
+	}
+ 
+	/**
 	 * @return string the ID of this KML.
 	 */
 	public function getId () {

Modified: trunk/mapbender/http/php/mod_GetPublishedData.php
===================================================================
--- trunk/mapbender/http/php/mod_GetPublishedData.php	2018-01-11 14:36:11 UTC (rev 9841)
+++ trunk/mapbender/http/php/mod_GetPublishedData.php	2018-01-11 16:11:01 UTC (rev 9842)
@@ -10,7 +10,7 @@
 require_once(dirname(__FILE__) . "/../classes/class_wmc.php");
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_Uuid.php");
-
+require_once(dirname(__FILE__)."/../classes/class_kml_ows.php");
 /**
  * publish the choosed data
  */
@@ -358,6 +358,13 @@
         return kml_to_gpx($kml);
         die;
     } elseif ($outputFormat == 'kml') {
+	//convert geojson to kml via classes
+	//initialize new kml objekt
+	$kml = new Kml();
+	$kml->parseGeoJSON($geoJson);
+	header("Content-type: text/xml");
+	return $kml->__toString();
+	die();
         //convert geojson to kml
         //create the geojson-file temporary
         $temp_geojson = TMPDIR.'/myDataCollection-'.$fileUuid.'.geojson';

Added: trunk/mapbender/http/php/mod_getSymbolFromRepository.php
===================================================================
--- trunk/mapbender/http/php/mod_getSymbolFromRepository.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_getSymbolFromRepository.php	2018-01-11 16:11:01 UTC (rev 9842)
@@ -0,0 +1,95 @@
+<?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+//apache2 mod_rewrite -  RewriteRule ^/icons/maki/([^/]+)/([^/]+)/([^[/]+).png$ http://127.0.0.1/mb_trunk/php/mod_getSymbolFromRepository.php?marker-color=$1&marker-size=$2&marker-symbol=$3 [P,L,QSA,NE]
+//http://127.0.0.1/icons/maki/7e7e7e/large/airfield.png
+//read variables from path - INFO: marker-color without # as first element!!!!!!
+//read from filesystem and recode from svg to png
+//path
+$symbolPath = dirname(__FILE__)."/../extensions/makiicons/mapbox-maki-463a9ff/icons/";
+//get name from parameter
+
+//read list of possible filenames
+$svgFiles = scandir($symbolPath);
+
+array_walk($svgFiles, 'cutEndPart');
+$svgFiles = array_unique($svgFiles);
+//echo implode(',', $svgFiles);
+$searchString = "airfield";
+$marker = "marker";
+$markerSize = "medium";
+$markerColor = "#7e7e7e";
+
+if (isset($_REQUEST["marker-symbol"]) & $_REQUEST["marker-symbol"] != "") {
+	$marker = $_REQUEST["marker-symbol"];
+}
+
+if (isset($_REQUEST["marker-size"]) & $_REQUEST["marker-size"] != "") {
+	//validate to inside / outside - TODO implement other ones than intersects which is default
+	$testMatch = $_REQUEST["marker-size"];	
+ 	if (!($testMatch == 'medium' or $testMatch == 'large' or $testMatch == 'small')){ 
+		//echo 'searchTypeBbox: <b>'.$testMatch.'</b> is not valid.<br/>';
+		echo 'Parameter <b>marke-size</b> is not valid (small, medium, large).<br/>'; 
+		die(); 		
+ 	}
+	$markerSize = $testMatch; //TODO activate this
+	$testMatch = NULL;
+}
+
+if (isset($_REQUEST["marker-color"]) & $_REQUEST["marker-color"] != "") {
+	//validate to hex color value
+	//
+	//add # before, because # cannot be part of the url
+	$testMatch = "#".$_REQUEST["marker-color"];	
+	//https://stackoverflow.com/questions/12837942/regex-for-matching-css-hex-colors
+	$pattern = '/#([a-f0-9]{3}){1,2}\b/i';
+	
+	if (!preg_match($pattern,$testMatch)){ 
+		echo 'Parameter <b>marker-color</b> is not a valid hex color code.<br/>'; 
+		die(); 		
+ 	}
+	$markerColor = $testMatch;
+	$testMatch = NULL;
+}
+
+//$e = new mb_exception("color: ".$markerColor);
+
+$key = array_search($marker, $svgFiles);
+
+if (gettype($key) == integer) {
+	$svgGraphicFilename = $symbolPath.$svgFiles[$key]."-15.svg";
+} else {
+	$svgGraphicFilename = $symbolPath."marker-15.svg";
+}
+
+$svgGraphic = file_get_contents($svgGraphicFilename);
+
+//replace color
+$svgGraphic = str_replace('<path ', '<path style="fill:'.$markerColor.'" ', $svgGraphic);
+
+//https://stackoverflow.com/questions/9226232/how-to-read-an-svg-with-a-given-size-using-php-imagick
+$im = new Imagick();
+$im->setBackgroundColor(new ImagickPixel('transparent'));
+
+$im->readImageBlob($svgGraphic);
+
+switch ($markerSize){
+	case "medium":
+		$im->scaleImage(20,20);
+		break;
+	case "small":
+		$im->scaleImage(15,15);
+		break;
+	case "large":
+		$im->scaleImage(25,25);
+		break;
+}
+
+$im->setImageFormat("png32");
+header('Content-type: image/png;filename="'.$svgFiles[$key].'-15.svg"');
+echo $im;
+
+function cutEndPart(&$item) {
+    $name = explode('-', $item);
+    $item = $name[0];
+}
+?>



More information about the Mapbender_commits mailing list