aboutsummaryrefslogtreecommitdiffstats
path: root/view/theme/diabook/js/jquery.mapquery.legend.js
diff options
context:
space:
mode:
authorMichael Vogel <icarus@dabo.de>2012-05-16 08:24:46 +0200
committerMichael Vogel <icarus@dabo.de>2012-05-16 08:24:46 +0200
commitf2c0c40f6e488f1a8e62bda9449b28115f343cac (patch)
treeae1418141f85be49b7d8cb3d2a0e8b2a7acc4eb4 /view/theme/diabook/js/jquery.mapquery.legend.js
parentf2e648d62fe7cafb9a55c7505687ea4d1c294778 (diff)
parenta65bd73bf3f4a1e6ccfcdf0a06c70a4f1f4182ce (diff)
downloadvolse-hubzilla-f2c0c40f6e488f1a8e62bda9449b28115f343cac.tar.gz
volse-hubzilla-f2c0c40f6e488f1a8e62bda9449b28115f343cac.tar.bz2
volse-hubzilla-f2c0c40f6e488f1a8e62bda9449b28115f343cac.zip
Merge remote branch 'upstream/master'
Diffstat (limited to 'view/theme/diabook/js/jquery.mapquery.legend.js')
-rw-r--r--view/theme/diabook/js/jquery.mapquery.legend.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/view/theme/diabook/js/jquery.mapquery.legend.js b/view/theme/diabook/js/jquery.mapquery.legend.js
new file mode 100644
index 000000000..0a475408f
--- /dev/null
+++ b/view/theme/diabook/js/jquery.mapquery.legend.js
@@ -0,0 +1,87 @@
+/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
+ * full list of contributors). Published under the MIT license.
+ * See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
+ * full text of the license. */
+
+/**
+#jquery.mapquery.legend.js
+A plugin on mapquery.core to add a legend to a layer. It will check if the layer
+is within a valid extent and zoom range. And if not will return an error message.
+*/
+
+(function($, MQ) {
+$.extend( $.fn.mapQuery.defaults.layer.all, {
+ legend: {
+ url: '',
+ msg: ''
+ }
+});
+//possible error messages to display in the legend
+LEGEND_ERRORS= ['E_ZOOMOUT', 'E_ZOOMIN', 'E_OUTSIDEBOX'];
+$.extend(MQ.Layer.prototype, {
+/**
+###**layer**.`legend([options])`
+_version added 0.1_
+####**Description**: get/set the legend of a layer
+
+**options** url:url the url to the legend image
+
+>Returns: {url:url, msg:'E\_ZOOMOUT' | 'E\_ZOOMIN' | 'E\_OUTSIDEBOX' | ''}
+
+
+The `.legend()` function allows us to attach a legend image to a layer. It will
+also check if the layer is not visible due to wrong extent or zoom level.
+It will return an error message which can be used to notify the user.
+
+
+ var legend = layer.legend(); //get the current legend
+ //set the legend url to legendimage.png
+ layer.legend({url:'legendimage.png'})
+
+ */
+ //get/set the legend object
+ legend: function(options) {
+ //get the legend object
+ var center = this.map.center();
+ if (arguments.length===0) {
+ this._checkZoom(center);
+ //if zoom = ok, check box
+ if(this.options.legend.msg==''){
+ this._checkBox(center);
+ }
+ return this.options.legend;
+ }
+ //set the legend url
+ if (options.url!==undefined) {
+ this.options.legend.url = options.url;
+ return this.options.legend;
+ }
+ },
+ //Check if the layer has a maximum box set and if the current box
+ //is outside these settings, set the legend.msg accordingly
+ _checkBox: function(center){
+ var maxExtent = this.options.maxExtent;
+ if(maxExtent!==undefined) {
+ var mapBounds = new OpenLayers.Bounds(
+ center.box[0],center.box[1],center.box[2],center.box[3]);
+ var layerBounds = new OpenLayers.Bounds(
+ maxExtent[0],maxExtent[1],maxExtent[2],maxExtent[3]);
+ var inside = layerBounds.containsBounds(mapBounds, true);
+ this.options.legend.msg = inside?'':LEGEND_ERRORS[2];
+ }
+ },
+ //Check if the layer has a minimum or maximum zoom set and if the
+ //current zoom is outside these settings, set the legend.msg accordingly
+ _checkZoom: function(center){
+ var zoom = center.zoom;
+ var maxZoom = this.options.maxZoom;
+ var minZoom = this.options.minZoom;
+ this.options.legend.msg=(
+ maxZoom!==undefined&&maxZoom<zoom)? LEGEND_ERRORS[0]:'';
+ this.options.legend.msg=(
+ minZoom!==undefined&&minZoom>zoom)? LEGEND_ERRORS[1]:'';
+ }
+
+});
+
+})(jQuery, $.MapQuery);