[Mapbender-commits] r5986 - in trunk/mapbender/http: php plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Apr 20 10:44:51 EDT 2010
Author: kmq
Date: 2010-04-20 10:44:51 -0400 (Tue, 20 Apr 2010)
New Revision: 5986
Added:
trunk/mapbender/http/php/kmlToGeoJSON.php
trunk/mapbender/http/plugins/mb_loadkmlgeorss.js
Log:
add element to temporarily load kml and georss into mapbender
Added: trunk/mapbender/http/php/kmlToGeoJSON.php
===================================================================
--- trunk/mapbender/http/php/kmlToGeoJSON.php (rev 0)
+++ trunk/mapbender/http/php/kmlToGeoJSON.php 2010-04-20 14:44:51 UTC (rev 5986)
@@ -0,0 +1,53 @@
+<?php
+# http://www.mapbender.org/index.php/Administration
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+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");
+
+
+//FIXME: what about projections?
+//header("Content-Type: text/x-json");
+
+if(isset($_REQUEST["url"])){
+ $url = $_REQUEST["url"];
+}else{
+ echo("{}");
+ exit;
+}
+
+
+$kml = new KML();
+$con = new connector();
+$kmlString = $con->load($url);
+try {
+
+ if($kml->parseKml($kmlString)){
+ $geojson = $kml->toGeoJSON();
+ echo $geojson;
+ }else{
+ echo("{}");
+ }
+
+
+} catch (Exception $e) {
+ echo($e);
+ die;
+}
+
+?>
Added: trunk/mapbender/http/plugins/mb_loadkmlgeorss.js
===================================================================
--- trunk/mapbender/http/plugins/mb_loadkmlgeorss.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_loadkmlgeorss.js 2010-04-20 14:44:51 UTC (rev 5986)
@@ -0,0 +1,108 @@
+
+var that = this;
+var markers = [];
+
+$('<div id="'+ options.id +'_dialog"><label>GeoRSS <input type="radio" name="type" value="GeoRSS" checked="checked"/></label>\
+ <label>KML<input type="radio" name="type" value="KML"></label><br />\
+ <label>Paste Url here </label> <input id="' + options.id +'_url" type="text" /></div>').dialog({
+ bgiframe: true,
+ autoOpen: false,
+ height: 240,
+ width: 400,
+ buttons: {
+ "OK" : function(){
+ var url = $('#' + options.id + '_url').val();
+ $('#' + options.id + '_url').val("");
+ var $dialog = $(this);
+
+ console.log($("input:checked", $dialog));
+ if($("input:checked",$dialog).val() == "GeoRSS"){
+ var endpointURL = "../php/geoRSSToGeoJSON.php";
+ }else{
+ var endpointURL = "../php/kmlToGeoJSON.php";
+ }
+ $.ajax({ url: endpointURL,
+ data: {url: url},
+ type: "POST",
+ dataType: "json",
+ success: function(data,textStatus,xhr){
+ console.log(data);
+
+ var map = $('#mapframe1').mapbender();
+
+ $("table", $dialog).remove();
+ var $table = $("<table><thead><tr><th>Name</th></tr></thead><tbody></tbody></table>");
+ if(data.features){
+ var markeroptions = {};
+ for(var i in data.features){
+ if(data.features[i].properties.title){
+ $("tbody",$table).append("<tr><td>"+ data.features[i].properties.title +"</td></tr>");
+ }else if(data.features[i].properties.name){
+ $("tbody",$table).append("<tr><td>"+ data.features[i].properties.name +"</td></tr>");
+ }
+ if(data.features[i].properties.iconurl){
+ markeroptions.img = {url: data.features[i].properties.iconurl, offset: {x:0,y:0}} ;
+ }
+
+
+ var x = data.features[i].geometry.coordinates[0];
+ var y = data.features[i].geometry.coordinates[1];
+ point = new Mapbender.Point(x,y);
+
+ $("tr:last-child", $table).click((function(x,y){
+ return function(){
+ var buffer = new Mapbender.Point(0.10,0.10);
+ var a = new Mapbender.Point(x,y);
+ a = a.minus(buffer);
+
+ var b = new Mapbender.Point(x,y);
+ b = b.plus(buffer);
+
+ map.calculateExtent( new Mapbender.Extent(a,b));
+ map.setMapRequest();
+ }})(x,y));
+ marker = new Mapbender.Marker(point,map, markeroptions);
+ markers.push(marker);
+
+ }
+ }
+ var $tableDialog = $("<div></div>").dialog({
+ width: "450",
+ height: "500",
+ beforeclose: function(){
+
+ for(var i in markers){
+ markers[i].remove();
+ }
+
+ },
+ buttons: {"Close": function(){
+ $(this).dialog('close');
+ $(this).dialog('destroy');
+ }
+ }
+ });
+ $tableDialog.append($table);
+ $table.dataTable({"bJQueryUI": true });
+
+
+ $dialog.dialog('close');
+ },
+ error: function(xhr, ajaxOptions,error){
+ $("<div>Could not load Document</div>").dialog({ buttons: {"OK":function(){ $(this).dialog("close"); }} });
+ }
+ });
+ },
+ "Cancel": function(){
+ $(this).dialog("close");
+ }
+ }
+});
+Mapbender.events.init.register(function () {
+ $(that).click(function(){
+ $('#'+options.id+'_dialog').dialog('open');
+
+ });
+
+});
+
More information about the Mapbender_commits
mailing list