[Mapbender-commits] r1860 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Nov 27 09:22:37 EST 2007
Author: christoph
Date: 2007-11-27 09:22:36 -0500 (Tue, 27 Nov 2007)
New Revision: 1860
Modified:
trunk/mapbender/http/javascripts/mod_digitize_tab.php
Log:
kml enhancement
Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php 2007-11-26 13:41:25 UTC (rev 1859)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php 2007-11-27 14:22:36 UTC (rev 1860)
@@ -81,11 +81,34 @@
var digitizeDivTag;
+var GeometryArray = parent.GeometryArray;
+var MultiGeometry = parent.MultiGeometry;
+var Geometry = parent.Geometry;
+var Point = parent.Point;
+var geomType = parent.geomType;
+
var msgObj;
var featureTypeElementFormId = "featureTypeElementForm";
try {if(mod_digitize_elName){}}catch(e) {mod_digitize_elName = "digitize";}
+
+/**
+ * Append geometries from KML when KML has been loaded
+ */
+function appendGeometryArrayFromKML () {
+ try {
+ parent.kmlHasLoaded.register(function(properties){
+ d = parent.geoJsonToGeometryArray(properties);
+ executeDigitizeSubFunctions();
+ });
+ }
+ catch (e) {
+ var exc = new parent.Mb_warning(e);
+ }
+}
+
+
// ------------------------------------------------------------------------------------------------------------------------
// --- polygon, line, point insertion (begin) ----------------------------------------------------------------------------------------------
@@ -348,9 +371,11 @@
}
function executeDigitizeSubFunctions(){
+// console.profile();
for(var i=0; i<mod_digitizeSubFunctions.length; i++){
eval(mod_digitizeSubFunctions[i]);
}
+// console.profileEnd();
}
function executeDigitizePreFunctions(){
@@ -372,13 +397,14 @@
parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].checkDigitizeTag()");
parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseSnapping()");
parent.mb_registerL10nFunctions("window.frames['"+ mod_digitize_elName + "'].getMessages()");
+ parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].appendGeometryArrayFromKML()");
if (!nonTransactionalEditable) {
parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseHighlight()");
}
parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].initialiseMeasure()");
parent.mb_registerSubFunctions("window.frames['" + mod_digitize_elName + "'].updateExtent()");
if(spatialRequestResultToDigitize==1){
- parent.mb_registerWfsReadSubFunctions(function(geom){parent.tab_open(mod_digitize_elName);parent.window.frames[mod_digitize_elName].appendGeometryArray(geom);});
+ parent.mb_registerWfsReadSubFunctions(function(geom){parent.tab_open(mod_digitize_elName);parent.window.frames[mod_digitize_elName].appendGeometryArray(geom);});
}
parent.mb_registerWfsWriteSubFunctions(function(){parent.zoom(mod_digitize_target, true, 0.999);});
}
@@ -640,75 +666,84 @@
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>";
-
- for(var i=0; i<d.count(); i++){
- if (!nonTransactionalEditable && !isTransactional(d.get(i))) {
- nonTransactionalHighlight.add(d.get(i), nonTransactionalColor);
+ 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>";
+
+ 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; j<d.get(i).count(); j++){
- for(var k = 0; k < d.getGeometry(i,j).count(); k++){
- var pos = parent.makeRealWorld2mapPos(mod_digitize_target,d.getPoint(i,j,k).x,d.getPoint(i,j,k).y);
+ for(var j=0, lenGeom = currentGeomArray.count(); j < lenGeom ; j++){
+ var currentGeometry = d.getGeometry(i,j);
+ 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);
- if (!d.getGeometry(i,j).isComplete() &&
- ( (k == 0 && d.get(i).geomType == parent.geomType.polygon) || (k == d.getGeometry(i,j).count()-1 && d.get(i).geomType == parent.geomType.line))) {
- smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";background-color:"+linepointColor+"'";
+ 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+"'";
}
else {
- smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";'";
+ smPArray[smPArray.length] = "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:"+digitizeTransactionalZIndex+";'";
}
- if(j==0 && d.get(i).geomType == parent.geomType.polygon && !d.getGeometry(i,j).isComplete()){
- smP += " title='"+closePolygon_title+"' ";
+ 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) {
- smP += " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
+ smPArray[smPArray.length] = " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
}
- smP += "></div>";
+ smPArray[smPArray.length] = "></div>";
}
- var mapObjInd = parent.getMapObjIndexByName(mod_digitize_target);
- for(var k = 1; k < d.getGeometry(i,j).count(); k++){
+ 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, parent.mb_mapObj[mapObjInd].width, parent.mb_mapObj[mapObjInd].height);
+ points = parent.calculateVisibleDash(p0, p1, mapObj.width, mapObj.height);
if (points != false) {
- smP += evaluateDashes(points[0], points[1], i, j, k);
+ smPArray[smPArray.length] = evaluateDashes(points[0], points[1], i, j, k);
}
}
}
}
}
- digitizeDivTag.write(smP);
+ digitizeDivTag.write(smPArray.join(""));
}
function evaluateDashes(start, end, memberIndex, geomIndex, pointIndex){
- var str_dashedLine = "";
+ var strArray = [];
var delta = new parent.Point(end.x - start.x, end.y - start.y);
+ var lastGeomIsComplete = d.getGeometry(-1,-1).isComplete();
var vecLength = start.dist(end);
var n = Math.round(vecLength/dotDistance);
- var step = new parent.Point(delta.x/n, delta.y/n);
- for(var i=1; i<n; i++){
+ if (n > 0) {
+ var step = delta.dividedBy(n);
+ }
+ for(var i=1; i < n; i++){
var x = Math.round(start.x + i * step.x) - 2;
var y = Math.round(start.y + i * step.y) - 2;
if(x >= 0 && x <= mod_digitize_width && y >= 0 && y <= mod_digitize_height){
- if (memberIndex == d.count()-1 && !d.getGeometry(-1,-1).isComplete()) {
- str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";background-color:"+linepointColor+"' ";
+ if (memberIndex == d.count()-1 && !lastGeomIsComplete) {
+ strArray[strArray.length] = "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";background-color:"+linepointColor+"' ";
}
else {
- str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";' ";
+ strArray[strArray.length] = "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:"+digitizeTransactionalZIndex+";' ";
}
if(mod_digitizeEvent == button_insert) {
- str_dashedLine += "onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].convertLinepointToBasepoint(this,"+memberIndex+","+geomIndex+","+pointIndex+")'";
+ strArray[strArray.length] = "onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].convertLinepointToBasepoint(this,"+memberIndex+","+geomIndex+","+pointIndex+")'";
}
- str_dashedLine += "></div>";
+ strArray[strArray.length] = "></div>";
}
}
- return str_dashedLine;
+ return strArray.join("");
}
function isTransactional(geom) {
@@ -748,6 +783,9 @@
}
return resultName;
}
+ else if (geom.e.getElementValueByName("name")) {
+ return geom.e.getElementValueByName("name");
+ }
else {
return msgObj.digitizeDefaultGeometryName;
}
@@ -758,15 +796,32 @@
if (d.count() > 0) {
wfsConf = parent.get_complete_wfs_conf();
for (var i = 0 ; i < d.count(); i ++) {
+
if (d.get(i).get(-1).isComplete() && (nonTransactionalEditable || isTransactional(d.get(i)))) {
- listOfGeom += "\t<tr>\n\t\t<td>\n";
- if (wfsExistsForGeom(d.get(i), wfsConf)) {
- listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_wfs_src+"' title='"+msgObj.buttonDig_wfs_title+"' onclick='showWfs("+i+")'>\n";
+
+ // for the geometries from a kml, there is another save dialogue
+ if (d.get(i).isFromKml()) {
+ // if the kml is in the db (id = id in database)
+ if (d.get(i).e.getElementValueByName("Mapbender:id")) {
+ // button: geometry information, update kml
+ listOfGeom += "\t<tr>\n\t\t<td>\n";
+ listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_wfs_src+"' title='"+msgObj.buttonDig_wfs_title+"' onclick='showWfsKml("+i+")'>\n";
+ }
}
+ else {
+ // button: geometry information, save, update, delete
+ listOfGeom += "\t<tr>\n\t\t<td>\n";
+ if (wfsExistsForGeom(d.get(i), wfsConf)) {
+ listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_wfs_src+"' title='"+msgObj.buttonDig_wfs_title+"' onclick='showWfs("+i+")'>\n";
+ }
+ listOfGeom += "\t\t</td>\n\t\t<td>\n";
+
+ // button: remove this geometry
+ listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_remove_src+"' title='"+msgObj.buttonDig_remove_title+"' onclick='parent.mb_disableThisButton(mod_digitizeEvent);d.del("+i+");executeDigitizeSubFunctions();'>\n";
+ }
listOfGeom += "\t\t</td>\n\t\t<td>\n";
- listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_remove_src+"' title='"+msgObj.buttonDig_remove_title+"' onclick='parent.mb_disableThisButton(mod_digitizeEvent);d.del("+i+");executeDigitizeSubFunctions();'>\n";
- listOfGeom += "\t\t</td>\n\t\t<td>\n";
-
+
+ // button: remove geometry from database
if (isValidWfsConfIndex(wfsConf, d.get(i).wfs_conf)) {
listOfGeom += "\t\t\t<img src = '"+buttonDig_imgdir+buttonDig_removeDb_src+"' title='"+msgObj.buttonDig_removeDb_title+"' onclick=\"var deltrans = confirm('"+msgObj.messageConfirmDeleteGeomFromDb+"');if (deltrans) dbGeom('delete', "+i+")\">\n";
}
@@ -958,6 +1013,46 @@
}
+function showWfsKml (geometryIndex) {
+ wfsKmlWindow = open("", "wfsattributes", "width="+wfsWindowWidth+", height="+wfsWindowHeight+", resizable, dependent=yes, scrollbars=yes");
+ wfsKmlWindow.document.open("text/html");
+ wfsKmlWindow.document.writeln("<html><head></head><body><div id='linkToKml'></div><div id='elementForm'></div></body></html>");
+ wfsKmlWindow.document.close();
+
+ str = "<form id = 'wmsKmlForm' onsubmit='return false;'><table>";
+
+ var properties = d.get(geometryIndex).e;
+ var propertyCount = properties.count();
+ for (var i = 0; i < propertyCount; i++) {
+ var key = properties.getName(i);
+ var value = properties.getValue(i);
+ var expr = /Mapbender:/;
+ if (!key.match(expr)) {
+ str += "\t\t<tr>\n";
+ str += "\t\t\t<td>\n\t\t\t\t<div>" + key + "</div>\n\t\t\t</td>\n";
+ str += "\t\t\t<td>\n";
+ str += "\t\t\t\t<input id = 'wmskml_" + i + "' name='" + key + "' type='text' size=20 value = '" + value + "'>\n";
+ str += "\t\t\t</td>\n\t\t</tr>\n";
+ }
+ }
+
+ var updateOnClickText = "this.disabled=true;window.opener.updateKmlInDb("+geometryIndex+", 'update');";
+ var deleteOnClickText = "var deltrans = confirm('This geometry will be removed from the KML.');";
+ deleteOnClickText += "if (deltrans){";
+ deleteOnClickText += "this.disabled=true;window.opener.updateKmlInDb("+geometryIndex+", 'delete')}";
+
+ str += "\t\t\t<td><input type='button' name='updateButton' value='Update' onclick=\""+updateOnClickText+"\"/></td>\n";
+// delete button not yet implemented
+// str += "\t\t\t<td><input type='button' name='deleteButton' value='Delete' onclick=\""+deleteOnClickText+"\"/></td>\n";
+ str += "\t\t\t<td><input type='button' name='abortButton' value='Abort' onclick=\"window.close();\" /></td>\n";
+
+ str += "\t\t</tr>\n";
+ str += "\t</table>\n";
+ str += "</form>\n";
+
+ wfsKmlWindow.document.getElementById("elementForm").innerHTML = str;
+}
+
//
// this method opens a new window and displays the attributes in wfs_conf
//
@@ -1234,6 +1329,62 @@
alert(wfsWriteMessage);
}
}
+function getMultiGeometryIdsByPlacemarkId (placemarkId) {
+ var multiGeometryIdArray = [];
+ for (var i = 0; i < d.count(); i++) {
+ var currentPlacemarkId = d.get(i).e.getElementValueByName("Mapbender:placemarkId");
+ if (currentPlacemarkId && currentPlacemarkId == placemarkId) {
+ multiGeometryIdArray.push(i);
+ }
+ }
+ return multiGeometryIdArray;
+}
+
+function updateKmlInDb (geometryIndex, command) {
+ var properties = d.get(geometryIndex).e;
+ var placemarkId = properties.getElementValueByName("Mapbender:placemarkId");
+
+ var multiGeometryIdArray = getMultiGeometryIdsByPlacemarkId(placemarkId);
+
+ if (typeof(wfsKmlWindow) != 'undefined' && !wfsKmlWindow.closed) {
+
+ // update properties from form
+ myform = wfsKmlWindow.document.getElementById("wmsKmlForm");
+
+ for (var i=0; i < myform.length; i++){
+ if (myform.elements[i].type == 'text' ){
+ if (myform.elements[i].id) {
+ var key = myform.elements[i].name;
+ var value = myform.elements[i].value;
+
+ // update all geometries with the same placemark id
+ for (var j = 0; j < multiGeometryIdArray.length; j++) {
+ var currentProperties = d.get(j).e;
+ currentProperties.setElement(key, value);
+ }
+ }
+ }
+ }
+ var kmlId = properties.getElementValueByName("Mapbender:id");
+
+ parent.mb_ajax_post("../php/mod_updateKmlInDb.php", {command:command, kmlId:kmlId, placemarkId:placemarkId, geoJSON:d.placemarkToString(placemarkId)}, function(obj, status) {
+ if (obj === "1") {
+ wfsKmlWindow.alert("KML updated.");
+ var link = wfsKmlWindow.document.createElement("a");
+ link.href = "../php/mod_displayKML.php?kmlId=" + kmlId;
+ link.target = "_blank";
+ link.innerHTML = "KML";
+ wfsKmlWindow.document.getElementById('elementForm').innerHTML = "";
+ wfsKmlWindow.document.getElementById('linkToKml').appendChild(link);
+ }
+ else {
+ wfsKmlWindow.alert("Error, KML could not be updated. Check your error log.");
+ }
+ });
+ }
+}
+
+
// --- wfs window (begin) -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------
More information about the Mapbender_commits
mailing list