[Mapbender-commits] r9212 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jun 12 00:36:25 PDT 2015
Author: armin11
Date: 2015-06-12 00:36:25 -0700 (Fri, 12 Jun 2015)
New Revision: 9212
Modified:
trunk/mapbender/http/javascripts/mod_coordsLookup.php
trunk/mapbender/http/javascripts/mod_coords_div.php
Log:
New option to show and look for international mapcodes
Modified: trunk/mapbender/http/javascripts/mod_coordsLookup.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_coordsLookup.php 2015-06-12 07:35:40 UTC (rev 9211)
+++ trunk/mapbender/http/javascripts/mod_coordsLookup.php 2015-06-12 07:36:25 UTC (rev 9212)
@@ -7,7 +7,7 @@
* the coordinate tuple to the current SRS and zooms to the location.
*
* Files:
- * - http/javascripts/mod_coordsLookup.js
+ * - http/javascripts/mod_coordsLookup.php
* - http/php/mod_coordsLookup_server.php
*
* SQL:
@@ -39,6 +39,7 @@
* Parameters:
* perimeters - Array of perimeters in m, like [50,200,1000,10000]
* projections - Array of EPSG names, like ['EPSG:31467','EPSG:31468']
+ * useMapcode - Boolean - option to search for mapcodes (http://www.mapcode.com)
*
* License:
* Copyright (c) 2009, Open Source Geospatial Foundation
@@ -83,16 +84,32 @@
typeof options.perimeters === 'undefined' || options.perimeters.length === 0
) {
}
+ if (typeof options.useMapcode === 'undefined' || options.useMapcode == false) {
+ options.useMapcode == false;
+ } else {
+ options.useMapcode == true;
+ }
this.buildForm = function() {
// Container elements
this.formContainer = $(document.createElement('form')).attr({'id':'coords-lookup-form'}).appendTo('#' + options.id);
- this.coordsInputContainer = $(document.createElement('p')).appendTo(this.formContainer);
- this.projectionSelectContainer = $(document.createElement('p')).appendTo(this.formContainer);
+ this.searchSwitchContainer = $(document.createElement('p')).attr({'id':'searchswitchcontainer'}).appendTo(this.formContainer);
+ this.coordsInputContainer = $(document.createElement('p')).attr({'id':'coordsinputcontainer'}).appendTo(this.formContainer);
+ this.projectionSelectContainer = $(document.createElement('p')).attr({'id':'projectionselectcontainer'}).appendTo(this.formContainer);
+ this.mapcodeContainer = $(document.createElement('p')).attr({'id':'mapcodecontainer'}).appendTo(this.formContainer);
this.perimeterSelectContainer = $(document.createElement('p')).appendTo(this.formContainer);
this.triggerButtonContainer = $(document.createElement('p')).appendTo(this.formContainer);
+
+ //check if searchSwitchContainer
+ if (options.useMapcode) {
+ //show searchSwitcher
+ this.searchRadioButton = this.searchSwitchContainer.append('<label><input type="radio" id="coords" name="searchswitcher" value="coords" /><?php echo _mb("Coordinates");?></label><label><input type="radio" id="mapcode" name="searchswitcher" value="mapcode" /><?php echo _mb("Mapcode");?><a target="_blank" href="http://www.mapcode.com"><img src="../img/help.png"></a></label>');
+ }
+ //enable coords by default
+
+ $('#coords').attr("checked", "checked");
+
// Coordinates input with label
-
this.coordsInputLabel = $(document.createElement('label')).attr({'for':'coord-x'}).text('<?php echo _mb("east / longitude");?>: ').appendTo(this.coordsInputContainer);
$(this.coordsInputLabel).after($(document.createElement('br')));
this.coordXInput = $(document.createElement('input')).attr({'id':'coord-x','size':18 }).appendTo(this.coordsInputContainer);
@@ -102,9 +119,9 @@
$(this.coordsInputLabel).after($(document.createElement('br')));
this.coordYInput = $(document.createElement('input')).attr({'id':'coord-y','size':18}).appendTo(this.coordsInputContainer);
$(this.coordYInput).after($(document.createElement('br')));
+ this.mapcodeInputLabel = $(document.createElement('label')).attr({'for':'coord-x'}).text('<?php echo _mb("Global Mapcode");?>: ').appendTo(this.mapcodeContainer);
+ this.mapcodeInput = $(document.createElement('input')).attr({'id':'mapcodeinput','size':18 }).appendTo(this.mapcodeContainer);
-
-
// $(this.coordXInput).after(' ');
// $(this.coordYInput).after(' ');
@@ -137,7 +154,21 @@
$(this.perimeterSelect).append('<option value=' + optionValue + ' >' + optionValue + '</option>');
}
$(this.perimeterSelect).prepend('<option value="Umkreis" ><?php echo _mb("Perimeter: ");?></option>');
-
+ //default
+ $("#mapcodecontainer").hide();
+
+ $('input:radio[name="searchswitcher"]').change(function() {
+ if ($(this).val() == 'coords') {
+ //show this.coordsInputContainer, this.projectionSelectContainer
+ $("#coordsinputcontainer").show();
+ $("#projectionselectcontainer").show();
+ $("#mapcodecontainer").hide();
+ } else {
+ $("#coordsinputcontainer").hide();
+ $("#projectionselectcontainer").hide();
+ $("#mapcodecontainer").show();
+ }
+ });
// Set action for trigger button
$(this.triggerButton).click(function() {
Mapbender.modules[options.id].zoomToCoordinates();
@@ -153,50 +184,77 @@
}
this.zoomToCoordinates = function() {
- this.coords = {};
-
- this.coords.x = this.coordXInput.val().replace(',','.');
- this.coords.y = this.coordYInput.val().replace(',','.');
- //check if deg/minutes/seconds have been inserted
- //validate
- this.regexdms = /([0-9.]+)\°([0-9.]+)\'([0-9.]+)\'\'/;
+ //switch coords / mapcode
+ activatedRadioButton = $("input[name='searchswitcher']:checked").val();
+ if (activatedRadioButton == "coords") {
+ this.coords = {};
+ this.coords.x = this.coordXInput.val().replace(',','.');
+ this.coords.y = this.coordYInput.val().replace(',','.');
+ //check if deg/minutes/seconds have been inserted
+ //validate
+ this.regexdms = /([0-9.]+)\°([0-9.]+)\'([0-9.]+)\'\'/;
+ this.coords.sourceProjection = (this.projectionSelect.val()) ?
+ this.projectionSelect.val() : null;
+ this.coords.targetProjection = Mapbender.modules[options.target].getSRS();
+ this.coords.perimeter = (this.perimeterSelect.val()) ?
+ parseFloat(this.perimeterSelect.val()) : null;
+ //validate coordinates
+ if(this.coords.x.length === 0 || isNaN(this.coords.x)) {
+ this.regexdms.exec(this.coords.x);
+ //alert(RegExp.$1 + ";" + RegExp.$2 + ";" + RegExp.$3);
+ if (isNaN(parseFloat(RegExp.$1)) || isNaN(parseFloat(RegExp.$2)) || isNaN(parseFloat(RegExp.$3)))
+ {
+ alert('<?php echo _mb("Invalid X coordinate! Must be a float or a DMS value!");?>');
+ return;
+ } else {
+ this.coords.x = parseFloat(RegExp.$1) + parseFloat(RegExp.$2) / 60.0 + parseFloat(RegExp.$3) / 3600.0;
+ //alert('this.coords.x');
+ }
+ }
+ if(this.coords.y.length === 0 || isNaN(this.coords.y)) {
+ this.regexdms.exec(this.coords.y);
+ //alert(RegExp.$1 + ";" + RegExp.$2 + ";" + RegExp.$3);
+ if (isNaN(parseFloat(RegExp.$1)) || isNaN(parseFloat(RegExp.$2)) || isNaN(parseFloat(RegExp.$3)))
+ {
+ alert('<?php echo _mb("Invalid Y coordinate! Must be a float or a DMS value!");?>');
+ return;
+ } else {
+ this.coords.y = parseFloat(RegExp.$1) + parseFloat(RegExp.$2 / 60.0) + parseFloat(RegExp.$3 / 3600.0);
+ //alert('this.coords.y');
+ }
+ }
- this.coords.sourceProjection = (this.projectionSelect.val()) ?
- this.projectionSelect.val() : null;
- this.coords.targetProjection = Mapbender.modules[options.target].getSRS();
- this.coords.perimeter = (this.perimeterSelect.val()) ?
- parseFloat(this.perimeterSelect.val()) : null;
- //validate coordinates
- if(this.coords.x.length === 0 || isNaN(this.coords.x)) {
- this.regexdms.exec(this.coords.x);
- //alert(RegExp.$1 + ";" + RegExp.$2 + ";" + RegExp.$3);
- if (isNaN(parseFloat(RegExp.$1)) || isNaN(parseFloat(RegExp.$2)) || isNaN(parseFloat(RegExp.$3)))
- {
- alert('<?php echo _mb("Invalid X coordinate! Must be a float or a DMS value!");?>');
+ if (this.coords.sourceProjection === null) {
+ alert('<?php echo _mb("Invalid SRS!");?>');
return;
- } else {
- this.coords.x = parseFloat(RegExp.$1) + parseFloat(RegExp.$2) / 60.0 + parseFloat(RegExp.$3) / 3600.0;
- //alert('this.coords.x');
}
- }
- if(this.coords.y.length === 0 || isNaN(this.coords.y)) {
- this.regexdms.exec(this.coords.y);
- //alert(RegExp.$1 + ";" + RegExp.$2 + ";" + RegExp.$3);
- if (isNaN(parseFloat(RegExp.$1)) || isNaN(parseFloat(RegExp.$2)) || isNaN(parseFloat(RegExp.$3)))
- {
- alert('<?php echo _mb("Invalid Y coordinate! Must be a float or a DMS value!");?>');
+ } else {
+ this.coords = {};
+ this.coords.targetProjection = Mapbender.modules[options.target].getSRS();
+ this.coords.perimeter = (this.perimeterSelect.val()) ?
+ parseFloat(this.perimeterSelect.val()) : null;
+ isMapcode = this.mapcodeInput.val().toUpperCase().match(/[A-Z0-9]{2,5}\.[A-Z0-9]{2,4}/g);
+ if (!isMapcode) {
+ alert('<?php echo _mb("No valid global mapcode!");?>');
return;
+ }
+ //results from mapcode
+ //validate input
+ //get coords
+ var coordsMapcode = master_decode(this.mapcodeInput.val().toUpperCase(), 'AAA');
+ if (!coordsMapcode) {
+ alert('<?php echo _mb("No position for given mapcode!");?>');
+ return;
} else {
- this.coords.y = parseFloat(RegExp.$1) + parseFloat(RegExp.$2 / 60.0) + parseFloat(RegExp.$3 / 3600.0);
- //alert('this.coords.y');
+ this.coords.x = coordsMapcode.x;
+ this.coords.y = coordsMapcode.y;
+ this.coords.sourceProjection = 'EPSG:4326'
}
+
+ //set projection
+
}
-
- if (this.coords.sourceProjection === null) {
- alert('<?php echo _mb("Invalid SRS!");?>');
- return;
- }
-
+ //alert(this.coords.x+" - "+this.coords.y);
//if(this.coords.sourceProjection && (this.coords.sourceProjection != this.coords.targetProjection)) {
if(this.coords.sourceProjection) {
this.transformProjection();
Modified: trunk/mapbender/http/javascripts/mod_coords_div.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_coords_div.php 2015-06-12 07:35:40 UTC (rev 9211)
+++ trunk/mapbender/http/javascripts/mod_coords_div.php 2015-06-12 07:36:25 UTC (rev 9212)
@@ -33,6 +33,15 @@
var mod_showCoords_div_fix = "";
var mod_showCoords_div_mapObj = null;
+var clickx;
+var clicky;
+
+/*if (typeof options.useMapcode === 'undefined' || options.useMapcode == false) {
+ options.useMapcode == false;
+} else {
+ options.useMapcode == true;
+}*/
+
function init_mod_showCoords_div(ind){
mod_showCoords_div_mapObj = getMapObjByName(mod_showCoords_div_target );
@@ -66,10 +75,14 @@
}
var pos = mod_showCoords_div_mapObj.convertPixelToReal(click);
mod_showCoords_div_fix = "<?php echo _mb('Selection'); ?>: " + pos.x + " / " + pos.y;
+
if (mod_showCoords_div_mapObj.epsg =='EPSG:4326' || mod_showCoords_div_mapObj.epsg=="EPSG:4258") {
strDMS = dec2dms(pos.x) + " / " + dec2dms(pos.y);
mod_showCoords_div_fix += " <br> " + strDMS;
}
+ clickx = pos.x;
+ clicky = pos.y;
+ clickcrs = mod_showCoords_div_mapObj.epsg;
mod_showCoord_write(pos.x,pos.y);
}
function mod_showCoords_div_display(e){
@@ -91,12 +104,49 @@
}
function dec2dms(x) {
- xD = Math.floor(x); //full deegrees
- xM = (x-xD) * 60; //decimal minutes
- xS = (xM-Math.floor(xM)) * 60;//decimal seconds
- return xD + "°" + Math.floor(xM) + "'" + round(xS,3) + "''";
+ xD = Math.floor(x); //full deegrees
+ xM = (x-xD) * 60; //decimal minutes
+ xS = (xM-Math.floor(xM)) * 60;//decimal seconds
+ return xD + "°" + Math.floor(xM) + "'" + round(xS,3) + "''";
}
+function getMapcode(x,y) {
+ this.transformProjection = function() {
+ var parameters = {
+ fromSrs: clickcrs,
+ toSrs: "EPSG:4326"
+ };
+ parameters.x = x;
+ parameters.y = y;
+ var req = new Mapbender.Ajax.Request({
+ url: "../php/mod_coordsLookup_server.php",
+ method: "transform",
+ async: false,
+ parameters: parameters,
+ callback: function (obj, success, message) {
+ if (!success) {
+ new Mapbender.Exception(message);
+ return;
+ }
+ if (obj.points.length === 1) {
+ var point = new Point(
+ obj.points[0].x,
+ obj.points[0].y
+ );
+ //call mapcode
+ var results = master_encode(point.y, point.x, 'AAA');
+ for (var i = 0; i < results.length; i++) {
+ //$('.selectedcoords').append('<p>Mapcode '+results[i][0]+'</p>');
+ alert('International Mapcode: '+results[i][0]);
+ }
+ }
+ }
+ });
+ req.send();
+ //invoke transformation
+ }
+ this.transformProjection();
+}
function mod_showCoord_write(x,y){
if(document.getElementById(displayTarget)){
@@ -106,7 +156,12 @@
str += " <br> " + strDMS + "</div>";
}
if(mod_showCoords_div_fix != ""){
+ //extract coordinates from mod_showCoords_div_fix
+
str += "<div class='selectedcoords'>" + mod_showCoords_div_fix + "</div>";
+ if (useMapcode == "true") {
+ str += '<?php echo _mb('Get Mapcode for this selection'); ?><img src="../img/up-ilink.png" onclick="getMapcode('+clickx+','+clicky+');"><a target="_blank" href="http://www.mapcode.com"><img src="../img/help.png"></a>';
+ }
}
writeTag("",displayTarget, str);
}
More information about the Mapbender_commits
mailing list