[Mapbender-commits] r3136 - branches/nimix_dev/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Oct 7 03:55:13 EDT 2008
Author: nimix
Date: 2008-10-07 03:55:13 -0400 (Tue, 07 Oct 2008)
New Revision: 3136
Modified:
branches/nimix_dev/http/javascripts/geometry.js
branches/nimix_dev/http/javascripts/mod_featureInfoTunnel.php
branches/nimix_dev/http/javascripts/mod_georss.php
branches/nimix_dev/http/javascripts/usemap.js
Log:
move linebuffering to geometry js
Modified: branches/nimix_dev/http/javascripts/geometry.js
===================================================================
--- branches/nimix_dev/http/javascripts/geometry.js 2008-10-07 07:47:52 UTC (rev 3135)
+++ branches/nimix_dev/http/javascripts/geometry.js 2008-10-07 07:55:13 UTC (rev 3136)
@@ -1049,6 +1049,111 @@
return true;
};
+/**
+ * creates a polygon geometry object which form a buffer around the line geometry
+ *
+ * @param {float} real world units to buffer around the line
+ * @param {float} (optional) units to buffer around the line in Y direction
+ *
+ * @return linebuffer polygon
+ * @type Geometry
+ */
+Geometry.prototype.bufferLine = function(bufferX, bufferY){
+ if(typeof(bufferY)=='undefined')
+ bufferY = bufferX;
+ if(this.geomType!=geomType.line || this.count()<2)
+ return false;
+
+ var ret = new Geometry(geomType.polygon)
+
+ //get vector from point 0 to point 1
+ last_vec = this.get(1).minus(this.get(0));
+
+ //get 90° rotated vector
+ last_vec_o = new Point(-last_vec.y, last_vec.x);
+
+ //resize vectors with apropriate linebuffer length
+ last_vec_o = last_vec_o.dividedBy(last_vec_o.dist(new Point(0,0)));
+ last_vec_o.x*=bufferX; last_vec_o.y*=bufferY;
+ last_vec = last_vec.dividedBy(last_vec.dist(new Point(0,0)));
+ last_vec.x*=bufferX; last_vec.y*=bufferY;
+
+ //add first pointsets
+ ret.list.unshift(this.get(0).plus(last_vec_o).minus(last_vec));
+ ret.list.push(this.get(0).minus(last_vec_o).minus(last_vec));
+
+ for(var i=1;i<this.count()-1;i++){
+ //get vector from point n to point n+1
+ vec = this.get(i+1).minus(this.get(i));
+ //get orthogonal (90° rotated) vector
+ vec_o = new Point(-vec.y, vec.x);
+
+ //resize vectors to linebuffer length
+ vec_o = vec_o.dividedBy(vec_o.dist(new Point(0,0)));
+ vec_o.x*=bufferX; vec_o.y*=bufferY;
+ vec = vec.dividedBy(vec.dist(new Point(0,0)));
+ vec.x*=bufferX; vec.y*=bufferY;
+
+ //if direction is the same continue
+ if(vec.equals(last_vec))
+ continue;
+
+ // calculate directed angle between the two vectors by
+ // calculating the argument diffenrences between complex numbers
+ // arg(x + i*y) (because law of cosine can onlycalculate undirected angle)
+ var angle = (Math.atan2(vec.x,vec.y)-Math.atan2(last_vec.x,last_vec.y))
+ //ensure that angle is -180<=angle<=180
+ if(angle<-Math.PI)angle=2*Math.PI+angle;
+ if(angle>+Math.PI)angle=2*Math.PI-angle;
+ console.log(angle);
+
+ //calculate the distance between the next points on boundary
+ //and the line point
+ //the point will be in the direction of angle/2 relative to last_vec_o
+ //since cosine is adjacent side / hypothenuse and we know that
+ //the adjacent side is lineBuffer the hypothenus (our distance) is
+ var ndist = 1/(Math.cos(angle/2))
+ //direction of next points on boundary
+ var int_vec = vec_o.plus(last_vec_o);
+ //resize direction vector to our distance
+ int_vec = int_vec.times(ndist/int_vec.dist(new Point(0,0)));
+ int_vec.x*=bufferX; int_vec.y*=bufferY;
+
+ //look if we have an outer sharp corner (>90°)
+ if(angle>Math.PI/2){
+ //push cutted edge points
+ ret.list.unshift(this.get(i).plus(last_vec_o).plus(last_vec));
+ ret.list.unshift(this.get(i).plus(vec_o).minus(vec));
+ }
+ else{
+ //push inner/light edge
+ ret.list.unshift(this.get(i).plus(int_vec));
+ }
+
+ //look if we have an inner sharp corner (<-90°)
+ if(angle<-Math.PI/2){
+ //push cutted edge points
+ ret.list.push(this.get(i).minus(last_vec_o).plus(last_vec));
+ ret.list.push(this.get(i).minus(vec_o).minus(vec));
+ }
+ else{
+ //push inner/light edge
+ ret.list.push(this.get(i).minus(int_vec));
+ }
+
+ //copy for next point
+ last_vec = vec;
+ last_vec_o = vec_o;
+ }
+ //add last pointsets
+ ret.list.unshift(this.get(i).plus(last_vec_o).plus(last_vec));
+ ret.list.push(this.get(i).minus(last_vec_o).plus(last_vec));
+
+ ret.close();
+
+ return ret;
+}
+
Geometry.prototype.toString = function () {
var str = "";
@@ -1087,8 +1192,6 @@
return str;
};
-
-
/**
* @class an array of elements, each consisting of a name/value pair
*
Modified: branches/nimix_dev/http/javascripts/mod_featureInfoTunnel.php
===================================================================
--- branches/nimix_dev/http/javascripts/mod_featureInfoTunnel.php 2008-10-07 07:47:52 UTC (rev 3135)
+++ branches/nimix_dev/http/javascripts/mod_featureInfoTunnel.php 2008-10-07 07:55:13 UTC (rev 3136)
@@ -101,5 +101,4 @@
else
alert(unescape("Please select a layer! \n Bitte waehlen Sie eine Ebene zur Abfrage aus!"));
}
-// setFeatureInfoRequest(mod_featureInfoTunnel_target,clickX,clickY, '../extensions/ext_featureInfoTunnel.php');
}
\ No newline at end of file
Modified: branches/nimix_dev/http/javascripts/mod_georss.php
===================================================================
--- branches/nimix_dev/http/javascripts/mod_georss.php 2008-10-07 07:47:52 UTC (rev 3135)
+++ branches/nimix_dev/http/javascripts/mod_georss.php 2008-10-07 07:55:13 UTC (rev 3136)
@@ -85,9 +85,9 @@
var min = realToMap(frame, extent[0]);
var max = realToMap(frame, extent[1]);
min.x-=pixel;
- min.y-=pixel;
+ min.y+=pixel;
max.x+=pixel;
- max.y+=pixel;
+ max.y-=pixel;
extent[0] = mapToReal(frame, min)
extent[1] = mapToReal(frame, max)
return extent;
Modified: branches/nimix_dev/http/javascripts/usemap.js
===================================================================
--- branches/nimix_dev/http/javascripts/usemap.js 2008-10-07 07:47:52 UTC (rev 3135)
+++ branches/nimix_dev/http/javascripts/usemap.js 2008-10-07 07:55:13 UTC (rev 3136)
@@ -91,12 +91,7 @@
}
//append to dom and set event handelers
-/* if($.browser.msie){
- alert(actualImageMap.areas.length)
- actualImageMap.areas[actualImageMap.areas.length] = area;
- }
- else
-*/ actualImageMap.appendChild(area);
+ actualImageMap.appendChild(area);
area.title = m.title;
area.onmouseover = m.mouseover;
@@ -116,102 +111,21 @@
};
this.setLineAttributes = function(area, m, target){
//apply line shape to area
- area.setAttribute("shape", 'poly');
if(m.count()==1)
return this.setPointAttributes(area,m,target);
- points = [];
+ var dim = mapToReal(target, new Point(this.lineBuffer,this.lineBuffer)).minus(mapToReal(target, new Point(0,0)));
- first_point= realToMap(target,m.get(0));
- this_point = realToMap(target,m.get(1));
- //get vector from point 0 to point 1
- last_vec = this_point.minus(first_point);
- //get 90° rotated vector
- last_vec_o = new Point(-last_vec.y, last_vec.x);
- //calculate vectors with linebuffer length
- last_vec_o = last_vec_o.times(this.lineBuffer/last_vec_o.dist(new Point(0,0)));
- last_vec = last_vec.times(this.lineBuffer/last_vec.dist(new Point(0,0)));
+ var g = m.bufferLine(Math.abs(dim.x),Math.abs(dim.y));
- //add first pointsets
- points.unshift(first_point.plus(last_vec_o).minus(last_vec));
- points.push(first_point.minus(last_vec_o).minus(last_vec));
+ var e = new MultiGeometry(geomType.polygon);
+ e.add(g);
- for(var i=1;i<m.count()-1;i++){
- next_point = realToMap(target,m.get(i+1));
- //get vector from point n to point n+1
- vec = next_point.minus(this_point);
- //get orthogonal (90° rotated) vector
- vec_o = new Point(-vec.y, vec.x);
-
- //resize vectors to linebuffer length
- vec_o = vec_o.times(this.lineBuffer/vec_o.dist(new Point(0,0)));
- vec = vec.times(this.lineBuffer/vec.dist(new Point(0,0)));
-
- //if direction is the same continue
- if(vec.equals(last_vec))
- continue;
-
- // calculate angle between the two vectors by
- // calculating the argument diffenrences between complex numbers
- // arg(x + i*y)
- var angle = (Math.atan2(vec.x,vec.y)-Math.atan2(last_vec.x,last_vec.y))
- //ensure that angle is -180<=angle<=180
- if(angle<-Math.PI)angle=2*Math.PI+angle;
- if(angle>+Math.PI)angle=2*Math.PI-angle;
-
- //calculate the distance between the next points on boundary
- //and the line point
- //the point will be in the direction of angle/2 relative to last_vec_o
- //since cosine is adjacent side / hypothenuse and we know that
- //the adjacent side is lineBuffer the hypothenus (our distance) is
- var ndist = this.lineBuffer/(Math.cos(angle/2))
- //direction of next points on boundary
- var int_vec = vec_o.plus(last_vec_o);
- //resize direction vector to our distance
- int_vec = int_vec.times(ndist/int_vec.dist(new Point(0,0)));
-
- //look if we have a sharp corner (>90°)
- if(Math.abs(angle)>Math.PI/2){
- //look where we have the outer edge of corner > 90°
- if(angle<0){
- //angle is negative so the outer edge is "on top"
- //push cutted edge points
- points.push(this_point.minus(last_vec_o).plus(last_vec));
- points.push(this_point.minus(vec_o).minus(vec));
- //TODO look if we need the inner edge or maybe even not the last inserted point
- //push inner edge
- points.unshift(this_point.plus(int_vec));
- }
- else{
- //angle is positive so the outer edge is "on bottom"
- //push cutted edge points
- points.unshift(this_point.plus(last_vec_o).plus(last_vec));
- points.unshift(this_point.plus(vec_o).minus(vec));
- //TODO look if we need the inner edge or maybe even not the last inserted point
- //push inner edge
- points.push(this_point.minus(int_vec));
- }
- }
- //otherwise only calculate intersection of bufferboundary lines
- else{
- points.unshift(this_point.plus(int_vec));
- points.push(this_point.minus(int_vec));
- }
- //copy for next point
- last_vec = vec;
- last_vec_o = vec_o;
- this_point = next_point;
- }
- //add last pointsets
- points.unshift(this_point.plus(last_vec_o).plus(last_vec));
- points.push(this_point.minus(last_vec_o).plus(last_vec));
-
- coords = [];
- for (var i=0; i<points.length; i++) {
- coords.push(String(parseInt(points[i].x)));
- coords.push(String(parseInt(points[i].y)));
- }
- area.setAttribute("coords", coords.join(","));
+ hter = new Highlight(new Array(target), "geoHL", {"position":"absolute", "top":"0px", "left":"0px", "z-index":30}, 2);
+ hter.add(e,"blue");
+ hter.paint();
+
+ this.setPolygonAttributes(area, g, target);
};
this.setPolygonAttributes = function(area, m, target){
//apply polygon shape to area
More information about the Mapbender_commits
mailing list