[Mapbender-commits] r8273 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Mar 5 09:51:14 EST 2012
Author: armin11
Date: 2012-03-05 06:51:14 -0800 (Mon, 05 Mar 2012)
New Revision: 8273
Added:
trunk/mapbender/http/javascripts/mod_jsonAutocompleteGazetteer.php
Log:
New client modul for geonames org
Added: trunk/mapbender/http/javascripts/mod_jsonAutocompleteGazetteer.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_jsonAutocompleteGazetteer.php (rev 0)
+++ trunk/mapbender/http/javascripts/mod_jsonAutocompleteGazetteer.php 2012-03-05 14:51:14 UTC (rev 8273)
@@ -0,0 +1,307 @@
+<?php
+/**
+ * Package: mod_jsonAutocompleteGazetteer
+ *
+ * Description:
+ * This module generates a table with wms of the mapObject. The user
+ * can change the mapformat, featureinfoformat and the exceptionformat for each wms.
+ * Also the wms priority and the map transparency can be changed interactivly. The module
+ * should exchange the old mod_WMSpreferences module which was an iframe before.
+ * The module is invoked thru a button click. The button must be a mb_button.js module
+ *
+ *
+ * Files:
+ * - http/javascripts/mod_jsonAutocompleteGazetteer.php
+ *
+ * SQL:
+ * >
+ * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment,
+ * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width,
+ * > e_height, e_z_index, e_more_styles, e_content, e_closetag,
+ * > e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES(
+ * > '<app_id>','WMS_preferencesDiv',12,1,'Configure WMS preferences - div tag','WMS preferences',
+ * > 'div','','',870,60,400,500,NULL ,'z-index:9999;','','div','mod_WMSpreferencesDiv.php',
+ * > '','mapframe1','jq_ui_dialog','http://www.mapbender.org/index.php/mod_WMSpreferencesDiv.php');
+ * >
+ * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment,
+ * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height,
+ * > e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url)
+ * > VALUES('<app_id>','WMS_preferencesButton',2,1,'button for configure the preferences of each loaded wms',
+ * > 'Manage WMS preferences','img','../img/button_blink_red/preferences_off.png','',
+ * > 670,60,24,24,1,'','','','../plugins/mb_button.js','','WMS_preferencesDiv',
+ * > '','http://www.mapbender.org/index.php/mb_button');
+ * >
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value,
+ * > context, var_type) VALUES('gui1', 'WMS_preferencesButton', 'dialogWidth', '400', '' ,'var');
+ * >
+ *
+ * Help:
+ * http://www.mapbender.org/mod_WMSpreferencesDiv
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Armin_Retterath
+ *
+ * Parameters:
+ * none
+ *
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+$e_id = 'jsonAutocompleteGazetteer';
+$gui_id = array(Mapbender::session()->get("mb_user_gui"));
+
+//include all element vars from the given element
+//include '../include/dyn_js.php';
+//include '../include/dyn_php.php';
+
+?>
+var standingHighlight = null;
+Mapbender.events.afterMapRequest.register( function(){
+ if(standingHighlight){
+ standingHighlight.paint();
+ }
+});
+
+//initialize module
+if (options.gazetteerUrl === undefined) {
+ options.gazetteerUrl = 'http://www.geoportal.rlp.de/mapbender/geoportal/gaz_geom_mobile.php';
+ //options.gazetteerUrl = 'http://ws.geonames.org/searchJSON?lang=de&';
+}
+if (options.isGeonames === undefined) {
+ options.isGeonames = false;
+}
+if (options.latLonZoomExtension === undefined) {
+ options.latLonZoomExtension = 0.1;
+}
+if (options.minLength === undefined) {
+ options.minLength = 3;
+}
+if (options.delay === undefined) {
+ options.delay = 400;
+}
+if (options.isDraggable === undefined) {
+ options.isDraggable = true;
+}
+if (options.maxResults === undefined) {
+ options.maxResults = 15;
+}
+if (options.inputWidth === undefined) {
+ options.inputWidth = 250;
+}
+if (options.searchEpsg === undefined) {
+ options.searchEpsg = "4326";
+}
+if (options.drawCentrePoint === undefined) {
+ options.drawCentrePoint = true;
+}
+if (options.gazetteerFrontImageOn === undefined) {
+ options.gazetteerFrontImageOn = "../img/button_blue_red/gazetteer3_on.png";
+}
+if (options.gazetteerFrontImageOff === undefined) {
+ options.gazetteerFrontImageOff = "../img/button_blue_red/gazetteer3_off.png";
+}
+var JsonAutocompleteGazetteer = function() {
+ var that = this;
+ var targetName = options.target;
+ var ind = getMapObjIndexByName(targetName);
+ var my = mb_mapObj[ind];
+
+ /*this.zoomToExtent = function(minx,miny,maxx,maxy) {
+ var newExtent = new Mapbender.Extent(
+ parseFloat(minx),
+ parseFloat(miny),
+ parseFloat(maxx),
+ parseFloat(maxy)
+ );
+ my.calculateExtent(newExtent);
+ alert(my.epsg);
+ my.setMapRequest();
+ }*/
+
+ this.zoomToExtent = function(fromSrs,minx,miny,maxx,maxy) {
+ var parameters = {
+ fromSrs: fromSrs,
+ toSrs: Mapbender.modules[targetName].epsg
+ };
+
+ parameters.bbox = parseFloat(minx)+ "," +parseFloat(miny)+ "," +parseFloat(maxx)+ "," +parseFloat(maxy);
+
+ //function to transform from one crs to another
+ var req = new Mapbender.Ajax.Request({
+ url: "../php/mod_coordsLookup_server.php",
+ method: "transform",
+ parameters: parameters,
+ callback: function (obj, success, message) {
+ if (!success) {
+ new Mapbender.Exception(message);
+ return;
+ }
+ if (options.drawCentrePoint) {
+
+ //generate layer for visualization of point
+ if(standingHighlight !== null){
+ standingHighlight.clean();
+ }else{
+ standingHighlight = new Highlight(
+ [options.target],
+ "standingHighlight",
+ {"position":"absolute", "top":"0px", "left":"0px", "z-index":10000},
+ 2);
+ }
+
+ var point0 = new Point(obj.points[0].x,obj.points[0].y);
+ var point1 = new Point(obj.points[1].x,obj.points[1].y);
+ var x = point0.x + (point1.x - point0.x)/2;
+ var y = point0.y + (point1.y - point0.y)/2;
+ var point = new Point(x,y);
+ var ga = new GeometryArray();
+ ga.importPoint({
+ coordinates:[x,y,null]
+ },Mapbender.modules[targetName].epsg)
+ var m = ga.get(-1,-1);
+ standingHighlight.add(m, "#ff0000");
+ //alert(m);
+ standingHighlight.paint();
+ }
+ if (obj.points) {
+ if (obj.points.length === 2) {
+ var newExtent = new Extent(
+ obj.points[0].x,
+ obj.points[0].y,
+ obj.points[1].x,
+ obj.points[1].y
+ );
+ my.calculateExtent(newExtent);
+ }
+ my.setMapRequest();
+ }
+ }
+ });
+ req.send();
+ };
+
+ this.toggleInput = function(){
+ /*if (this.inputAddress.attr("disabled")) {
+ $("#geographicName").show();
+ } else {
+ $("#geographicName").hide();
+ }*/
+ if ($("#geographicName").css("display") == 'none') {
+ $("#geographicName").show();
+ $("#symboldForInputId").attr({'src':options.gazetteerFrontImageOn});
+ } else {
+ $("#geographicName").hide();
+ $("#symboldForInputId").attr({'src':options.gazetteerFrontImageOff});
+ }
+
+ //$("#geographicName").toggle();
+ }
+
+
+
+ this.initForm = function() {
+ epsg = Mapbender.modules[targetName].epsg.replace('EPSG:', '');
+ this.formContainer = $(document.createElement('form')).attr({'id':'json-autocomplete-gazetteer'}).appendTo('#' + options.id);
+ this.formContainer.submit(function() {
+ return false;
+ });
+ if (options.isDraggable){
+ this.formContainer.draggable();
+ }
+ //this.labelForInput = $(document.createElement('label')).appendTo(this.formContainer);
+ //this.labelForInput.attr({'for':'geographicName'});
+ //this.labelForInputTitle = this.labelForInput.append('<?php echo _mb('Address'); ?>: ');
+ this.symbolForInput = $(document.createElement('img')).appendTo(this.formContainer);
+ this.symbolForInput.attr({'id':'symboldForInputId'});
+ this.symbolForInput.attr({'src':options.gazetteerFrontImageOn});
+ this.symbolForInput.attr({'title':'<?php echo _mb('Address'); ?>'});
+ this.symbolForInput.click(function() {
+ that.toggleInput();
+ });
+ //.ui-menu .ui-menu-item {
+ this.inputAddress = $(document.createElement('input')).appendTo(this.formContainer);
+ this.inputAddress.attr({'id':'geographicName'});
+ //default value
+ this.inputAddress.val('<?php echo _mb('Search for addresses'); ?>');
+ this.inputAddress.css('width',options.inputWidth);
+ $('.ui-menu').css('width','100px');
+ $('.ui-menu-item').css('width','100px');
+ //set the loading symbol for autoloader class
+ $('.ui-autocomplete-loading').css('background','white url("../img/indicator_wheel.gif") right center no-repeat');
+ //http://stackoverflow.com/questions/622122/how-can-i-change-the-css-class-rules-using-jquery
+ //$("<style type='text/css'> .ui-autocomplete { position: absolute; cursor: default; background:black; color:white} </style>").appendTo("head");
+
+ //this.inputAddress.attr({'width':options.inputWidth}); is defind thru css ui-widget-autocomplete
+ $(function() {
+ $( "#geographicName" ).autocomplete({
+ source: function( request, response ) {
+ $.ajax({
+ url: options.gazetteerUrl,
+ dataType: "jsonp",
+ data: {
+ outputFormat: 'json',
+ resultTarget: 'web',
+ searchEPSG: options.searchEpsg,
+ maxResults: options.maxResults,
+ maxRows: options.maxResults,
+ searchText: request.term,
+ featureClass: "P",
+ style: "full",
+ name_startsWith: request.term
+
+ },
+ success: function( data ) {
+ if (options.isGeonames) {
+ response( $.map( data.geonames, function( item ) {
+ return {
+ label: item.name+" - "+item.fclName+" - "+item.countryName,
+ minx: item.lng-options.latLonZoomExtension,
+ miny: item.lat-options.latLonZoomExtension,
+ maxx: item.lng+options.latLonZoomExtension,
+ maxy: item.lat+options.latLonZoomExtension
+ }
+ }));
+ } else {
+ response( $.map( data.geonames, function( item ) {
+ return {
+ label: item.title,
+ minx: item.minx,
+ miny: item.miny,
+ maxx: item.maxx,
+ maxy: item.maxy
+ }
+ }));
+ }
+ }
+ });
+ },
+ minLength: options.minLength,
+ delay: options.delay,
+ select: function( event, ui ) {
+ that.zoomToExtent("EPSG:"+options.searchEpsg,ui.item.minx,ui.item.miny,ui.item.maxx,ui.item.maxy);
+ },
+ open: function() {
+ $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
+ },
+ close: function() {
+ $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
+ }
+ });
+ });
+ }
+ this.initForm();
+}
+
+Mapbender.events.init.register(function() {
+ Mapbender.modules[options.id] = $.extend(new JsonAutocompleteGazetteer(),Mapbender.modules[options.id]);
+});
+
+
+
+
More information about the Mapbender_commits
mailing list