svn commit: r921 - trunk/mapbender/http/javascripts/mod_highlight.php

christoph at osgeo.org christoph at osgeo.org
Tue Nov 21 06:53:52 EST 2006


Author: christoph
Date: 2006-11-21 11:53:51+0000
New Revision: 921

Modified:
   trunk/mapbender/http/javascripts/mod_highlight.php

Log:
wz_graphics draws only visible parts of geometries

Modified: trunk/mapbender/http/javascripts/mod_highlight.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_highlight.php?view=diff&rev=921&p1=trunk/mapbender/http/javascripts/mod_highlight.php&p2=trunk/mapbender/http/javascripts/mod_highlight.php&r1=920&r2=921
==============================================================================
--- trunk/mapbender/http/javascripts/mod_highlight.php	(original)
+++ trunk/mapbender/http/javascripts/mod_highlight.php	2006-11-21 11:53:51+0000
@@ -7,6 +7,74 @@
 */
 require_once("mod_geometryArray.js");
 ?>
+function calculateVisibleDash (p0, p1, width, height) {
+	if (p0.x > p1.x) {var p_temp = p0; p0 = p1; p1 = p_temp; p_temp = null;}
+	var p = p0; var q = p1; var m; 
+	if (p1.x != p0.x) {
+		m = -(p1.y-p0.y)/(p1.x-p0.x); 
+		if (p0.x < width && p1.x > 0 && !(p0.y < 0 && p1.y < 0) && !(p0.y > height && p1.y > height) ) {
+			if (p0.x < 0) {
+				var iy = p0.y - m*(0-p0.x);
+				if (iy > 0 && iy < height) p = new Point(0, iy);
+				else if (iy > height) {
+				    var ix = p0.x+((p0.y - height)/m);
+				    if (ix > 0 && ix < width) p = new Point(ix, height); else return false;
+				}
+				else if (iy < 0) {
+				    var ix = p0.x+(p0.y/m);
+				    if (ix > 0 && ix < width) p = new Point(ix, 0); else return false;
+				}
+				else return false;
+			}
+			else if (p0.y >= 0 && p0.y <= height) {p = p0;}
+			else if (p0.y < 0) {
+			    var ix = p0.x+(p0.y/m);
+			    if (ix > 0 && ix < width) p = new Point(ix, 0); else return false;
+			}
+			else if (p0.y > height && m > 0) {
+			    var ix = p0.x+((p0.y - height)/m);
+			    if (ix > 0 && ix < width) p = new Point(ix, height); else return false;
+			}
+			else return false;
+			if (p1.x > width) {
+				var iy = p1.y - m*(width-p1.x);
+				if (iy > 0 && iy < height) {q = new Point(width, iy);}
+				else if (iy < 0) {
+				    var ix = p0.x+(p0.y/m);
+				    if (ix > 0 && ix < width) q = new Point(ix, 0); else return false;
+				}
+				else if (iy > height) {
+				    var ix = p0.x+((p0.y - height)/m);
+				    if (ix > 0 && ix < width) q = new Point(ix, height); else return false;
+				}
+				else return false;
+			}
+			else if (p1.y >= 0 && p1.y <= height) {q = p1;}
+			else if (p1.y < 0) {
+			    var ix = p1.x+(p1.y/m);
+			    if (ix > 0 && ix < width) q = new Point(ix, 0); else return false;
+			}
+			else if (p1.y > height) {
+			    var ix = p1.x+((p1.y- height)/m);
+			    if (ix > 0 && ix < width) q = new Point(ix, height); else return false;
+			}
+		}
+		else return false;
+	}
+	else {
+		if (!(p0.y < 0 && p1.y < 0) && !(p0.y > height && p1.y > height)) {
+			if (p0.y < 0) {p = new Point(p0.x, 0);}
+			else if (p0.y > height) {p = new Point(p0.x, height);}
+			else p = p0;
+			if (p1.y < 0) {q = new Point(p0.x, 0);}
+			else if (p1.y > height) {q = new Point(p0.x, height);}
+			else q = p1;
+		}
+		else return false;
+	}
+	return new Array(new Point(Math.round(q.x), Math.round(q.y)), new Point(Math.round(p.x), Math.round(p.y)));
+}
+	
 function Canvas(mapframe, tagname) {
 	this.paint = function(gA) {
 		if (this.checkTag()) {
@@ -33,24 +101,34 @@
 	}
 	
 	this.drawGeometry = function(t,g){
+		var mapObjInd = getMapObjIndexByName(this.mapframe);
+		width = mb_mapObj[mapObjInd].width;
+		height = mb_mapObj[mapObjInd].height;
 		for(var i=0; i < g.count(); i++){
-			var a = this.mb_wfs_toPix(g.get(i));
-			if(t==geomTypePoint) this.drawCircle(a['x'][0],a['y'][0],this.diameter,this.lineColor);
-			else if(t==geomTypeLine) this.drawLine(a['x'],a['y'],this.lineColor);
-			else if(t==geomTypePolygon)	this.drawPolygon(a['x'],a['y'],this.lineColor);
-		}
-	}
-
-	this.mb_wfs_toPix = function(g){
-		var r = new Array();
-		r['x'] = new Array();
-		r['y'] = new Array();
-		for(var i=0; i < g.count(); i++){
-			var currentV = realToMap(this.mapframe,g.get(i));
-			r['x'][i] = currentV.x;
-			r['y'][i] = currentV.y;
+			if(t==geomTypePoint) {
+				var p = realToMap(this.mapframe,g.get(i).get(0));
+				if (p.x + this.diameter < mb_mapObj[mapObjInd].width && p.x - this.diameter > 0 &&
+					p.y + this.diameter < mb_mapObj[mapObjInd].height && p.y - this.diameter > 0) {
+					this.drawCircle(p.x-1,p.y-1,this.diameter,this.lineColor);
+				}
+			}
+			else if(t==geomTypeLine) {
+				for (var j=0; j<g.get(i).count()-1; j++) {
+					var pq = calculateVisibleDash(realToMap(this.mapframe,g.get(i).get(j)), realToMap(this.mapframe,g.get(i).get(j+1)), width, height);
+					if (pq) {
+						this.drawLine(new Array(pq[0].x, pq[1].x),new Array(pq[0].y, pq[1].y),this.lineColor);
+					}
+				}
+			}
+			else if(t==geomTypePolygon) {
+				for (var j=0; j<g.get(i).count()-1; j++) {
+					var pq = calculateVisibleDash(realToMap(this.mapframe,g.get(i).get(j)), realToMap(this.mapframe,g.get(i).get(j+1)), width, height);
+					if (pq) {
+						this.drawLine(new Array(pq[0].x, pq[1].x),new Array(pq[0].y, pq[1].y),this.lineColor);
+					}
+				}
+			}
 		}
-		return r;
 	}
 	
 	this.isTooSmall = function(g){




More information about the Mapbender_commits mailing list