[Mapbender-commits] r5326 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jan 13 10:35:43 EST 2010
Author: christoph
Date: 2010-01-13 10:35:43 -0500 (Wed, 13 Jan 2010)
New Revision: 5326
Modified:
trunk/mapbender/http/javascripts/geometry.js
Log:
linted
Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js 2010-01-13 15:34:55 UTC (rev 5325)
+++ trunk/mapbender/http/javascripts/geometry.js 2010-01-13 15:35:43 UTC (rev 5326)
@@ -108,7 +108,7 @@
* @returns the Point object at the given indices
*/
GeometryArray.prototype.getPoint = function(i, j, k, l){
- if (l == undefined) {
+ if (l === undefined) {
return this.get(i).get(j).get(k);
}
return this.get(i).get(j).innerRings.get(k).get(l);
@@ -126,18 +126,20 @@
*/
GeometryArray.prototype.union = function(geom, uniqueFid){
var oldLen = this.count();
+ var i, j;
+ var mygeom = geom;
//
// only add geometries that are not already present
//
if (typeof uniqueFid === "boolean" && uniqueFid) {
- var geom = geom.clone();
- for (var i = 0; i < this.count(); i++) {
+ mygeom = geom.clone();
+ for (i = 0; i < this.count(); i++) {
var existingFid = this.get(i).e.getElementValueByName("fid");
- var len = geom.count() - 1;
- for (var j = len; j >= 0; j--) {
- var fid = geom.get(j).e.getElementValueByName("fid");
+ var len = mygeom.count() - 1;
+ for (j = len; j >= 0; j--) {
+ var fid = mygeom.get(j).e.getElementValueByName("fid");
if (fid && fid === existingFid) {
- geom.del(j);
+ mygeom.del(j);
continue;
}
}
@@ -145,10 +147,10 @@
}
this.importGeoJSON(geom.toString());
- var j = 0;
- for (var i = oldLen; i < this.count(); i++) {
- if (typeof geom.get(j).wfs_conf !== "undefined") {
- this.get(i).wfs_conf = geom.get(j).wfs_conf;
+ j = 0;
+ for (i = oldLen; i < this.count(); i++) {
+ if (typeof mygeom.get(j).wfs_conf !== "undefined") {
+ this.get(i).wfs_conf = mygeom.get(j).wfs_conf;
}
j++;
}
@@ -201,16 +203,27 @@
* closes the current {@link MultiGeometry}. Calls method close of the {@link Geometry} class.
*
*/
-GeometryArray.prototype.close = function(){
- if (!this.get(-1).get(-1).close()) {
- this.delGeometry(-1, -1);
+GeometryArray.prototype.close = function(i){
+ var index;
+ if (arguments.length > 0) {
+ index = this.getIndex(i);
+ if (index === false) {
+ return null;
+ }
}
else {
- if (this.get(-1).get(-1).count() === 0) {
- this.get(-1).del(-1);
+ index = -1;
+ }
+
+ if (!this.get(index).get(-1).close()) {
+ this.delGeometry(index, -1);
+ }
+ else {
+ if (this.get(index).get(-1).count() === 0) {
+ this.get(index).del(-1);
}
- if (this.get(-1).count() === 0) {
- this.del(-1);
+ if (this.get(index).count() === 0) {
+ this.del(index);
}
}
@@ -223,15 +236,16 @@
*/
GeometryArray.prototype.delAllPointsLike = function(point){
var finished = false;
+ var i, j, k, l;
while (finished === false){
finished = true;
- for (var i = 0 ; finished === true && i < this.count() ; i++){
- for (var j = 0 ; finished === true && j < this.get(i).count() ; j++){
+ for (i = 0 ; finished === true && i < this.count() ; i++){
+ for (j = 0 ; finished === true && j < this.get(i).count() ; j++){
var currentGeometry = this.get(i).get(j);
if (currentGeometry.geomType == geomType.polygon && currentGeometry.innerRings) {
- for (var k = 0; finished === true && k < currentGeometry.innerRings.count(); k++) {
- for (var l = 0; finished === true && l < currentGeometry.innerRings.get(k).count(); l++) {
+ for (k = 0; finished === true && k < currentGeometry.innerRings.count(); k++) {
+ for (l = 0; finished === true && l < currentGeometry.innerRings.get(k).count(); l++) {
if (this.getPoint(i, j, k, l).equals(point)) {
this.delPoint(i, j, k, l);
finished = false;
@@ -243,7 +257,7 @@
break;
}
- for (var k = 0 ; finished === true && k < this.get(i).get(j).count() ; k++){
+ for (k = 0 ; finished === true && k < this.get(i).get(j).count() ; k++){
if (this.getPoint(i,j,k).equals(point)){
this.delPoint(i,j,k);
finished = false;
@@ -267,11 +281,12 @@
};
GeometryArray.prototype.placemarkToString = function (placemarkId) {
+ var i;
var str = "{\"type\": \"Feature\", \"geometry\": ";
// get geometries with placemarkId
var geometriesFromPlacemark = [];
- for (var i = 0, len = this.count(); i < len; i++) {
+ for (i = 0, len = this.count(); i < len; i++) {
if (this.get(i).isFromKml() && this.get(i).e.getElementValueByName("Mapbender:placemarkId") == placemarkId) {
geometriesFromPlacemark.push(i);
}
@@ -279,7 +294,7 @@
if (geometriesFromPlacemark.length > 1) {
str += "{\"type\": \"GeometryCollection\", \"geometries\": [";
- for (var i = 0; i < geometriesFromPlacemark.length; i++) {
+ for (i = 0; i < geometriesFromPlacemark.length; i++) {
if (i > 0) {
str += ",";
}
@@ -316,7 +331,7 @@
};
GeometryArray.prototype.importGeometryFromText = function (text, srs) {
-
+ var i, j, m, currentPoint;
var tmpArray = text.split("(");
var geometryType = tmpArray[0];
@@ -327,15 +342,15 @@
var polyArray = sepArray[1].split(",((");
this.addMember(geomType.polygon);
- for (var i = 0; i < polyArray.length; i++) {
+ for (i = 0; i < polyArray.length; i++) {
var ringArray = polyArray[i].split(",(");
- for (var j = 0; j < ringArray.length; j++) {
+ for (j = 0; j < ringArray.length; j++) {
var coordinatesArray = ringArray[j].split(",");
if (j === 0) {
// add outer ring
this.get(-1).addGeometry();
- for (var m = 0; m < -1 + coordinatesArray.length; m++) {
- var currentPoint = coordinatesArray[m].split(" ");
+ for (m = 0; m < -1 + coordinatesArray.length; m++) {
+ currentPoint = coordinatesArray[m].split(" ");
this.getGeometry(-1, -1).addPointByCoordinates(parseFloat(currentPoint[0]), parseFloat(currentPoint[1]));
this.getGeometry(-1,-1).setEpsg(srs);
}
@@ -344,8 +359,8 @@
else {
// add inner ring
var ring = new Geometry(geomType.polygon);
- for (var m = 0; m < -1 + coordinatesArray.length; m++) {
- var currentPoint = coordinatesArray[m].split(" ");
+ for (m = 0; m < -1 + coordinatesArray.length; m++) {
+ currentPoint = coordinatesArray[m].split(" ");
ring.addPointByCoordinates(parseFloat(currentPoint[0]), parseFloat(currentPoint[1]));
}
ring.close();
@@ -355,6 +370,23 @@
}
}
break;
+ case "MULTILINESTRING":
+ var text = text.replace(/\)/g, "");
+ var sepArray = text.split("((");
+ var lineArray = sepArray[1].split(",(");
+
+ this.addMember(geomType.line);
+ for (var i = 0; i < lineArray.length; i++) {
+ var coordinatesArray = lineArray[i].split(",");
+ this.get(-1).addGeometry();
+ for (var m = 0; m < coordinatesArray.length; m++) {
+ var currentPoint = coordinatesArray[m].split(" ");
+ this.getGeometry(-1, -1).addPointByCoordinates(parseFloat(currentPoint[0]), parseFloat(currentPoint[1]));
+ this.getGeometry(-1,-1).setEpsg(srs);
+ }
+ this.close();
+ }
+ break;
}
};
@@ -436,7 +468,7 @@
var currentPolygon = coordinates[m];
for (var n = 0; n < currentPolygon.length; n++) {
var currentRing = currentPolygon[n];
- if (n == 0) {
+ if (n === 0) {
for (var p = 0; p < currentRing.length; p++) {
var currentPoint = currentRing[p];
this.getGeometry(-1, -1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
@@ -518,12 +550,12 @@
this.get(-1).e.setElement("fid", currentFeature.id);
}
}
-}
+};
GeometryArray.prototype.importGeoJSON = function (geoJSON) {
// you can pass either geoJSON or the evaluated geoJSON string
// for backwards compatibility
if (typeof(geoJSON) == 'string') {
- var geoJSON = eval('(' + geoJSON + ')');
+ var geoJSON = $.parseJSON(geoJSON);
}
//
@@ -543,7 +575,7 @@
break;
}
return true;
-}
+};
GeometryArray.prototype.featureToString = function (i) {
var str = "{\"type\": \"FeatureCollection\", \"features\": [";
@@ -763,7 +795,7 @@
*/
MultiGeometry.prototype.delPoint = function(i, j, k){
var res;
- if (k == undefined) {
+ if (k === undefined) {
res = this.get(i).del(j);
if (res === false) {
return this.del(i);
@@ -815,7 +847,7 @@
}
var currentPoint = currentLine.get(j);
- text += currentPoint.x + " " + currentPoint.y
+ text += currentPoint.x + " " + currentPoint.y;
}
text += ")";
@@ -894,7 +926,7 @@
break;
}
- str += "\"coordinates\": "
+ str += "\"coordinates\": ";
// geometries
if (len > 1) {
str += "[";
@@ -932,7 +964,7 @@
function InnerRings () {
this.list = [];
-};
+}
InnerRings.prototype = new List();
@@ -1138,8 +1170,8 @@
epsg = someEpsg;
return true;
- var e = new Mb_exception("EPSG code not valid ("+someEpsg+")");
- return false;
+// var e = new Mb_exception("EPSG code not valid ("+someEpsg+")");
+// return false;
};
/**
@@ -1186,7 +1218,7 @@
text += ", ";
}
var currentPoint = this.get(j);
- text += currentPoint.x + " " + currentPoint.y
+ text += currentPoint.x + " " + currentPoint.y;
}
text += ")";
if (this.innerRings && this.innerRings.count() > 0) {
@@ -1314,10 +1346,11 @@
Geometry.prototype.bufferLine = function(bufferX, bufferY){
if(typeof(bufferY)=='undefined')
bufferY = bufferX;
- if(this.geomType!=geomType.line || this.count()<2)
+ if (this.geomType != geomType.line || this.count() < 2) {
return false;
+ }
- var ret = new Geometry(geomType.polygon)
+ var ret = new Geometry(geomType.polygon);
//get vector from point 0 to point 1
last_vec = this.get(1).minus(this.get(0));
@@ -1348,8 +1381,9 @@
vec.x*=bufferX; vec.y*=bufferY;
//if direction is the same continue
- if(vec.equals(last_vec))
+ if(vec.equals(last_vec)) {
continue;
+ }
// calculate directed angle between the two vectors by
// calculating the argument diffenrences between complex numbers
@@ -1404,7 +1438,7 @@
ret.close();
return ret;
-}
+};
Geometry.prototype.toString = function () {
var str = "";
@@ -1515,7 +1549,7 @@
this.name.splice(i, 1);
this.value.splice(i, 1);
}
- }
+ };
/**
* checks if an index is valid
More information about the Mapbender_commits
mailing list