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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jul 16 07:54:55 PDT 2015


Author: armin11
Date: 2015-07-16 07:54:55 -0700 (Thu, 16 Jul 2015)
New Revision: 9258

Added:
   trunk/mapbender/conf/geoJsonDefaultStyle.json
   trunk/mapbender/http/classes/class_geojson_style.php
Modified:
   trunk/mapbender/http/php/kmlToGeoJSON.php
   trunk/mapbender/http/php/uploadKml.php
Log:
Add default values for simple style spec if external geojson is uploaded (new digitize module)

Added: trunk/mapbender/conf/geoJsonDefaultStyle.json
===================================================================
--- trunk/mapbender/conf/geoJsonDefaultStyle.json	                        (rev 0)
+++ trunk/mapbender/conf/geoJsonDefaultStyle.json	2015-07-16 14:54:55 UTC (rev 9258)
@@ -0,0 +1,19 @@
+{
+	"Polygon": {
+             	"stroke": "#555555",
+             	"stroke-opacity": "1",
+		"stroke-width":"2",
+		"fill":"#555555",
+		"fill-opacity":"0.5"
+        	},
+	"LineString": {
+             	"stroke": "#555555",
+             	"stroke-opacity": "1",
+		"stroke-width":"2"
+        	},
+	"Point": {
+             	"marker-size":"34",
+             	"marker-symbol":"marker",
+		"marker-color":"#7e7e7e"
+        	}
+}

Added: trunk/mapbender/http/classes/class_geojson_style.php
===================================================================
--- trunk/mapbender/http/classes/class_geojson_style.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_geojson_style.php	2015-07-16 14:54:55 UTC (rev 9258)
@@ -0,0 +1,30 @@
+<?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+class geojson_style {
+	var $geojson;
+	var $geojsonObject;
+	var $defaultStyleJson;
+
+	function __construct () {
+		$this->defaultStyleJson = file_get_contents(dirname(__FILE__)."/../../conf/geoJsonDefaultStyle.json");
+	}
+	
+	public function addDefaultStyles($geojson) {
+		$this->geojson = $geojson;
+		$this->geojsonObject = json_decode($this->geojson);
+		$styleObject = json_decode($this->defaultStyleJson);
+		foreach($this->geojsonObject->features as $feature) {
+			$properties = $feature->properties;
+			foreach ($styleObject->{$feature->geometry->type} as $name => $value) {
+				//check for existence
+				if (gettype($properties->{$name}) == "NULL") {
+					$properties->{$name} = $value;
+			
+				}
+			}
+		}
+		return json_encode($this->geojsonObject);
+	}
+}
+?>

Modified: trunk/mapbender/http/php/kmlToGeoJSON.php
===================================================================
--- trunk/mapbender/http/php/kmlToGeoJSON.php	2015-07-16 09:58:51 UTC (rev 9257)
+++ trunk/mapbender/http/php/kmlToGeoJSON.php	2015-07-16 14:54:55 UTC (rev 9258)
@@ -19,8 +19,8 @@
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_kml_ows.php");
+require_once(dirname(__FILE__)."/../classes/class_geojson_style.php");
 
-
 //FIXME: what about projections?
 //header("Content-Type: text/x-json");
 if(isset($_REQUEST["url"])){
@@ -44,6 +44,9 @@
         }
     }
     if(preg_match('/.(json|geojson)$/', $url)) {
+	//set dummy style attributes if not exits!!!
+	$jsonStyle = new geojson_style();
+	$content = $jsonStyle->addDefaultStyles($content);
         header("Content-Type: text/plain");
         echo $content;
     }

Modified: trunk/mapbender/http/php/uploadKml.php
===================================================================
--- trunk/mapbender/http/php/uploadKml.php	2015-07-16 09:58:51 UTC (rev 9257)
+++ trunk/mapbender/http/php/uploadKml.php	2015-07-16 14:54:55 UTC (rev 9258)
@@ -18,6 +18,7 @@
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__) . "/../classes/class_kml_ows.php");
+require_once(dirname(__FILE__)."/../classes/class_geojson_style.php");
 
 header("Content-Type: text/plain");
 
@@ -35,6 +36,9 @@
         }
     }
     if(preg_match('/.(json|geojson)$/', $_FILES['kml']['name'])) {
+	//set dummy style attributes if not exits!!!
+	$jsonStyle = new geojson_style();
+	$content = $jsonStyle->addDefaultStyles($content);
         header("Content-Type: text/plain");
         echo $content;
     }



More information about the Mapbender_commits mailing list