[Mapbender-commits] r2224 - branches/2.5/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Mar 13 05:53:49 EDT 2008
Author: verenadiewald
Date: 2008-03-13 05:53:48 -0400 (Thu, 13 Mar 2008)
New Revision: 2224
Added:
branches/2.5/http/javascripts/requestGeometryConstructor.js
Log:
new file for creating geometries for spatial request
Added: branches/2.5/http/javascripts/requestGeometryConstructor.js
===================================================================
--- branches/2.5/http/javascripts/requestGeometryConstructor.js (rev 0)
+++ branches/2.5/http/javascripts/requestGeometryConstructor.js 2008-03-13 09:53:48 UTC (rev 2224)
@@ -0,0 +1,201 @@
+/*
+* $Id: requestGeometryConstructor.js 1882 2007-12-03 09:01:24Z verenadiewald $
+* COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
+* License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
+*/
+//http://www.mapbender.org/index.php/requestGeometryConstructor.js
+
+/**
+ * @class A class representing a constructor for a geometry/WFS request.
+ *
+ * @constructor
+ * @param {String} geomType type of the {@link RequestGeometryConstructor}
+ * @param {String} geomType target of the {@link RequestGeometryConstructor}
+ */
+ function RequestGeometryConstructor(geomTarget){
+ /**
+ * geomTarget target of the {@link RequestGeometryConstructor}
+ *
+ * @type String
+ */
+
+ this.geomTarget = geomTarget;
+
+ this.getGeometry = function(queryType,callbackFunction){
+ var target = this.geomTarget;
+ s = new Snapping(this.geomTarget);
+ callback = callbackFunction;
+
+ var el = window.frames[target].document;
+ el.onmouseover = null;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+
+ if (queryType == "point") {
+ queryGeom = new Geometry(geomType.point);
+ el.onmousedown = function (e) {
+ mb_getMousePos(e,target);
+ realWorldPos = mapToReal(target,new Point(clickX,clickY));
+ queryGeom.addPoint(realWorldPos);
+ callback(target, queryGeom);
+ el.onmouseover = null;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+ queryGeom = null;
+ };
+ }
+ else if (queryType == "polygon") {
+ queryGeom = new Geometry(geomType.polygon);
+ el.onmousedown = wfsSpatialRequestStart;
+ el.onmousemove = wfsSpatialRequestRun;
+ }
+ else if (queryType == "rectangle") {
+ queryGeom = new Geometry(geomType.line);
+ el.onmouseover = selAreaExtInit;
+ el.onmousedown = mod_box_start;
+ el.onmouseup = selAreaExtGet;
+ el.onmousemove = mod_box_run;
+ }
+ else if (queryType == "extent") {
+ queryGeom = new Geometry(geomType.line);
+ var ind = getMapObjIndexByName(target);
+ var p0 = mapToReal(target, new Point(0,0));
+ var p1 = mapToReal(target, new Point(mb_mapObj[ind].width,mb_mapObj[ind].height));
+ queryGeom.addPoint(p0);
+ queryGeom.addPoint(p1);
+ callback(target, queryGeom);
+ el.onmouseover = null;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+ queryGeom = null;
+ }
+
+ }
+
+ var s;
+ var callback;
+
+ var wfsSpatialRequestStart = function(e){
+ this.geomTarget = geomTarget;
+ var that = this;
+ var realWorldPos;
+ if (s.isSnapped() == true) {
+ realWorldPos = s.getSnappedPoint();
+ s.clean();
+ }
+ else {
+ mb_getMousePos(e,that.geomTarget);
+ realWorldPos = mapToReal(that.geomTarget,new Point(clickX,clickY));
+ }
+ queryGeom.addPoint(realWorldPos);
+
+ if (queryGeom.count() == 1) {
+ s.add(queryGeom.get(0));
+ }
+ if (s.isSnapped() && queryGeom.count() >= 3 && queryGeom.get(-1).equals(queryGeom.get(0))) {
+ queryGeom.close();
+ callback(that.geomTarget,queryGeom);
+ writeTag(that.geomTarget,"measuring","");
+ writeTag(that.geomTarget,"measure_display","");
+ var el = window.frames[that.geomTarget].document;
+ el.onmouseover = null;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+ queryGeom = null;
+ return;
+ }
+ drawDashedLineExt();
+ }
+
+ var wfsSpatialRequestRun = function(e){
+ this.geomTarget = geomTarget;
+ var that = this;
+ if (queryGeom.count() >= 3) {
+ mb_getMousePos(e,that.geomTarget);
+ var pos = new Point(clickX,clickY);
+ s.check(pos);
+ }
+ }
+
+ var drawDashedLineExt = function(e){
+ this.geomTarget = geomTarget;
+ var that = this;
+ var ind = getMapObjIndexByName(that.geomTarget);
+ var str_mPoints = "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='"+mb_mapObj[ind].width+"' height='0'></div>";
+ str_mPoints += "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='0' height='"+mb_mapObj[ind].height+"'></div>";
+ if (queryGeom != null) {
+ for(var i=0; i<queryGeom.count(); i++){
+ var pos = realToMap(that.geomTarget,queryGeom.get(i));
+ str_mPoints += "<div style='font-size:1px;position:absolute;top:"+(pos.y-2)+"px;left:"+(pos.x-2)+"px;width:3px;height:3px;background-color:#ff0000'></div>";
+ }
+ if(queryGeom.count()>1){
+ for(var k=1; k<queryGeom.count(); k++){
+ var pos0 = realToMap(that.geomTarget,queryGeom.get(k));
+ var pos1 = realToMap(that.geomTarget,queryGeom.get(k-1));
+ str_mPoints += evaluateDashesExt(pos1,pos0,k);
+ }
+ }
+ }
+ writeTag(that.geomTarget,"measuring",str_mPoints);
+ }
+
+ var evaluateDashesExt = function(p1,p0,count){
+ this.geomTarget = geomTarget;
+ var that = this;
+ var ind = getMapObjIndexByName(that.geomTarget);
+ var str_dashedLine = "";
+ var d = p0.dist(p1);
+ var n = Math.round(d);
+ var s = p0.minus(p1).dividedBy(n);
+ for(var i=1; i<n; i++){
+ var currPoint = p1.plus(s.times(i)).minus(new Point(2,2)).round(0);
+ if(currPoint.x >= 0 && currPoint.x <= mb_mapObj[ind].width && currPoint.y >= 0 && currPoint.y <= mb_mapObj[ind].height){
+ str_dashedLine += "<div style='font-size:1px;position:absolute;top:"+currPoint.y+"px;left:"+currPoint.x+"px;width:3px;height:3px;background-color:#ff0000'></div>";
+ }
+ }
+ return str_dashedLine;
+ }
+
+ var selAreaExtInit = function(e){
+ this.geomTarget = geomTarget;
+ var that = this;
+ mb_isBF = that.geomTarget;
+ mb_zF = that.geomTarget;
+ }
+
+ var selAreaExtGet = function(e){
+ this.geomTarget = geomTarget;
+ var that = this;
+ selAreaExtSetValidClipping(mod_box_stop(e));
+ mb_isBF = that.geomTarget;
+ mb_zF = that.geomTarget;
+ }
+
+ var selAreaExtSetValidClipping = function(coords){
+ this.geomTarget = geomTarget;
+ var that = this;
+ if (queryGeom != null) {
+ queryGeom.addPoint(new Point(coords[0],coords[1]));
+ queryGeom.addPoint(new Point(coords[2],coords[3]));
+
+ if(queryGeom.count() == 2){
+ callback(that.geomTarget,queryGeom);
+ var el = window.frames[that.geomTarget].document;
+ el.onmouseover = null;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+ queryGeom = null;
+ }
+ else{
+ callback(that.geomTarget,queryGeom);
+ }
+ }
+ }
+}
+
+
More information about the Mapbender_commits
mailing list