diff --git a/LICENSE b/LICENSE index f53c283..8e675bc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Sebastian Pauli +Copyright (c) 2022-2023 Sebastian Pauli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/demo/lanis.html b/demo/lanis.html index 8ac4a97..61e14e9 100644 --- a/demo/lanis.html +++ b/demo/lanis.html @@ -104,7 +104,7 @@ { "folder": 2, "type": "WFS", "title": "Überschwemmungsgebiete WFS Test", "url": "http://213.139.159.34:80/geoserver/uesg/wfs?", "name": "uesg:uesg_gesetzlich", "outputFormat": "application/json" }, { "folder": 3, "type": "WMS", "title": "TopPlusOpen", "attribution": "BKG", "url": "https://sgx.geodatenzentrum.de/wms_topplus_open?", "name": "web", "active": false }, - { "folder": 3, "type": "OSM", "title": "Open Street Map", "attribution": "OSM", "active": true, "minZoom": 8, "maxZoom": 11 } + { "folder": 3, "type": "OSM", "title": "Open Street Map", "attribution": "OSM", "active": true, "minZoom": 1, "maxZoom": 20 } ], "folders": diff --git a/demo/ows.html b/demo/ows.html index 31d7a13..7a6ec6d 100644 --- a/demo/ows.html +++ b/demo/ows.html @@ -7,11 +7,11 @@ - NetGIS Client + OWS Demo | NetGIS Client - + @@ -19,6 +19,7 @@ + @@ -49,7 +50,14 @@ - + + + + + + + + @@ -66,6 +74,7 @@ + diff --git a/src/netgis/Attribution.js b/src/netgis/Attribution.js index ec73545..e99e650 100644 --- a/src/netgis/Attribution.js +++ b/src/netgis/Attribution.js @@ -26,6 +26,7 @@ netgis.Attribution.prototype.load = function() this.client.on( netgis.Events.CONTEXT_UPDATE, this.onContextUpdate.bind( this ) ); this.client.on( netgis.Events.LAYER_SHOW, this.onLayerShow.bind( this ) ); this.client.on( netgis.Events.LAYER_HIDE, this.onLayerHide.bind( this ) ); + this.client.on( netgis.Events.EDIT_FEATURES_CHANGE, this.onEditFeaturesChange.bind( this ) ); }; netgis.Attribution.prototype.update = function() @@ -83,4 +84,28 @@ netgis.Attribution.prototype.onLayerHide = function( e ) } this.update(); +}; + +netgis.Attribution.prototype.onEditFeaturesChange = function( e ) +{ + // Update Area + var areaLabel = "Zeichnungsfläche: "; + + for ( var i = 0; i < this.items.length; i++ ) + { + var item = this.items[ i ]; + + if ( item.search( areaLabel ) > -1 ) + { + this.items.splice( i, 1 ); + break; + } + } + + if ( e.area && e.area > 0.0 ) + { + var areaItem = areaLabel + netgis.util.formatArea( e.area, true ); + this.items.push( areaItem ); + this.update(); + } }; \ No newline at end of file diff --git a/src/netgis/Util.js b/src/netgis/Util.js index b16eb2d..4d7f95a 100644 --- a/src/netgis/Util.js +++ b/src/netgis/Util.js @@ -153,27 +153,42 @@ netgis.util = return timestamp; }; + /** + * @returns {String} The users language locale string (defaults to German) + */ + var getUserLanguage = function() + { + var lang = navigator.language || "de-DE"; + + return lang; + }; + /* * @param {Number} area Raw Area in Square Meters * @param {Boolean} decimals Output Rounded Decimals + * @param {Number} threshold Threshold for normal (square meters) vs. large (square kilometers) values + * @param {Boolean} seperate Use thousands seperators * @returns {String} Formatted Area String (Square Meters/Square Kilometers) */ - var formatArea = function( area, decimals ) + var formatArea = function( area, decimals, threshold, seperate ) { var output; // Normal / Large Value - var large = ( area > 10000 ); + threshold = threshold || 100000; + var large = ( area > threshold ); // Round Value var i = 0; if ( large ) { + var METERS_PER_KILOMETER = 1000000; + if ( decimals ) - i = Math.round( area / 1000000 * 1000 ) / 1000; + i = Math.round( area / METERS_PER_KILOMETER * 1000 ) / 1000; else - i = Math.round( area / 1000000 ); + i = Math.round( area / METERS_PER_KILOMETER ); } else { @@ -185,10 +200,14 @@ netgis.util = if ( i === 0 ) large = false; - // Build String - output = i + ( large ? " qkm" : " qm" ); + // Thousands Seperators + seperate = seperate || true; + if ( seperate ) i = i.toLocaleString( getUserLanguage() ); - //NOTE: HTML Superscript / Unicode (² etc.) not supported in OL Labels + // Build String + output = i + ( large ? " km²" : " m²" ); + + // NOTE: HTML Superscript / Unicode (² etc.) not supported in OL Labels return output; }; @@ -208,6 +227,7 @@ netgis.util = padstr: padstr, merge: merge, getTimeStamp: getTimeStamp, + getUserLanguage: getUserLanguage, formatArea: formatArea };