[Mapbender-commits] r2078 - branches/2.5/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Feb 11 09:16:38 EST 2008


Author: christoph
Date: 2008-02-11 09:16:38 -0500 (Mon, 11 Feb 2008)
New Revision: 2078

Modified:
   branches/2.5/http/javascripts/mod_digitize_tab.php
Log:
optimization of drawdashedline(), much faster now

Modified: branches/2.5/http/javascripts/mod_digitize_tab.php
===================================================================
--- branches/2.5/http/javascripts/mod_digitize_tab.php	2008-02-11 14:15:32 UTC (rev 2077)
+++ branches/2.5/http/javascripts/mod_digitize_tab.php	2008-02-11 14:16:38 UTC (rev 2078)
@@ -675,57 +675,89 @@
 	if (!nonTransactionalEditable) {
 		nonTransactionalHighlight.clean();
 	}
+	var smP = "";
+	smP += "<div class='t_img'>";
+	smP += "<img src='"+parent.mb_trans.src+"' width='"+mod_digitize_width+"' height='0'></div>";
+	smP += "<div class='t_img'>";
+	smP += "<img src='"+parent.mb_trans.src+"' width='0' height='"+mod_digitize_height+"'></div>";
+
+	if (!nonTransactionalEditable) {
+		nonTransactionalHighlight.clean();
+	}
 	var smPArray = [];
 	smPArray[smPArray.length] = "<div class='t_img'>"
 			+ "<img src='"+parent.mb_trans.src+"' width='"+mod_digitize_width+"' height='0'></div>"
 			+ "<div class='t_img'>"
 			+ "<img src='"+parent.mb_trans.src+"' width='0' height='"+mod_digitize_height+"'></div>";
 	
+	var mapObj = parent.mb_mapObj[parent.getMapObjIndexByName(mod_digitize_target)];
+	var width = mapObj.width;
+	var height = mapObj.height;
+	var arrayBBox = mapObj.extent.split(",")
+	var minX = parseFloat(arrayBBox[0]);
+	var minY = parseFloat(arrayBBox[1]);
+	var maxX = parseFloat(arrayBBox[2]);
+	var maxY = parseFloat(arrayBBox[3]);
+	var cx = width/(maxX - minX);
+	var cy = height/(maxY - minY);
+	var isMoveOrInsertOrDelete = mod_digitizeEvent == button_move || mod_digitizeEvent == button_insert || mod_digitizeEvent == button_delete;
+	var minDist = 6;
+
 	for(var i=0, lenGeomArray = d.count(); i < lenGeomArray; i++){
 		var currentGeomArray = d.get(i);
-		
+
 		if (!nonTransactionalEditable && !isTransactional(currentGeomArray)) {
 			nonTransactionalHighlight.add(currentGeomArray, nonTransactionalColor);
 		}
 		else {
 			for(var j=0, lenGeom = currentGeomArray.count(); j < lenGeom ; j++){
-				var currentGeometry = d.getGeometry(i,j); 
+				var currentGeometry = d.getGeometry(i,j);
+				var isPolygon = currentGeomArray.geomType == parent.geomType.polygon;
+				var isLine = currentGeomArray.geomType == parent.geomType.line;
+				var isComplete = currentGeometry.isComplete();
+				var lastPaintedPoint = false;
+
 				for(var k = 0, lenPoint = currentGeometry.count(); k < lenPoint; k++){
-					var currentPoint = d.getPoint(i,j,k);
-					var pos = parent.makeRealWorld2mapPos(mod_digitize_target, currentPoint.x, currentPoint.y);
+					var currentPoint = currentGeometry.get(k);
+					var currentPointMap = new Point(Math.round((currentPoint.x - minX)*cx), Math.round((maxY - currentPoint.y)*cy));
 					
-					if (!currentGeometry.isComplete() && 
-						( (k == 0 && currentGeomArray.geomType == parent.geomType.polygon) || (k == currentGeometry.count()-1 && currentGeomArray.geomType == parent.geomType.line))) {
-						smPArray[smPArray.length] = "<div class='bp' style='top:"+
-							(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+
-							digitizeTransactionalZIndex+";background-color:"+linepointColor+"'";
+					var isTooCloseToPrevious = lastPaintedPoint && (k > 0) && Math.abs(currentPointMap.x-lastPaintedPoint.x) <= minDist && Math.abs(currentPointMap.y-lastPaintedPoint.y) <= minDist;
+					if (!isTooCloseToPrevious) {
+						var currentPointIsVisible = currentPointMap.x > 0 && currentPointMap.x < width && currentPointMap.y > 0 && currentPointMap.y < height;
+						if (currentPointIsVisible) {
+							if (!isComplete && ((k == 0 && isPolygon) || (k == lenPoint-1 && isLine))) {
+								smPArray[smPArray.length] = "<div class='bp' style='top:"+
+									(currentPointMap.y-2)+"px;left:"+(currentPointMap.x-2)+"px;z-index:"+
+									digitizeTransactionalZIndex+";background-color:"+linepointColor+"'";
+							}
+							else {
+								smPArray[smPArray.length] = "<div class='bp' style='top:"+(currentPointMap.y-2)+"px;left:"+(currentPointMap.x-2)+"px;z-index:"+digitizeTransactionalZIndex+";'";
+							}
+							if(k==0 && isPolygon && !isComplete){
+								smPArray[smPArray.length] = " title='"+closePolygon_title+"' ";
+							}
+							if(isMoveOrInsertOrDelete) {
+								smPArray[smPArray.length] = " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
+							}
+							smPArray[smPArray.length] = "></div>";
+							lastPaintedPoint = currentPointMap;
+						}
+						if (k > 0) {
+							points = parent.calculateVisibleDash(currentPointMap, previousPointMap, width, height);
+							if (points != false) {
+								smPArray[smPArray.length] = evaluateDashes(points[0], points[1], i, j, k);
+							}
+						}
 					}
-					else {
-						smPArray[smPArray.length] = "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";'";
-					}
-					if(j==0 && currentGeomArray.geomType == parent.geomType.polygon && !currentGeometry.isComplete()){
-						smPArray[smPArray.length] = " title='"+closePolygon_title+"' ";
-					}
-					if(mod_digitizeEvent == button_move || mod_digitizeEvent == button_insert || mod_digitizeEvent == button_delete) {
-						smPArray[smPArray.length] = " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
-					}
-					smPArray[smPArray.length] = "></div>";
+					var previousPointMap = currentPointMap;
 				}
-				var mapObj = parent.mb_mapObj[parent.getMapObjIndexByName(mod_digitize_target)];
-				for(var k = 1; k < currentGeometry.count(); k++){
-					var p0 = parent.realToMap(mod_digitize_target, d.getPoint(i,j,k));
-					var p1 = parent.realToMap(mod_digitize_target, d.getPoint(i,j,k-1));
-					points = parent.calculateVisibleDash(p0, p1, mapObj.width, mapObj.height);
-					if (points != false) {
-						smPArray[smPArray.length] = evaluateDashes(points[0], points[1], i, j, k);
-					}
-				}
 			}
 		}
 	}
 	digitizeDivTag.write(smPArray.join(""));
 }
 
+
 function evaluateDashes(start, end, memberIndex, geomIndex, pointIndex){
 	var strArray = [];
 	var delta = new parent.Point(end.x - start.x, end.y - start.y);



More information about the Mapbender_commits mailing list