[Mapbender-commits] r6125 - branches/3_dev/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Sun May 9 12:49:37 EDT 2010
Author: astrid_emde
Date: 2010-05-09 12:49:36 -0400 (Sun, 09 May 2010)
New Revision: 6125
Added:
branches/3_dev/http/plugins/mod_box1.js
branches/3_dev/http/plugins/mod_pan.js
branches/3_dev/http/plugins/mod_selArea.js
branches/3_dev/http/plugins/mod_zoomIn1.js
branches/3_dev/http/plugins/mod_zoomOut1.js
Log:
navigation modules
Added: branches/3_dev/http/plugins/mod_box1.js
===================================================================
--- branches/3_dev/http/plugins/mod_box1.js (rev 0)
+++ branches/3_dev/http/plugins/mod_box1.js 2010-05-09 16:49:36 UTC (rev 6125)
@@ -0,0 +1,231 @@
+/*
+ * 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
+ */
+
+Mapbender.Box = function (options) {
+ var map = (typeof options.target !== "undefined") ?
+ getMapObjByName(options.target) : null;
+
+ var color = (typeof options.color !== "undefined") ?
+ options.color : "#ff0000";
+
+ var isActive = false;
+ var top = 0;
+ var topSuffix = "_l_top";
+ var topNode;
+ var left = 0;
+ var leftSuffix = "_l_left";
+ var leftNode;
+ var bottom = 0;
+ var bottomSuffix = "_l_bottom";
+ var bottomNode;
+ var right = 0;
+ var rightSuffix = "_l_right";
+ var rightNode;
+
+ var startPos = null;
+ var stopPos = null;
+
+ var exists = false;
+ var that = this;
+
+ this.start = function (e) {
+ if (!map) {
+ return;
+ }
+ $(map.getDomElement()).mousemove(function (e) {
+ that.run(e);
+ return false;
+ });
+
+ isActive = true;
+ var click = map.getMousePosition(e);
+ startPos = new Point(click.x, click.y);
+ stopPos = new Point(click.x, click.y);
+ top = click.y;
+ left = click.y;
+ bottom = click.y;
+ right = click.x;
+
+ };
+
+ this.run = function (e) {
+ var pos = map.getMousePosition(e);
+ if (pos !== null) {
+ stopPos = pos;
+ var width = map.width;
+ var height = map.height;
+
+ if (startPos.x > stopPos.x) {
+ right = startPos.x;
+ left = stopPos.x;
+ }
+ else {
+ left = startPos.x;
+ right = stopPos.x;
+ }
+ if (startPos.y > stopPos.y) {
+ bottom = startPos.y;
+ top = stopPos.y;
+ }
+ else {
+ top = startPos.y;
+ bottom = stopPos.y;
+ }
+
+ if (!startPos.equals(stopPos)) {
+ this.draw();
+ }
+ }
+ return true;
+ };
+
+ this.stop = function (e, callback) {
+ $(map.getDomElement()).unbind("mousemove");
+
+ hideElement(topNode);
+ hideElement(leftNode);
+ hideElement(rightNode);
+ hideElement(bottomNode);
+
+
+ if (isActive) {
+ isActive = false;
+ if (typeof callback === "function") {
+ return callback(getExtent());
+ }
+ return getExtent();
+ }
+ isActive = false;
+ };
+
+ var arrangeBox = function (node, left, top, right, bottom) {
+ var el = node.style;
+ el.height = Math.abs(bottom - top);
+ el.width = Math.abs(right - left);
+ el.top = top + "px";
+ el.left = left + "px";
+ };
+
+ var displayElement = function (node) {
+ node.style.visibility = "visible";
+ };
+
+ var hideElement = function (node) {
+ node.style.visibility = "hidden";
+ };
+
+ var domElementsExist = function () {
+ if (!map) {
+ return;
+ }
+ return map.getDomElement(
+ ).ownerDocument.getElementById(
+ map.elementName + topSuffix
+ ) !== null;
+ };
+
+ var createDomElements = function () {
+ if (!map) {
+ return;
+ }
+ var map_el = map.getDomElement();
+ topNode = map_el.ownerDocument.createElement("div");
+ topNode.style.position = "absolute";
+ topNode.style.top = "0px";
+ topNode.style.left = "0px";
+ topNode.style.width = "0px";
+ topNode.style.height = "0px";
+ topNode.style.overflow = "hidden";
+// topNode.style.zIndex = parseInt(map_el.style.zIndex, 10) + 1;
+ topNode.style.zIndex = 100;
+ topNode.style.visibility = "visible";
+ topNode.style.cursor = "crosshair";
+ topNode.style.backgroundColor = color;
+
+ leftNode = topNode.cloneNode(false);
+ rightNode = topNode.cloneNode(false);
+ bottomNode = topNode.cloneNode(false);
+
+ topNode.id = map.elementName + topSuffix;
+ leftNode.id = map.elementName + leftSuffix;
+ rightNode.id = map.elementName + rightSuffix;
+ bottomNode.id = map.elementName + bottomSuffix;
+
+ map_el.appendChild(topNode);
+ map_el.appendChild(leftNode);
+ map_el.appendChild(rightNode);
+ map_el.appendChild(bottomNode);
+
+ exists = true;
+ };
+
+ this.draw = function (extent) {
+ if (!map) {
+ return;
+ }
+ if (typeof extent === "object"
+ && extent.constructor === Mapbender.Extent) {
+
+ left = extent.min.x;
+ right = extent.max.x;
+ bottom = extent.min.y;
+ top = extent.max.y;
+ }
+
+ arrangeBox(topNode, left, top, right, top + 2);
+ arrangeBox(leftNode, left, top, left + 2, bottom);
+ arrangeBox(rightNode, right - 2, top, right, bottom);
+ arrangeBox(bottomNode, left, bottom - 2, right, bottom);
+ displayElement(topNode);
+ displayElement(leftNode);
+ displayElement(rightNode);
+ displayElement(bottomNode);
+ };
+
+ var getExtent = function () {
+ if (!map) {
+ return null;
+ }
+ var x1 = startPos.x;
+ var x2 = stopPos.x;
+ var y1 = startPos.y;
+ var y2 = stopPos.y;
+
+ var minx = x2;
+ var maxx = x1;
+ if(x1 < x2){
+ minx = x1;
+ maxx = x2;
+ }
+
+ var miny = y1;
+ var maxy = y2;
+ if(y1 < y2){
+ miny = y2;
+ maxy = y1;
+ }
+
+ // area or clickpoint ?
+ var posMin = map.convertPixelToReal(new Point(minx,miny));
+ if((maxx - minx) > 3 && (miny - maxy) > 3){
+ var posMax = map.convertPixelToReal(new Point(maxx,maxy));
+ return new Mapbender.Extent(posMin, posMax);
+ }
+ return posMin;
+ };
+
+ if (!domElementsExist()) {
+ createDomElements();
+ }
+ else {
+ topNode = document.getElementById(map.elementName + topSuffix);
+ leftNode = document.getElementById(map.elementName + leftSuffix);
+ rightNode = document.getElementById(map.elementName + rightSuffix);
+ bottomNode = document.getElementById(map.elementName + bottomSuffix);
+ }
+};
Added: branches/3_dev/http/plugins/mod_pan.js
===================================================================
--- branches/3_dev/http/plugins/mod_pan.js (rev 0)
+++ branches/3_dev/http/plugins/mod_pan.js 2010-05-09 16:49:36 UTC (rev 6125)
@@ -0,0 +1,98 @@
+/**
+ * Package: selArea
+ *
+ * Description:
+ * Zoom by rectangle
+ *
+ * Files:
+ * - http/javascripts/mod_selArea.js
+ *
+ * SQL:
+ * > <SQL for element>
+ * >
+ * > <SQL for element var>
+ *
+ * Help:
+ * http://www.mapbender.org/SelArea1
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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
+ */
+
+var that = this;
+
+Mapbender.events.init.register(function () {
+
+ var mb_panActive = false;
+ var startPos, stopPos;
+ var map = Mapbender.modules[options.target];
+
+ var button = new Mapbender.Button({
+ domElement: that,
+ over: options.src.replace(/_off/, "_over"),
+ on: options.src.replace(/_off/, "_on"),
+ off: options.src,
+ name: options.id,
+ go: function () {
+ if (!map) {
+ new Mb_exception(options.id + ": " +
+ options.target + " is not a map!");
+ return;
+ }
+ $(map.getDomElement())
+ .css("cursor", "move")
+ .mousedown(function (e) {
+ mb_panActive = true;
+ startPos = map.getMousePosition(e);
+ stopPos = new Mapbender.Point(startPos);
+ return false;
+ }).mousemove(function (e) {
+ if (!mb_panActive) {
+ return false;
+ }
+ stopPos = map.getMousePosition(e);
+ var dif = stopPos.minus(startPos);
+ map.moveMap(dif.x, dif.y);
+ if (!$.browser.msie){
+ return true;
+ }
+ return false;
+ }).mouseup(function (e) {
+ if (!mb_panActive) {
+ return false;
+ }
+ if (!map) {
+ return false;
+ }
+ mb_panActive = false;
+ var dif = stopPos.minus(startPos);
+ var widthHeight = new Mapbender.Point(
+ map.getWidth(),
+ map.getHeight()
+ );
+ var center = widthHeight.times(0.5).minus(dif);
+ var realCenter = map.convertPixelToReal(center);
+ map.moveMap();
+ map.zoom(false, 1.0, realCenter);
+ return false;
+ });
+ },
+ stop: function () {
+ if (!map) {
+ return false;
+ }
+ $(map.getDomElement())
+ .css("cursor", "default")
+ .unbind("mousedown")
+ .unbind("mouseup")
+ .unbind("mousemove");
+ mb_panActive = false;
+ }
+ });
+});
Added: branches/3_dev/http/plugins/mod_selArea.js
===================================================================
--- branches/3_dev/http/plugins/mod_selArea.js (rev 0)
+++ branches/3_dev/http/plugins/mod_selArea.js 2010-05-09 16:49:36 UTC (rev 6125)
@@ -0,0 +1,85 @@
+/**
+ * Package: selArea
+ *
+ * Description:
+ * Zoom by rectangle
+ *
+ * Files:
+ * - http/javascripts/mod_selArea.js
+ *
+ * SQL:
+ * > <SQL for element>
+ * >
+ * > <SQL for element var>
+ *
+ * Help:
+ * http://www.mapbender.org/SelArea1
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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
+ */
+
+var that = this;
+
+Mapbender.events.init.register(function () {
+
+ var box;
+ var map = Mapbender.modules[options.target];
+
+ var button = new Mapbender.Button({
+ domElement: that,
+ over: options.src.replace(/_off/, "_over"),
+ on: options.src.replace(/_off/, "_on"),
+ off: options.src,
+ name: options.id,
+ go: function () {
+ if (!map) {
+ new Mb_exception(options.id + ": " +
+ options.target + " is not a map!");
+ return;
+ }
+
+ box = new Mapbender.Box({
+ target: options.target
+ });
+ $(map.getDomElement()).css(
+ "cursor", "crosshair"
+ ).mousedown(function (e) {
+ box.start(e);
+ return false;
+ }).mouseup(function (e) {
+ box.stop(e, function (extent) {
+ if (typeof extent === "undefined") {
+ return false;
+ }
+ if (extent.constructor === Mapbender.Extent) {
+ var xt = map.calculateExtent(extent);
+ map.setMapRequest();
+ }
+ else if (extent.constructor === Mapbender.Point) {
+ map.setCenter(extent);
+ map.setMapRequest();
+ }
+ });
+ return false;
+ });
+ },
+ stop: function () {
+ if (!map) {
+ return;
+ }
+ $(map.getDomElement())
+ .css("cursor", "default")
+ .unbind("mousedown")
+ .unbind("mouseup")
+ .unbind("mousemove");
+ box = null;
+ }
+ });
+});
\ No newline at end of file
Added: branches/3_dev/http/plugins/mod_zoomIn1.js
===================================================================
--- branches/3_dev/http/plugins/mod_zoomIn1.js (rev 0)
+++ branches/3_dev/http/plugins/mod_zoomIn1.js 2010-05-09 16:49:36 UTC (rev 6125)
@@ -0,0 +1,44 @@
+/**
+ * Package: ZoomIn1
+ *
+ * Description:
+ * Click button, which minimizes the real world bounding box of the visible map section, doubles the scale (halfes the scale number). Image size is not affected.
+ *
+ * Files:
+ * - http/javascripts/mod_zoomIn1.js
+ *
+ * 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('gui', 'zoomIn1', 2, 1, 'zoomIn button','Zoom in',
+ * > 'img','../img/button_gray/zoomIn2_off.png','',220,10,24,24,1,
+ * > '','','','mod_zoomIn1.js','','mapframe1','',
+ * > 'http://www.mapbender.org/index.php/ZoomIn');
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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
+ */
+$(this).click(function () {
+ if (!options.target
+ || !Mapbender.modules[options.target]
+ || typeof Mapbender.modules[options.target].zoom !== "function") {
+ return;
+ }
+ Mapbender.modules[options.target].zoom(true, 2.0);
+}).mouseover(function () {
+ if (options.src) {
+ this.src = options.src.replace(/_off/, "_over");
+ }
+}).mouseout(function () {
+ if (options.src) {
+ this.src = options.src;
+ }
+});
\ No newline at end of file
Added: branches/3_dev/http/plugins/mod_zoomOut1.js
===================================================================
--- branches/3_dev/http/plugins/mod_zoomOut1.js (rev 0)
+++ branches/3_dev/http/plugins/mod_zoomOut1.js 2010-05-09 16:49:36 UTC (rev 6125)
@@ -0,0 +1,48 @@
+/**
+ * Package: ZoomOut1
+ *
+ * Description:
+ * Click button, which doubles the real world bounding box of the visible
+ * map section, halfes the scale (doubles the scale number). Image size
+ * is not affected.
+ *
+ * Files:
+ * - http/javascripts/mod_zoomOut1.js
+ *
+ * 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>','zoomOut1',
+ * > 2,1,'zoomOut button','Zoom out','img',
+ * > '../img/button_gray/zoomOut2_off.png','',245,10,24,24,1,'','','',
+ * > 'mod_zoomOut1.js','','mapframe1','',
+ * > 'http://www.mapbender.org/index.php/ZoomOut');
+ *
+ * Help:
+ * http://www.mapbender.org/ZoomOut
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * 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
+ */
+$(this).click(function () {
+ if (!options.target
+ || !Mapbender.modules[options.target]) {
+ return;
+ }
+ Mapbender.modules[options.target].zoom(false, 2.0);
+}).mouseover(function () {
+ if (options.src) {
+ this.src = options.src.replace(/_off/, "_over");
+ }
+}).mouseout(function () {
+ if (options.src) {
+ this.src = options.src;
+ }
+});
\ No newline at end of file
More information about the Mapbender_commits
mailing list