[Mapbender-commits] r1959 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jan 14 07:34:18 EST 2008


Author: christoph
Date: 2008-01-14 07:34:18 -0500 (Mon, 14 Jan 2008)
New Revision: 1959

Modified:
   trunk/mapbender/http/javascripts/geometry.js
Log:
merged with route planning project

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2008-01-14 11:21:58 UTC (rev 1958)
+++ trunk/mapbender/http/javascripts/geometry.js	2008-01-14 12:34:18 UTC (rev 1959)
@@ -227,6 +227,21 @@
 	return str;
 }
 
+GeometryArray.prototype.getBBox = function(){
+	var q = this.get(0).get(0).get(0);
+	var min = cloneObject(q);
+	var max = cloneObject(q);
+	for(var i=0; i<this.count();i++){
+		var pos = this.get(i).getBBox();
+		if (pos[0].x < min.x) {min.x = pos[0].x;}
+		if (pos[1].x > max.x) {max.x = pos[1].x;}
+		if (pos[1].y > max.y) {max.y = pos[1].y;}
+		if (pos[0].y < min.y) {min.y = pos[0].y;}
+	}
+	return [min, max];
+};
+
+
 GeometryArray.prototype.importGeoJSON = function (geoJSON) {
 	var isFeatureCollection = false;
 	var featureCollectionEpsg = 4326;
@@ -363,9 +378,9 @@
 	}
 }
 
+
 GeometryArray.prototype.toString = function () {
-	var str = "{\"type\": \"FeatureCollection\", ";
-	str += "\"features\": [";
+	var str = "{\"type\": \"FeatureCollection\", \"features\": [";
 
 	// separate: geometries that are from a KML and those which are not
 	var multiGeometriesFromKml = [];
@@ -613,7 +628,7 @@
 };
 
 MultiGeometry.prototype.toStringWithoutProperties = function () {
-	var str = "{\"type\": \"Feature\", ";
+	var str = "{\"type\": \"Feature\", \"geometry\": ";
 
 	var epsg = this.getEpsg();
 	if (epsg) {
@@ -644,7 +659,6 @@
 	return false;
 }
 
-
 /**
  * @class a Geometry is a List of Point objects. If it is a polygon, the last point has 
  * to equal the first point.
@@ -1094,37 +1108,47 @@
 	 * @private
 	 */
  	this.drawGeometry = function(t,g,col){ 
-		var mapObjInd = getMapObjIndexByName(mapframe);
-		width = mb_mapObj[mapObjInd].width;
-		height = mb_mapObj[mapObjInd].height;
-		for(var i=0; i < g.count(); i++){
-			if(t==geomType.point) {
-				var p = realToMap(mapframe,g.get(i).get(0));
-				if (p.x + diameter < mb_mapObj[mapObjInd].width && p.x - diameter > 0 &&
-					p.y + diameter < mb_mapObj[mapObjInd].height && p.y - diameter > 0) {
+		if(t == geomType.point) {
+			var poiIcon = g.e.getElementValueByName("Mapbender:icon");
+			for(var i=0, ilen = g.count(); i < ilen; i++){
+				var currentGeom = g.get(i);
+				var p = realToMap(mapframe, currentGeom.get(0));
+				var px = p.x;
+				var py = p.y;
+				if (px + diameter < mapframeWidth && px - diameter > 0 &&
+					py + diameter < mapframeHeight && py - diameter > 0) {
 					// if the point contains a link to an icon, display the icon
-					if (g.e.getElementValueByName("Mapbender:icon")) {
-						displayIcon(g.e.getElementValueByName("Mapbender:icon"), p.x, p.y);
+					if (poiIcon) {
+						displayIcon(poiIcon, px, py);
 					}
 					else {
-						drawCircle(p.x-1, p.y-1, diameter,col);
+						drawCircle(px-1, py-1, diameter,col);
 					}
 				}
 			}
-			else if(t==geomType.line || t==geomType.polygon) {
-				for (var j=0; j<g.get(i).count()-1; j++) {
-					var pq = calculateVisibleDash(realToMap(mapframe,g.get(i).get(j)), realToMap(mapframe,g.get(i).get(j+1)), width, height);
-					if (pq) {
-						drawLine([pq[0].x-1, pq[1].x-1], [pq[0].y-1, pq[1].y-1], col);
-					}
+		}
+		else if(t == geomType.line || t==geomType.polygon) {
+			for(var i=0, ilen = g.count(); i < ilen; i++){
+				var currentGeom = g.get(i);
+				var previousPoint = realToMap(mapframe, currentGeom.get(0));
+				for (var j=1, jlen = currentGeom.count(); j < jlen; j++) {
+					(function () {
+						var currentPoint = realToMap(mapframe, currentGeom.get(j));
+						
+						var pq = calculateVisibleDash(previousPoint, currentPoint, mapframeWidth, mapframeHeight);
+						if (pq) {
+							drawLine([pq[0].x-1, pq[1].x-1], [pq[0].y-1, pq[1].y-1], col);
+						}
+						previousPoint = currentPoint;
+					})();
 				}
 			}
-			else {
-				var e = new Mb_exception("class Canvas: function drawGeometry: unknown geomType " + t);
-			}
 		}
+		else {
+			var e = new Mb_exception("class Canvas: function drawGeometry: unknown geomType " + t);
+		}
 	};
-	
+
 	/**
 	 * checks if the MultiGeometry's bounding box width and height is smaller than minWidth
 	 *
@@ -1132,6 +1156,9 @@
 	 * @param {MultiGeometry} g a MultiGeometry object
 	 */
 	this.isTooSmall = function(g){
+		// TODO switch between dot, original, circle
+		return false;
+
 		var tmp = g.getBBox();
 		var min = realToMap(mapframe,tmp[0]);
 		var max = realToMap(mapframe,tmp[1]);
@@ -1190,11 +1217,14 @@
 	var displayIcon = function (url, x, y) {
 		var newImg = document.createElement("img");
 		newImg.src = url;
+		newImg.className = "mapsymbol";
+		newImg.style.cursor = "help";
 		newImg.style.position = "absolute";
 
 		// center the image at x, y
 		newImg.style.top = y - Math.round(newImg.height/2);
 		newImg.style.left = x - Math.round(newImg.width/2);
+		newImg.style.zIndex = 100;
 		that.canvasDivTag.getTag().appendChild(newImg);
 	}
 	
@@ -1211,6 +1241,9 @@
 	var minWidth = 8;
 	var lineWidth = aLineWidth;
 	var mapframe = aMapframe;
+	var mapObjInd = getMapObjIndexByName(mapframe);
+	var mapframeWidth = mb_mapObj[mapObjInd].width;
+	var mapframeHeight = mb_mapObj[mapObjInd].height;
 	var style = aStyle;
 	var canvas = new jsGraphics(aTagName, window.frames[mapframe]);
 	canvas.setStroke(lineWidth);
@@ -1283,7 +1316,6 @@
 				del = true;
 			}
 		}
-		this.paint();
 	};
 
 	/**
@@ -1328,8 +1360,8 @@
 	this.setMouseOver = function (callback) {
 		for (var i=0; i<targets.length; i++){
 			if (typeof(canvas[i]) !== 'undefined') {
-				canvas[i].canvasDivTag.getTag().onmouseover = function () {
-					callback();
+				canvas[i].canvasDivTag.getTag().onmouseover = function (e) {
+					callback(e);
 				}
 			}
 		}
@@ -1338,8 +1370,8 @@
 	this.setMouseOut = function (callback) {
 		for (var i=0; i<targets.length; i++){
 			if (typeof(canvas[i]) !== 'undefined') {
-				canvas[i].canvasDivTag.getTag().onmouseout = function () {
-					callback();
+				canvas[i].canvasDivTag.getTag().onmouseout = function (e) {
+					callback(e);
 				}
 			}
 		}
@@ -1348,8 +1380,8 @@
 	this.setMouseClick = function (callback) {
 		for (var i=0; i<targets.length; i++){
 			if (typeof(canvas[i]) !== 'undefined') {
-				canvas[i].canvasDivTag.getTag().onclick = function () {
-					callback();
+				canvas[i].canvasDivTag.getTag().onclick = function (e) {
+					callback(e);
 				}
 			}
 		}



More information about the Mapbender_commits mailing list