svn commit: r93 - trunk/mapbender/http/javascripts/mod_digitize_tab.php
christoph at osgeo.org
christoph at osgeo.org
Wed Apr 19 09:21:54 EDT 2006
Author: christoph
Date: 2006-04-19 13:21:54+0000
New Revision: 93
Modified:
trunk/mapbender/http/javascripts/mod_digitize_tab.php
Log:
only basepoints on mapframe are calculated
wfs featuretype namespaces
etc
Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_digitize_tab.php?view=diff&rev=93&p1=trunk/mapbender/http/javascripts/mod_digitize_tab.php&p2=trunk/mapbender/http/javascripts/mod_digitize_tab.php&r1=92&r2=93
==============================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php (original)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php 2006-04-19 13:21:54+0000
@@ -1,1643 +1,1873 @@
-<?php
-#$Id: mod_digitize_tab.php,v 1.39 2006/04/07 15:48:13 c_baudson Exp $
-#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_digitize_tab.php,v 1.39 2006/04/07 15:48:13 c_baudson Exp $
-# Copyright (C) 2002 CCGIS
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-session_start();
-import_request_variables("PG");
-require_once("../php/mb_validateSession.php");
-require_once("../../conf/mapbender.conf");
-$con = db_connect($DBSERVER,$OWNER,$PW);
-db_select_db(DB,$con);
-$gui_id = $_SESSION["mb_user_gui"];
-?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
- <html>
- <head>
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="expires" content="0">
- <?php
- echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';
- ?>
- <title>Digitize</title>
- <?php
- include '../include/dyn_css.php';
-
-
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db(DB,$con);
- $sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'digitize' AND fkey_gui_id = '".$gui_id."'";
- $res = db_query($sql);
- $cnt = 0;
- while($row = db_fetch_array($res)){
- $e_src = $row["e_src"];
- $e_target = explode(",",$row["e_target"]);
- $cnt++;
- }
- if($cnt > 1){ echo "alert('digitize_button: ID not unique!');";}
-# echo $e_target[0] . "<br>";
-# echo $e_target[1];
- echo "<script language='JavaScript'>";
- echo "var mod_digitize_target = '".$e_target[0]."';";
- echo "var mod_digitize_frame = '".$e_target[1]."';";
-
-?>
-
-// var mod_digitize_status = 0;
-
- //public
-
- var mod_digitize_color1 = "white";
- var mod_digitize_color2 = "black";
- var mod_digitize_font = "Arial, Helvetica, sans-serif";
- var mod_digitize_fontsize = "9px";
- var mod_digitize_basepoint = "#8a2be2";
- var mod_digitize_linepoint = "#ff00ff";
- var mod_digitize_bg = "";
-
- var mod_digitize_elName = "digitize";
- var mod_digitize_frameName = "";
-
- var wfsWindow;
-
-
- var snappingCoordinates = new Array();
- var snappingTolerance = 12;
- var snappedMember = -1;
- var snappedGeometry = -1;
- var snappedPoint = -1;
- var snapped = false;
-
- // canvas contains circles around snapping target
- var canvas = new Array();
-
- var wfs_conf = new Array();
-
- var D = new Array();
-
- var activeButton = null; // contains id of active button
- var isOn = true;
- var mod_digitize_width;
- var mod_digitize_height;
- var mod_digitize_Dist = new Array();
- var mod_digitize_TotalDist = new Array();
- var mod_digitizeSubFunctions = new Array();
- var mod_digitizeEvent = false;
-
- //currently selected basepoint
- var basepointObject = false;
-
- // stores the number of geometries in the geometry list
- var numberOfGeometries = 0;
-
- //indices of the geometry associated with a certain basepoint
- var basepointMemberIndex = false;
- var basepointGeometryIndex = false;
- var basepointPointIndex = false;
-
- //when a basepoint is being dragged, the coordinates are stored
- var basepointDragActive = false;
- var basepointDragStartX = false;
- var basepointDragStartY = false;
- var basepointDragEndX = false;
- var basepointDragEndY = false;
-
- //indices of the geometry that is currently built
- var currentMemberIndex = -1;
- var currentGeometryIndex = -1;
-
-
-
- var canvas = new Array();
-
-
-
- // ------------------------------------------------------------------------------------------------------------------------
- // --- registered functions (begin) ---------------------------------------------------------------------------------------
-
- //
- // this method is called onload. these functions will be invoked whenever they are triggered by the mapObj
- //
- function registerFunctions(){
- parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].setStyleForTargetFrame()");
- parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].checkTag()");
- parent.mb_registerSubFunctions("window.frames['"+ mod_digitize_elName + "'].drawDashedLine()");
- }
-
- //
- // checks if a div tag with id "digitize" exists in frame mod_digitize_target.
- // if yes, these element's attributes are set and itself is returned
- // if not, it is created (with attributes) and returned
- // if an element with id "digitize" exists and it is not a div tag, false is returned
- //
- function checkTag () {
- var attributes = new Array();
- attributes[0] = new Array();
- attributes[0][0] = "style";
- attributes[0][1] = "position:absolute; top:0px; left:0px; z-index:26; font-size:10px";
- node = parent.mb_checkTag(mod_digitize_target, "div", "digitize", "body", attributes);
- if (node == false) {
- alert("Fatal error: Element id 'digitize' is already taken!");
- }
- }
-
- //
- // this adds the stylesheet to the map frame
- //
- function setStyleForTargetFrame() {
- var cssLink = parent.window.frames[mod_digitize_target].document.createElement("link");
- cssLink.setAttribute("href", cssUrl);
- cssLink.setAttribute("type", "text/css");
- cssLink.setAttribute("rel", "stylesheet");
- var cssTmp = parent.window.frames[mod_digitize_target].document.getElementsByTagName("head")[0];
- cssTmp.appendChild(cssLink);
- }
-
- // --- registered functions (end) -----------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------
-
-/*
- function const_D(id,type){
- this.id = id;
- this.type = type;
- this.x = new Array();
- this.y = new Array();
- this.label = "";
-
- var ind = parent.getMapObjIndexByName(mod_digitize_target);
- this.epsg = parent.mb_mapObj[ind].epsg;
- this.units = "";
- this.dist = new Array();
- this.totaldist = new Array();
- this.complete = false;
- }
-*/
-
-
- // ------------------------------------------------------------------------------------------------------------------------
- // --- preload images (begin) ---------------------------------------------------------------------------------------------
-
- // up
- var digitize_point_up = new Image(); digitize_point_up.src = "../img/button_digitize/text_up.png";
- var digitize_line_up = new Image(); digitize_line_up.src = "../img/button_digitize/line_up.png";
- var digitize_poly_up = new Image(); digitize_poly_up.src = "../img/button_digitize/poly_up.png";
- var digitize_move_up = new Image(); digitize_move_up.src = "../img/button_digitize/move_up.png";
- var digitize_addNode_up = new Image(); digitize_addNode_up.src = "../img/button_digitize/newNode_up.png";
- var digitize_delNode_up = new Image(); digitize_delNode_up.src = "../img/button_digitize/delNode_up.png";
- // down
- var digitize_point_down = new Image(); digitize_point_down.src = "../img/button_digitize/text_down.png";
- var digitize_line_down = new Image(); digitize_line_down.src = "../img/button_digitize/line_down.png";
- var digitize_poly_down = new Image(); digitize_poly_down.src = "../img/button_digitize/poly_down.png";
- var digitize_move_down = new Image(); digitize_move_down.src = "../img/button_digitize/move_down.png";
- var digitize_addNode_down = new Image(); digitize_addNode_down.src = "../img/button_digitize/newNode_down.png";
- var digitize_delNode_down = new Image(); digitize_delNode_down.src = "../img/button_digitize/delNode_down.png";
-
- // --- preload images (end) -----------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------
-
-
- // ------------------------------------------------------------------------------------------------------------------------
- // --- button handling (begin) --------------------------------------------------------------------------------------------
-
- function register_button(obj) {
- parent.mb_regButton_frame("init_digitize_button", obj, mod_digitize_elName);
- }
-
- function init_digitize_button(obj, ind){
- parent.mb_button[ind] = obj;
- parent.mb_button[ind].img_over = obj.src;
-
- if (obj.id == "dragBasePoint") {
- parent.mb_button[ind].img_on = digitize_move_down.src;
- parent.mb_button[ind].img_off = digitize_move_up.src;
- }
- else if (obj.id == "setBasePoint"){
- parent.mb_button[ind].img_on = digitize_addNode_down.src;
- parent.mb_button[ind].img_off = digitize_addNode_up.src;
- }
- else if (obj.id == "delBasePoint"){
- parent.mb_button[ind].img_on = digitize_delNode_down.src;
- parent.mb_button[ind].img_off = digitize_delNode_up.src;
- }
- else if (obj.id == "Point"){
- parent.mb_button[ind].img_on = digitize_point_down.src;
- parent.mb_button[ind].img_off = digitize_point_up.src;
- }
- else if (obj.id == "Line"){
- parent.mb_button[ind].img_on = digitize_line_down.src;
- parent.mb_button[ind].img_off = digitize_line_up.src;
- }
- else if (obj.id == "Polygon"){
- parent.mb_button[ind].img_on = digitize_poly_down.src;
- parent.mb_button[ind].img_off = digitize_poly_up.src;
- }
- parent.mb_button[ind].status = 0;
- parent.mb_button[ind].elName = obj.id;
- parent.mb_button[ind].fName = "";
- parent.mb_button[ind].go = new Function ("digitize_click(parent.mb_button["+ind+"])");
- parent.mb_button[ind].stop = new Function ("digitize_disable(parent.mb_button["+ind+"])");
- }
-
- function digitize_click(obj) {
- if (obj.id == "dragBasePoint") {
- activeButton = obj.id;
- setEvent(obj);
- }
- else if (obj.id == "setBasePoint"){
- activeButton = obj.id;
- setEvent(obj);
- }
- else if (obj.id == "delBasePoint"){
- activeButton = obj.id;
- setEvent(obj);
- }
- else if (obj.id == "Point"){
- activeButton = obj.id;
- obj.title = "Finish editing";
- currentMemberIndex = -1;
- registerGeometry(obj);
- storeSnappingCoordinates();
- var el = parent.frames[mod_digitize_target].document;
- el.onmousemove = mod_digitize_go;
- }
- else if (obj.id == "Line"){
- activeButton = obj.id;
- obj.title = "Finish editing";
- currentMemberIndex = -1;
- registerGeometry(obj);
- storeSnappingCoordinates();
- var el = parent.frames[mod_digitize_target].document;
- el.onmousemove = mod_digitize_go;
- }
- else if (obj.id == "Polygon"){
- activeButton = obj.id;
- obj.title = "Finish editing";
- currentMemberIndex = -1;
- registerGeometry(obj);
- storeSnappingCoordinates();
- var el = parent.frames[mod_digitize_target].document;
- el.onmousemove = mod_digitize_go;
- }
- }
-
- function digitize_disable(obj) {
- if (obj.id == "dragBasePoint") {
- }
- else if (obj.id == "setBasePoint"){
- }
- else if (obj.id == "delBasePoint"){
- }
- else if (obj.id == "Point"){
- activeButton = null;
- obj.title = "Add point";
- closeGeometry(obj.id);
- mod_digitize_timeout();
- }
- else if (obj.id == "Line"){
- activeButton = null;
- obj.title = "Add line";
- closeGeometry(obj.id);
- mod_digitize_timeout();
- }
- else if (obj.id == "Polygon"){
- activeButton = null;
- obj.title = "Add polygon";
- closeGeometry(obj.id);
- mod_digitize_timeout();
- }
- }
-
- // --- button handling (end) ----------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------
-
-
- var dwin = null;
-
- function mod_saveGeom() {
- dwin = window.open("../php/mod_wfs_save.php","dwin","width=300,height=200");
- }
-
-
-
- // ------------------------------------------------------------------------------------------------------------------------
- // --- snapping (begin) ----------------------------------------------------------------------------------------------
-
- //
- // deletes all snapping areas from the canvas
- //
- function cleanCanvas () {
- var el = parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw');
- if (el) el.innerHTML = "";
- }
-
- //
- // checks if the canvas for snapping areas is present
- // if not, it is being generated
- //
- function checkCanvasTag () {
- var isTag = (parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw'))?1:0;
- if(isTag == 0){
- var draw = parent.window.frames[mod_digitize_target].document.createElement("div");
- var tmp = parent.window.frames[mod_digitize_target].document.getElementsByTagName("body")[0].appendChild(draw);
- tmp.setAttribute("id","mod_digi_draw");
- tmp.setAttribute("style","position:absolute;top:0px;left:0px;width:0px;height:0px;z-index:100");
- }
- canvas[mod_digitize_target] = new parent.jsGraphics('mod_digi_draw', parent.window.frames[mod_digitize_target]);
- canvas[mod_digitize_target].setStroke(3);
- }
-
- //
- // draws a snapping area around a given point
- //
- function drawSnappingArea (centerX,centerY,radius,size) {
- canvas[mod_digitize_target].setColor("#ff0000");
- canvas[mod_digitize_target].drawEllipse(centerX-(size/2)*radius,centerY-(size/2)*radius,size*radius,size*radius);
- canvas[mod_digitize_target].paint();
- }
-
- //
- // stores the coordinates of points that may be used for snapping
- // in respect to the current point (the point being moved or inserted)
- //
- function storeSnappingCoordinates() {
- snappingCoordinates = new Array();
-
- // copy coordinates of other geometries in another array
- var im = -1;
-
- var cnt = 0;
- for (var i = 0; i < D.length ; i++) {
- for (var j = 0 ; j < D[i]['geometry'].length ; j++) {
- for (var k = 0 ; k < D[i]['geometry'][j]['x'].length ; k++) {
- var pos = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k], D[i]['geometry'][j]['y'][k]);
-
- // snap only if the two points have different coordinates
- if (basepointDragActive == false || basepointDragActive == true && (D[i]['geometry'][j]['x'][k] != D[basepointMemberIndex]['geometry'][basepointGeometryIndex]['x'][basepointPointIndex] || D[i]['geometry'][j]['y'][k] != D[basepointMemberIndex]['geometry'][basepointGeometryIndex]['y'][basepointPointIndex])) {
-
- snappingCoordinates[cnt] = new Array();
- snappingCoordinates[cnt]['map_x'] = pos[0];
- snappingCoordinates[cnt]['map_y'] = pos[1];
- snappingCoordinates[cnt]['member'] = i;
- snappingCoordinates[cnt]['geometry'] = j;
- snappingCoordinates[cnt]['point'] = k;
- cnt++;
- }
- }
- }
- }
- return false;
- }
-
-
- //
- // checks if a point is in snapping range
- // if yes, the snapping area is highlighted and the snapped point is stored
- //
- function checkSnapped (basepointDragEndX, basepointDragEndY, defaultMouseCursor) {
-
- var minDist = false;
- var min_i = -1;
- for (var i = 0 ; i < snappingCoordinates.length ; i++) {
- var aDist = dist(basepointDragEndX, basepointDragEndY, snappingCoordinates[i]['map_x'], snappingCoordinates[i]['map_y']);
- if (aDist < snappingTolerance) {
- if (minDist == false || aDist < minDist) {
- minDist = aDist;
- snappedMember = snappingCoordinates[i]['member'];
- snappedGeometry = snappingCoordinates[i]['geometry'];
- snappedPoint = snappingCoordinates[i]['point'];
- min_i = i;
- }
- }
- }
-
- if (minDist == false || minDist > snappingTolerance) {
- snapped = false;
- var el = parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw');
- if (el) el.innerHTML = "";
- }
- else {
- snapped = true;
-
- checkCanvasTag();
- cleanCanvas();
- drawSnappingArea(snappingCoordinates[min_i]['map_x'], snappingCoordinates[min_i]['map_y'], snappingTolerance, 3);
- }
-
- if (basepointObject != false) {
- if (snapped == true) {
- basepointObject.style.cursor = 'crosshair';
- }
- else {
- basepointObject.style.cursor = defaultMouseCursor;
- }
-
- if (defaultMouseCursor == 'move') {
- // replace basepoint by transparent blob
- basepointObject.style.width = mod_digitize_width;
- basepointObject.style.height = mod_digitize_height;
- basepointObject.style.left = 0;
- basepointObject.style.top = 0;
-
- if (parent.ie) {
- // ie cannot handle backgroundColor = 'transparent'
- basepointObject.style.background = "url(/../img/button_digitize/trans.png)";
- }
- else{
- basepointObject.style.backgroundColor = 'transparent';
- }
- }
- }
- }
-
- // --- snapping (end) ----------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------
-
- function mod_digitize_go(e){
- parent.mb_registerGML(mod_digitize_target,D);
- parent.document.getElementById(mod_digitize_elName).style.visibility = 'visible';
-
- // track mouse position
- parent.mb_getMousePos(e, mod_digitize_target);
- checkSnapped(parent.clickX, parent.clickY, 'default');
-
- var el = parent.frames[mod_digitize_target].document;
- el.onmousedown = mod_digitize_start;
- //el.onmousemove = mod_digitize_run;
-
- var ind = parent.getMapObjIndexByName(mod_digitize_target);
- mod_digitize_width = parent.mb_mapObj[ind].width;
- mod_digitize_height = parent.mb_mapObj[ind].height;
- mod_digitize_epsg = parent.mb_mapObj[ind].epsg;
- }
-
-
- function mod_digitize_timeout(){
-// isOn = false;
-// parent.document.getElementById(mod_digitize_elName).style.visibility = 'hidden';
- var el = parent.frames[mod_digitize_target].document;
- el.onmousedown = null;
- el.onmouseup = null;
- el.onmousemove = null;
-// drawDashedLine();
- }
-
-
- //
- // a new member is being generated and attached to the array D
- //
- function registerGeometry(type){
-
- // a new geometry will be inserted
- if (currentMemberIndex == -1) {
- currentMemberIndex = D.length;
-
- // generate a new member
- D[currentMemberIndex] = new Array();
- D[currentMemberIndex]['geometry'] = new Array();
- D[currentMemberIndex]['element'] = new Array();
- D[currentMemberIndex]['wfs_conf'] = -1;
- D[currentMemberIndex]['geomtype'] = type.id;
-
- // attach a new geometry
- var geomInd = D[currentMemberIndex]['geometry'].length;
- D[currentMemberIndex]['geometry'][geomInd] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['x'] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['y'] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['complete'] = false;
-
- currentGeometryIndex = 0;
- }
- // a geometry will be added to an existing geometry
- else {
-
- // FIXME: check if geometry types match
-
- // attach a new geometry
- var geomInd = D[currentMemberIndex]['geometry'].length;
- D[currentMemberIndex]['geometry'][geomInd] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['x'] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['y'] = new Array();
- D[currentMemberIndex]['geometry'][geomInd]['complete'] = false;
-
- currentGeometryIndex = geomInd;
- }
- }
-
- //
- // adds a new basepoint to the geometry
- //
- function mod_digitize_start(e){
- isOn = true;
-
- if (currentMemberIndex != -1) {
-
- // select the last geometry of the current member
- var geomInd = D[currentMemberIndex]['geometry'].length - 1;
-
- // check if a proper geometry is selected
- if(D[currentMemberIndex]['geometry'][geomInd]['complete'] == true || (D.length == 0)){
-
- if (activeButton != null) {
- alert("No geometry selected!");
- }
- return true;
- }
-
- // get the mouse position and calculate real world position
- if (snapped == true) {
- cleanCanvas();
-
- var realWorldPos = new Array();
- realWorldPos[0] = D[snappedMember]['geometry'][snappedGeometry]['x'][snappedPoint];
- realWorldPos[1] = D[snappedMember]['geometry'][snappedGeometry]['y'][snappedPoint];
-
- }
- else {
- parent.mb_getMousePos(e,mod_digitize_target);
- var realWorldPos = parent.makeClickPos2RealWorldPos(mod_digitize_target,parent.clickX,parent.clickY);
- }
- snapped = false;
-
- if (D[currentMemberIndex]['geomtype'].toLowerCase() == 'polygon'
- && D[currentMemberIndex]['geometry'][geomInd]['x'].length > 1
- && D[currentMemberIndex]['geometry'][geomInd]['x'][0] == realWorldPos[0]
- && D[currentMemberIndex]['geometry'][geomInd]['y'][0] == realWorldPos[1]) {
-
- // close the polygon
- parent.mb_disableThisButton('Polygon');
- }
- else {
- // set the calculated real world position as point of the geometry
- xInd = D[currentMemberIndex]['geometry'][geomInd]['x'].length;
- yInd = D[currentMemberIndex]['geometry'][geomInd]['y'].length;
- D[currentMemberIndex]['geometry'][geomInd]['x'][xInd] = realWorldPos[0];
- D[currentMemberIndex]['geometry'][geomInd]['y'][yInd] = realWorldPos[1];
-
- // if the current geometry is a point, attach a label to it
- if(D[currentMemberIndex]['geomtype'].toLowerCase() == 'point'){
- parent.mb_disableThisButton('Point');
- }
-
- // add first point of polygon to snapping list (if three points have been inserted).
- if (D[currentMemberIndex]['geomtype'].toLowerCase() == 'polygon'
- && D[currentMemberIndex]['geometry'][geomInd]['x'].length == 3) {
- var tempInd = snappingCoordinates.length;
- var pos = parent.makeRealWorld2mapPos(mod_digitize_target, D[currentMemberIndex]['geometry'][geomInd]['x'][0], D[currentMemberIndex]['geometry'][geomInd]['y'][0]);
- snappingCoordinates[tempInd] = new Array();
- snappingCoordinates[tempInd]['map_x'] = pos[0];
- snappingCoordinates[tempInd]['map_y'] = pos[1];
- snappingCoordinates[tempInd]['member'] = currentMemberIndex;
- snappingCoordinates[tempInd]['geometry'] = geomInd;
- snappingCoordinates[tempInd]['point'] = 0;
- }
- }
- drawDashedLine();
- }
-
- return true;
- }
-
- //
- // finishes a geometry by labelling it complete.
- // if no coordinates have been added, the geometry is discarded.
- //
- // when a polygon is built and the polygon button is clicked again, the
- // polygon will be closed by connecting the last to the first point.
- // Actually, the first point is stored twice at index '0' and index 'length'
- //
- function closeGeometry(obj_id){
- var i = currentMemberIndex;
- var j = currentGeometryIndex;
-
- if(!isOn){ return; };
-
- D[i]['geometry'][j]['complete'] = true;
-
- var tmpLength = D[i]['geometry'][j]['x'].length;
-
- // if no geometries have been inserted, delete the geometry or member
- if (tmpLength == 0) {
- if (j == 0) {
- D.length--;
- }
- else {
- D[i]['geometry'].length--;
- }
- }
- if (obj_id == "Polygon") {
- if (tmpLength > 0) {
- D[i]['geometry'][j]['x'][tmpLength] = D[i]['geometry'][j]['x'][0];
- D[i]['geometry'][j]['y'][tmpLength] = D[i]['geometry'][j]['y'][0];
- }
- }
- drawDashedLine();
- }
-
- //
- // displays *all* digitized geometries
- //
- function drawDashedLine(){
- 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>";
-
- // *all* members will be painted
- for(var i=0; i<D.length; i++){
-
- // paint all geometries of member i
- for(var j=0; j<D[i]['geometry'].length; j++){
- //
- // paint the basepoints
- //
- for(var k=0; k<D[i]['geometry'][j]['x'].length; k++){
- // calculate screen position from real world coordinates
- var pos = parent.makeRealWorld2mapPos(mod_digitize_target,D[i]['geometry'][j]['x'][k],D[i]['geometry'][j]['y'][k]);
-
- // if this geometry is a point
- if(D[i]['geomtype'].toLowerCase() == "point"){
- // smP += "<div class='label' style='top:"+(pos[1]-6)+"px;left:"+(pos[0])+"px;z-index:50;'>"+D[i]['label']+"</div>";
- }
-
- smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:50;'";
- if(j==0 && D[i]['geomtype'].toLowerCase() == 'polygon' && D[i]['geometry'][j]['complete'] == false){
- smP += " title='to close polygon, release the polygon button on the left' ";
- }
- if(isOn){
- smP += " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
- }
- smP += "></div>";
- }
- //
- // paint the lines between basepoints
- //
- for(var k = 1; k < D[i]['geometry'][j]['x'].length; k++){
-
- var pos0 = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k] , D[i]['geometry'][j]['y'][k]);
- var pos1 = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k-1], D[i]['geometry'][j]['y'][k-1]);
-
- smP += evaluateDashes(pos1[0], pos1[1], pos0[0], pos0[1], i, j, k);
- }
- }
- }
- parent.writeTag(mod_digitize_target,"digitize",smP);
- updateListOfGeometries();
- }
-
-
- //
- // this function calculates the line points between start and end
- //
- function evaluateDashes(startX, startY, endX, endY, memberIndex, geomIndex, pointIndex){
- var str_dashedLine = "";
- var deltaX = endX - startX;
- var deltaY = endY - startY;
-
- // s = distance between two linepoints
- var s = 10;
- var vecLength = dist(startX, startY, endX, endY);
- var n = Math.round(vecLength/s);
- var stepX = deltaX/n;
- var stepY = deltaY/n;
- for(var i=1; i<n; i++){
- var x = Math.round(startX + i * stepX) - 2;
- var y = Math.round(startY + i * stepY) - 2;
- if(x >= 0 && x <= mod_digitize_width && y >= 0 && y <= mod_digitize_height){
- str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:50;' ";
- if(isOn){
- str_dashedLine += "onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].convertLinepointToBasepoint(this,"+memberIndex+","+geomIndex+","+pointIndex+")'>";
- }
- str_dashedLine += "</div>";
- }
- }
- return str_dashedLine;
- }
-
-
- // ------------------------------------------------------------------------------------------------------------------------
- // --- basepoint handling (begin) -----------------------------------------------------------------------------------------
-
- //
- // this function checks what to do with a basepoint that is currently under
- // the mouse pointer.
- // Depending on what action is intended, other methods are invoked.
- //
-
- function handleBasepoint(Obj,memberIndex,geometryIndex,pointIndex){
- if(!isOn){ return false; };
-
- // set the global variables that will be used in deleteBasepoint etc.
- basepointObject = Obj;
- basepointMemberIndex = memberIndex;
- basepointGeometryIndex = geometryIndex;
- basepointPointIndex = pointIndex;
-
- if(mod_digitizeEvent == "dragBasePoint" && activeButton == 'dragBasePoint'){
- mod_digitize_timeout();
- basepointObject.style.cursor = 'move';
- basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].selectBasepoint;
- }
-/*
- if(mod_digitizeEvent == false && D[memberIndex]['geomtype'].toLowerCase() == 'polygon' && D[memberIndex]['geometry'][geometryIndex].complete == false){
- basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].closeGeometry("Polygon");
- }
-*/
- if(mod_digitizeEvent == "delBasePoint" && activeButton == 'delBasePoint'){
- mod_digitize_timeout();
- basepointObject.style.cursor = 'crosshair';
- basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].deleteBasepoint;
- }
- }
-
- function deleteBasepoint(e){
-
- var i = basepointMemberIndex;
- var j = basepointGeometryIndex;
- var k = basepointPointIndex;
-
- var xCoord = D[i]['geometry'][j]['x'][k];
- var yCoord = D[i]['geometry'][j]['y'][k];
-
- var deleted = false;
-
- while (deleted == false) {
- var continueFor = true;
- deleted = true;
-
- //find points of other geometries with the same coordinates and delete them as well
- for (var l = 0 ; l < D.length && continueFor == true; l ++) {
- for (var m = 0; m < D[l]['geometry'].length && continueFor == true; m++) {
- for (var n = 0; n < D[l]['geometry'][m]['x'].length && continueFor == true ; n++) {
- if (D[l]['geometry'][m]['x'][n] == xCoord && D[l]['geometry'][m]['y'][n] == yCoord) {
- deletePoint(l,m,n);
- continueFor = false;
- deleted = false;
- }
- }
- }
- }
- }
- }
-
- //
- // deletes the point at the i-th member, j-th geometry, k-th point
- //
- function deletePoint (i,j,k) {
- //
- // the last point is being deleted...
- //
- if ( (k == 0 || (D[i]['geometry'][j]['x'].length - k) == 1) && D[i]['geomtype'].toLowerCase() == 'polygon') {
- // if the last basepoint of a polygon is being deleted,
- // the first basepoint is now set to be the last but one as well,
- // in order to close the polygon
-
- // Shorten the array by one
- D[i]['geometry'][j]['x'].length = D[i]['geometry'][j]['x'].length - 1;
- D[i]['geometry'][j]['y'].length = D[i]['geometry'][j]['y'].length - 1;
-
- // if only one point is left (which has been stored twice), remove it as well
- if (D[i]['geometry'][j]['x'].length == 1) {
- D[i]['geometry'][j]['x'].length = 0;
- D[i]['geometry'][j]['y'].length = 0;
- }
- // point that will be deleted is not the only point of the geometry
- else {
-
- // place a copy of the last point at index 0
- var tmpIndex = D[i]['geometry'][j]['x'].length - 1;
- D[i]['geometry'][j]['x'][0] = D[i]['geometry'][j]['x'][tmpIndex];
- D[i]['geometry'][j]['y'][0] = D[i]['geometry'][j]['y'][tmpIndex];
- }
- }
- //
- // a point that is *not* the last point of a geometry is being deleted
- //
- else {
-
- // move basepoints behind deleted basepoints up by one...
- for(var z= k; z<D[i]['geometry'][j]['x'].length-1; z++){
- D[i]['geometry'][j]['x'][z] = D[i]['geometry'][j]['x'][z+1];
- D[i]['geometry'][j]['y'][z] = D[i]['geometry'][j]['y'][z+1];
- }
- // ...and adjust length of the array
- D[i]['geometry'][j]['x'].length = D[i]['geometry'][j]['x'].length - 1;
- D[i]['geometry'][j]['y'].length = D[i]['geometry'][j]['y'].length - 1;
- }
-
- //
- // if all basepoints of this geometry have been deleted...
- //
-
- if (D[i]['geometry'][j]['x'].length == 0) {
- deleteGeometry(i, j);
- }
- else {
- drawDashedLine();
- //resetButtonsIfNoMembersLeft();
- }
- }
-
- //
- // deletes the geometry at index 'indexGeometry' of member at index 'indexmember' of D
- //
- function deleteGeometry (indexMember, indexGeometry) {
- var i = indexMember;
- var j = indexGeometry;
-
- //
- // check whether the deleted geometry is the only geometry of the member...
- //
- if (D[i]['geometry'].length == 1) {
- deleteMember(i);
- }
- //
- // ...if not, move other geometries one spot up
- //
- else {
- var tmpLength = D[i]['geometry'].length - 1;
- for (var z = j; z < tmpLength ; z ++) {
- D[i]['geometry'][z] = D[i]['geometry'][z+1];
- D[i]['element'][z] = D[i]['element'][z+1];
- }
- D[i]['geometry'].length -= 1;
-
- drawDashedLine();
- resetButtonsIfNoMembersLeft();
- }
- }
-
- //
- // deletes the member of D at index 'index''
- //
- function deleteMember (index) {
- // delete geometry itself...
- for(var z = index ; z < D.length - 1; z++){
- D[z] = D[z+1];
- }
- // ... and adjust length of geometry array
- D.length -= 1;
-
- drawDashedLine();
- }
-
-
- //
- // this function is invoked when the mouse is over a linepoint.
- // When the mouse is clicked, the method insert basepoint is
- // called.
- //
- function convertLinepointToBasepoint(obj, memberIndex, geomIndex, pointIndex){
- if(!isOn){ return false; };
-
- if(mod_digitizeEvent == "setBasePoint" && activeButton == 'setBasePoint'){
- mod_digitize_timeout();
- obj.style.cursor = 'crosshair';
- obj.onclick = insertBasepoint;
-
- basepointObject = obj;
- basepointMemberIndex = memberIndex;
- basepointGeometryIndex = geomIndex;
- basepointPointIndex = pointIndex;
- }
- }
-
- //
- // this function inserts a new basepoint into the geometry.
- // the basepoint is a former linepoint.
- //
- function insertBasepoint(e){
- var i = basepointMemberIndex;
- var j = basepointGeometryIndex;
- var k = basepointPointIndex;
-
- parent.mb_getMousePos(e, mod_digitize_target);
- var pos = parent.makeClickPos2RealWorldPos(mod_digitize_target,parent.clickX, parent.clickY);
-
- for(var z = D[i]['geometry'][j]['x'].length; z > k; z--){
- D[i]['geometry'][j]['x'][z] = D[i]['geometry'][j]['x'][z-1];
- D[i]['geometry'][j]['y'][z] = D[i]['geometry'][j]['y'][z-1];
- }
-
- D[i]['geometry'][j]['x'][k] = pos[0];
- D[i]['geometry'][j]['y'][k] = pos[1];
-
- drawDashedLine();
- }
-
- //
- // when a basepoint move is intended, this function is invoked when the mouse button
- // is pressed. It stores the start coordinates in a global variable and sets
- // the global basepointDragActive to true, so other modules know that a basepoint is
- // currently being dragged
- //
-
- function selectBasepoint(e){
- if(basepointDragActive == false && mod_digitizeEvent == "dragBasePoint"){
- basepointDragActive = true;
- storeSnappingCoordinates();
- basepointObject.onmouseup = releaseBasepoint;
- basepointObject.onmousemove = dragBasepoint;
- }
- }
-
- function dist (startX, startY, endX, endY) {
- var deltaX = endX - startX;
- var deltaY = endY - startY;
-
- return Math.sqrt(Math.pow(deltaY,2) + Math.pow(deltaX,2)) ;
- }
-
-
- //
- // when a basepoint is being dragged and the mouse button is down,
- // this function will track the mouse position.
- // instead of the basepoint, a transparent object the size of the
- // mapframe is being displayed
- //
- function dragBasepoint(e){
- if(basepointDragActive){
- parent.mb_getMousePos(e, mod_digitize_target);
- checkSnapped(parent.clickX, parent.clickY, 'move');
- }
- }
-
-
- //
- // checks if a geometry has identical neighbour points
- //
- function removeDuplicates(i, j) {
- var length1 = D[i]['geometry'][j]['x'].length;
- var continueFor = true;
- for (var k = 2; k < length1 && continueFor == true ; k++) {
- if (D[i]['geometry'][j]['x'][k] == D[i]['geometry'][j]['x'][k-1] && D[i]['geometry'][j]['y'][k] == D[i]['geometry'][j]['y'][k-1] ) {
- deletePoint(i,j,k-1);
- continueFor = false;
- }
- }
- }
-
-
- //
- // when a basepoint is being dragged and the mouse button is released,
- // this function is invoked and the geometry will be updated
- //
- function releaseBasepoint(e){
-
- var i = basepointMemberIndex;
- var j = basepointGeometryIndex;
- var k = basepointPointIndex;
-
- basepointDragActive = false;
-
- parent.mb_getMousePos(e, mod_digitize_target);
- basepointDragEndX = parent.clickX;
- basepointDragEndY = parent.clickY;
- basepointObject.onmousedown = null;
- var pos = parent.makeClickPos2RealWorldPos(mod_digitize_target, basepointDragEndX, basepointDragEndY);
-
- if (snapped == true) {
- cleanCanvas();
-
- pos[0] = D[snappedMember]['geometry'][snappedGeometry]['x'][snappedPoint];
- pos[1] = D[snappedMember]['geometry'][snappedGeometry]['y'][snappedPoint];
- }
-
- if ( (k == D[i]['geometry'][j]['x'].length - 1 || k == 0) && D[i]['geometry'][j]['complete'] == true && D[i]['geomtype'].toLowerCase() == 'polygon') {
- D[i]['geometry'][j]['x'][0] = pos[0];
- D[i]['geometry'][j]['y'][0] = pos[1];
- }
-
- // check if there are points in other geometries with the same coordinates
- for (var l = 0; l < D.length ; l++) {
- for (var m = 0 ; m < D[l]['geometry'].length ; m++) {
- for (n = 0 ; n < D[l]['geometry'][m]['x'].length ; n++) {
- if ((l != i || m != j) && D[i]['geometry'][j]['x'][k] == D[l]['geometry'][m]['x'][n] && D[i]['geometry'][j]['y'][k] == D[l]['geometry'][m]['y'][n]) {
- D[l]['geometry'][m]['x'][n] = pos[0];
- D[l]['geometry'][m]['y'][n] = pos[1];
- if (snapped == true) {
- removeDuplicates(l,m);
- }
- }
- }
- }
- }
-
- D[i]['geometry'][j]['x'][k] = pos[0];
- D[i]['geometry'][j]['y'][k] = pos[1];
- if (snapped == true) {
- removeDuplicates(i,j);
- }
-
- snapped = false;
- drawDashedLine();
- }
-
- // --- basepoint handling (end) -----------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------------------------------
-
-
- //
- // clones a given object
- //
-
- function cloneObject (someArray) {
- var a = someArray;
- var z = new Array();
-
- for (attr in a) {
- var b = a[attr];
-
- if (typeof(b) == "object") {
- z[attr] = cloneObject(b);
- }
- else {
- z[attr] = b;
- }
- }
- return z;
- }
-
-
- //
- // clones a given geometry array
- //
-
- function cloneGeometryArray(originalArray) {
- z = cloneObject(originalArray);
-
- // add the attribute 'complete' for every geometry
- for (var i = 0 ; i < originalArray['geometry'].length ; i ++) {
- z['geometry'][i]['complete'] = true;
- }
- return z;
- }
-
-
- //
- // a given geometry object is appended to the member array
- //
- function addMember(newMember) {
- var index = D.length;
- D[index] = new Array();
-
- D[index] = cloneGeometryArray(newMember);
-
- mod_digitize_go();
- drawDashedLine();
- }
-
-
- function setEvent(obj){
- mod_digitizeEvent = obj.id;
- }
-
- function delEvent(){
- mod_digitizeEvent = false;
- mod_digitize_go();
- }
-
- //
- // displays an object
- // (may not be essential, but useful for debugging)
- //
- function displayObject (someArray) {
- var a = someArray;
- var str = "";
-
- for (attr in a) {
- b = a[attr];
-
- if (typeof(b) == "object") {
- str += "<br>" + attr + "<br>";
- str += displayObject(b);
- }
- else {
- str += attr + ": " + b + "<br>";
- }
- }
- return str;
- }
-
- //
- // returns a form with the elements of a selected wfs
- // (if the original wfs is the selected wfs, the values are set too)
- //
- function buildElementForm (wfsConfIndex, memberIndex) {
- var selMember = memberIndex;
- // if the selected wfs is not the original wfs,
- // the form template, updating and deleting are disabled.
- if (parseInt(D[memberIndex]['wfs_conf']) != parseInt(wfsConfIndex)) {
- memberIndex = -1;
- }
-
- var str = "";
-
- // the wfs conf needs to have a gid and a geom, otherwise saving does not work
- var gid = false;
- var geom = false;
-
- var wfs = wfs_conf[wfsConfIndex];
-
- var memEl;
- if (parseInt(memberIndex) != -1) {
- memEl = D[memberIndex]['element'];
- }
-
- // search attribute 'element' in wfsConfArray
- for (attr in wfs) {
- if (attr == "element") {
- str += "<form id='wfs_conf'>\n\t<table>\n";
-
- b = wfs[attr];
-
- // get the 'element name' of wfsConfArray['element'][i]
- for (var i = 0 ; i < b.length ; i ++) {
- var c = b[i];
-
- var wfsElementName = c['element_name'];
-
- // don't display geoms
- if (parseInt(c['f_geom']) != 1) {
-
-
- if (parseInt(wfs['element'][i]['f_gid']) == 1) {
- gid = wfsElementName;
- }
-
- //
- // display the element name and an input row for its value
- //
- str += "\t\t<tr>\n\t\t\t<td>\n";
- str += "\t\t\t\t" + wfsElementName + "\n\t\t\t</td>\n\t\t\t<td colspan = 2>\n";
- str += "\t\t\t\t<input name='" + wfsElementName + "' type='text' size=20 ";
-
- // only if the selected wfs is the original wfs!
- if (parseInt(memberIndex) != -1) {
- //
- // get the 'element name' of memberArray['element'][j]
- //
- for (var j = 0 ; j < memEl.length ; j ++) {
- currentElementName = memEl[j]['name'];
- //
- // if the element is in both objects, display the value as default
- //
- if (currentElementName == wfsElementName) {
- str += "value = '" + memEl[j]['val'] + "' ";
- }
- }
- }
- str += ">\n";
- str += "\t\t\t</td>\n\t\t</tr>\n";
-
- }
- else {
- geom = wfsElementName;
- }
- }
-
- //
- // generating buttons "save", "update", "delete"
- //
-
- // a wfs_transaction url is required.
- if (wfs['wfs_transaction']) {
- str += "\t\t<tr>\n";
-
- // if not all buttons will be generated, the missing columns will be generated afterwards.
- var colspan = 0;
-
- if (geom) {
- str += "\t\t\t<td><input type='button' name='saveButton' value='Save' onclick='window.opener.saveGeom("+selMember+")' /></td>\n";
- }
- else {
- colspan++;
- }
- if (parseInt(memberIndex) != -1 && gid) {
- if (geom) {
- str += "\t\t\t<td><input type='button' name='updateButton' value='Update' onclick='window.opener.updateGeom("+selMember+")'/></td>\n";
- }
- else {
- colspan++;
- }
- str += "\t\t\t<td><input type='button' name='deleteButton' value='Delete' onclick='window.opener.deleteGeom("+selMember+")'/></td>\n";
- }
- else {
- colspan++;
- }
-
- if (colspan > 0 && colspan < 3) {
- str += "\t\t\t<td colspan = " + colspan + "></td>\n";
- }
-
- str += "\t\t</tr>";
- }
- str += "\t</table>\n";
-// str += "<input type='text' name='mb_geom'>";
-// str += "<input type='text' name='mb_wfs_conf'>";
- str += "</form>\n";
- }
- }
- return str;
- }
-
-
- //
- // this method opens a new window and displays the attributes in wfs_conf
- //
- function showWfs(index) {
-
- wfsWindow = open("", "wfsattributes", "width=300, height=300, resizable, dependent=yes, scrollbars=yes");
- wfsWindow.document.open("text/html");
- wfs_conf = parent.get_complete_wfs_conf();
- var str = "";
- var defaultIndex = -1;
-
- str += "<form id='wfs'>\n\t<select name='wfs' size='" + wfs_conf.length + "'";
- str += " onChange='document.getElementById(\"elementForm\").innerHTML = window.opener.buildElementForm(this.value , " + index + ")'";
- str += ">\n\t\t";
-
- for (var attr in wfs_conf) {
- str += "<option value='" + attr + "'";
-
- // if the geometry is already associated with a wfs
- if (parseInt(D[index]['wfs_conf']) == parseInt(attr)) {
- str += " selected";
- defaultIndex = parseInt(attr);
- }
- str += ">" + wfs_conf[attr]['wfs_conf_abstract'];
- str += "</option>\n\t\t";
-
- }
- str += "</select>\n\t\t</form>\n\t";
- str += "<div id='elementForm'>\n</div>\n";
-
- wfsWindow.document.write(str);
- wfsWindow.document.close();
-
- if (defaultIndex != -1) {
- wfsWindow.document.getElementById("elementForm").innerHTML = buildElementForm(defaultIndex, index);
- }
- }
-
-
-
- //
- // updates the list of geometries.
- // this function is invoked only at the end of drawDashedLines()
- //
- function updateListOfGeometries () {
- var listOfGeom = "";
-
- if (D.length > 0) {
- listOfGeom += "<table>\n";
- }
-
- for (var i = 0 ; i < D.length; i ++) {
- listOfGeom += "\t<tr>\n";
- listOfGeom += "\t\t<td>\n";
- listOfGeom += "\t\t\t<img src = '../img/button_digitize/geomInfo.png' title='WFS conf' onclick='showWfs("+i+")'>\n";
- listOfGeom += "\t\t</td>\n";
- listOfGeom += "\t\t<td>\n";
- listOfGeom += "\t\t\t<img src = '../img/button_digitize/geomRemove.png' title='delete this " + D[i]['geomtype'] + "' onclick='deleteMember("+i+")'>\n";
- listOfGeom += "\t\t</td>\n";
- listOfGeom += "\t\t<td style = 'color:blue'>\n";
- listOfGeom += "\t\t\t<div onmouseover='parent.mb_wfs_perform(\"over\",D["+i+"])' ";
- listOfGeom += " onmouseout='parent.mb_wfs_perform(\"out\",D["+i+"])' ";
-
- // if a geometry is a wfs result -> zoom to geometry
-
- if (D[i]['wfs_conf'] != -1) {
- listOfGeom += " onclick='parent.mb_wfs_perform(\"click\",D["+i+"]);' ";
- }
- // ... a geometry has been digitized by hand -> zoom to first point (FIXME: zooming to the entire geometry would be better)
- else{
- listOfGeom += " onclick='parent.zoom(mod_digitize_target,\"true\", 1.0, " + D[i]['geometry'][0]['x'][0] + ", " + D[i]['geometry'][0]['y'][0] + ");' ";
- }
- var geomName = parent.getElementValueByName(D, i, "name");
- if (!geomName) {
- geomName = "new";
- }
- var suffix = " ";
- if (D[i]['geomtype'] == "Polygon") {
- suffix += "(Py)";
- }
- else if (D[i]['geomtype'] == "Line") {
- suffix += "(Li)";
- }
- if (D[i]['geomtype'] == "Point") {
- suffix += "(Pt)";
- }
-
- listOfGeom += ">" + geomName + suffix +"</div>";
- listOfGeom += "\t\t</td>\n";
- }
-
- if (D.length > 0) {
- listOfGeom += "</table>\n";
- }
- parent.writeTag(mod_digitize_elName,"listOfGeometries",listOfGeom);
- }
-function saveGeom(m){
- var myform = wfsWindow.document.forms[0];
- var ind = myform.wfs.selectedIndex;
- var wfs = myform.wfs.options[ind].value;
- myform = wfsWindow.document.forms[1];
- D[m]['wfs_conf'] = wfs;
- D[m]['element'] = new Array();
- D[m]['element']['name'] = new Array();
- D[m]['element']['val'] = new Array();
- var cnt = 0;
- for( var i=0; i<myform.length; i++){
- if(myform.elements[i].type == 'text'){
- D[m]['element'][cnt] = new Array();
- D[m]['element'][cnt]['name'] = myform.elements[i].name;
- D[m]['element'][cnt]['val'] = myform.elements[i].value;
- cnt++;
- }
- }
-// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
- var myconf = wfs_conf[D[m]['wfs_conf']];
- document.sendForm.url.value = myconf['wfs_transaction'];
- var str = '<wfs:Transaction version="1.0.0" service="WFS" xmlns="http://www.someserver.com/myns" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd" xmlns:topp="http://www.someserver.com/topp">';
- str += '<wfs:Insert>';
- str += '<'+ myconf['featuretype_name']+'>';
- for(var i=0; i<D[m]['element'].length; i++){
- if(D[m]['element'][i]['val'] != ""){
- var tmp = D[m]['element'][i]['name'];
- str += '<' + tmp + '>';
- str += D[m]['element'][i]['val'];
- str += '</' + tmp + '>';
- }
- }
- for(var j=0; j<myconf['element'].length; j++){
- if(myconf['element'][j]['f_geom'] == 1){
- var el_geom = myconf['element'][j]['element_name'];
- }
- }
- str += '<' + el_geom + '>';
-
-// if(dig.D[0].type == 'text'){
-// str += '<gml:Point srsName="epsg:4326">';
-// str += '<gml:coordinates>';
-// str += dig.D[0].x[0] + "," + dig.D[0].y[0];
-// str += '</gml:coordinates>';
-// str += '</gml:Point>';
-// }
-// if(dig.D[0].type == 'line'){
-// str += '<gml:MultiLineString srsName="epsg:4326">';
-// str += '<gml:lineStringMember>';
-// str += '<gml:LineString>';
-//
-// str += '<gml:coordinates>';
-// for(var k=0; k<dig.D[0].x.length; k++){
-// if(k>0){
-// str += " ";
-// }
-// str += dig.D[0].x[k] + "," + dig.D[0].y[k];
-// }
-// str += '</gml:coordinates>';
-// str += '</gml:LineString>';
-// str += '</gml:lineStringMember>';
-// str += '</gml:MultiLineString>';
-// }
- if(D[m]['geomtype'] == 'Polygon'){
- str += '<gml:MultiPolygon srsName="epsg:4326">';
- str += '<gml:polygonMember>';
- str += '<gml:Polygon>';
- str += '<gml:outerBoundaryIs>';
- str += '<gml:LinearRing>';
-
- str += '<gml:coordinates>';
- for(var k=0; k<D[m]['geometry'][0]['x'].length; k++){
- if(k>0){
- str += " ";
- }
- str += D[m]['geometry'][0]['x'][k] + "," + D[m]['geometry'][0]['y'][k];
- }
- str += '</gml:coordinates>';
- str += '</gml:LinearRing>';
- str += '</gml:outerBoundaryIs>';
- str += '</gml:Polygon>';
- str += '</gml:polygonMember>';
- str += '</gml:MultiPolygon>';
- }
- str += '</' + el_geom + '>';
- str += '</'+ myconf['featuretype_name']+'>';
- str += '</wfs:Insert>';
- str += '</wfs:Transaction>';
- document.forms[1].filter.value = str;
- document.forms[1].submit();
- return false;
-}
-function updateGeom(m){
- var myid_value;
- var myform = wfsWindow.document.forms[0];
- var ind = myform.wfs.selectedIndex;
- var wfs = myform.wfs.options[ind].value;
- myform = wfsWindow.document.forms[1];
- D[m]['wfs_conf'] = wfs;
- D[m]['element'] = new Array();
- D[m]['element']['name'] = new Array();
- D[m]['element']['val'] = new Array();
- var cnt = 0;
- for( var i=0; i<myform.length; i++){
- if(myform.elements[i].type == 'text'){
- D[m]['element'][cnt] = new Array();
- D[m]['element'][cnt]['name'] = myform.elements[i].name;
- D[m]['element'][cnt]['val'] = myform.elements[i].value;
- if(D[m]['element'][cnt]['name'] == 'gid'){
- myid_value = D[m]['element'][cnt]['val'];
- }
- cnt++;
- }
- }
-// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
- var myconf = wfs_conf[D[m]['wfs_conf']];
- document.sendForm.url.value = myconf['wfs_transaction'];
- var str = '<wfs:Transaction version="1.0.0" service="WFS" xmlns="http://www.someserver.com/myns" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd" xmlns:topp="http://www.someserver.com/topp">';
- str += '<wfs:Update typeName="'+ myconf['featuretype_name']+'">';
- for(var i=0; i<D[m]['element'].length; i++){
- if(D[m]['element'][i]['val'] != ""){
- str += '<wfs:Property>';
- str += '<wfs:Name>'+D[m]['element'][i]['name']+'</wfs:Name>';
- str += '<wfs:Value>'+D[m]['element'][i]['val']+'</wfs:Value>';
- str += '</wfs:Property>';
- }
- }
- for(var j=0; j<myconf['element'].length; j++){
- if(myconf['element'][j]['f_geom'] == 1){
- var el_geom = myconf['element'][j]['element_name'];
- }
- }
-// str += '<' + el_geom + '>';
-
-// if(dig.D[0].type == 'text'){
-// str += '<gml:Point srsName="epsg:4326">';
-// str += '<gml:coordinates>';
-// str += dig.D[0].x[0] + "," + dig.D[0].y[0];
-// str += '</gml:coordinates>';
-// str += '</gml:Point>';
-// }
-// if(dig.D[0].type == 'line'){
-// str += '<gml:MultiLineString srsName="epsg:4326">';
-// str += '<gml:lineStringMember>';
-// str += '<gml:LineString>';
-//
-// str += '<gml:coordinates>';
-// for(var k=0; k<dig.D[0].x.length; k++){
-// if(k>0){
-// str += " ";
-// }
-// str += dig.D[0].x[k] + "," + dig.D[0].y[k];
-// }
-// str += '</gml:coordinates>';
-// str += '</gml:LineString>';
-// str += '</gml:lineStringMember>';
-// str += '</gml:MultiLineString>';
-// }
- if(D[m]['geomtype'] == 'Polygon'){
- str += '<wfs:Property>';
- str += '<wfs:Name>' + el_geom + '</wfs:Name>';
- str += '<wfs:Value>';
- str += '<gml:MultiPolygon srsName="epsg:4326">';
- str += '<gml:polygonMember>';
- str += '<gml:Polygon>';
- str += '<gml:outerBoundaryIs>';
- str += '<gml:LinearRing>';
-
- str += '<gml:coordinates>';
- for(var k=0; k<D[m]['geometry'][0]['x'].length; k++){
- if(k>0){
- str += " ";
- }
- str += D[m]['geometry'][0]['x'][k] + "," + D[m]['geometry'][0]['y'][k];
- }
- str += '</gml:coordinates>';
- str += '</gml:LinearRing>';
- str += '</gml:outerBoundaryIs>';
- str += '</gml:Polygon>';
- str += '</gml:polygonMember>';
- str += '</gml:MultiPolygon>';
- str += '</wfs:Value>';
- str += '</wfs:Property>';
- }
-// str += '</' + el_geom + '>';
- str += '<ogc:Filter>';
- str += '<ogc:PropertyIsEqualTo>';
- str += '<ogc:PropertyName>gid</ogc:PropertyName>';
- str += '<ogc:Literal>'+myid_value+'</ogc:Literal>';
- str += '</ogc:PropertyIsEqualTo>';
- str += '</ogc:Filter>';
- str += '</wfs:Update>';
- str += '</wfs:Transaction>';
- document.forms[1].filter.value = str;
- //prompt("",str);
- document.forms[1].submit();
- return false;
-}
-function deleteGeom(m){
- var myid_value;
- var myform = wfsWindow.document.forms[0];
- var ind = myform.wfs.selectedIndex;
- var wfs = myform.wfs.options[ind].value;
- myform = wfsWindow.document.forms[1];
- D[m]['wfs_conf'] = wfs;
- D[m]['element'] = new Array();
- D[m]['element']['name'] = new Array();
- D[m]['element']['val'] = new Array();
- var cnt = 0;
- for( var i=0; i<myform.length; i++){
- if(myform.elements[i].type == 'text'){
- D[m]['element'][cnt] = new Array();
- D[m]['element'][cnt]['name'] = myform.elements[i].name;
- D[m]['element'][cnt]['val'] = myform.elements[i].value;
- if(D[m]['element'][cnt]['name'] == 'gid'){
- myid_value = D[m]['element'][cnt]['val'];
- }
- cnt++;
- }
- }
-// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
- var myconf = wfs_conf[D[m]['wfs_conf']];
- document.sendForm.url.value = myconf['wfs_transaction'];
- var str = '<wfs:Transaction version="1.0.0" service="WFS" xmlns="http://www.someserver.com/myns" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd" xmlns:topp="http://www.someserver.com/topp">';
- str += '<wfs:Delete typeName="'+ myconf['featuretype_name']+'">';
- for(var j=0; j<myconf['element'].length; j++){
- if(myconf['element'][j]['f_geom'] == 1){
- var el_geom = myconf['element'][j]['element_name'];
- }
- }
-
- str += '<ogc:Filter>';
- str += '<ogc:PropertyIsEqualTo>';
- str += '<ogc:PropertyName>gid</ogc:PropertyName>';
- str += '<ogc:Literal>'+myid_value+'</ogc:Literal>';
- str += '</ogc:PropertyIsEqualTo>';
- str += '</ogc:Filter>';
- str += '</wfs:Delete>';
- str += '</wfs:Transaction>';
- document.forms[1].filter.value = str;
- //prompt("",str);
- document.forms[1].submit();
- return false;
-}
- </script>
- </head>
- <body onload="registerFunctions()">
- <table cellpadding='0' cellspacing='0' align = center>
- <tr>
- <td>
- <form name='dig'>
- <table cellpadding='0' cellspacing='2'>
- <tr>
- <td>
- <img name='Point' onmouseover='register_button(this)' id='Point' title="Add point" src = '../img/button_digitize/text_up.png'>
- </td>
- <td>
- <img name='Line' onmouseover='register_button(this)' id='Line' title="Add line" src = '../img/button_digitize/line_up.png'>
- </td>
- <td>
- <img name='Polygon' onmouseover='register_button(this)' id='Polygon' title="Add polygon" src = '../img/button_digitize/poly_up.png'>
- </td>
- <td>
-
- </td>
- <td>
- <img name='dragBasePoint' onmouseover='register_button(this)' id='dragBasePoint' title="Move node" src = '../img/button_digitize/move_up.png'>
- </td>
- <td>
- <img name='setBasePoint' onmouseover='register_button(this)' id='setBasePoint' title="Add node" src = '../img/button_digitize/newNode_up.png'>
- </td>
- <td>
- <img name='delBasePoint' onmouseover='register_button(this)' id='delBasePoint' title="Delete node" src = '../img/button_digitize/delNode_up.png'>
- </td>
- </tr>
- </table>
- </form>
- </td>
- </tr>
- </table>
- <div id = 'listOfGeometries'></div>
- <form name='sendForm' action='../extensions/geom2wfst.php' method='POST' TARGET='_blank'>
- <input type='hidden' name='url'>
- <input type='hidden' name='filter'>
- </form>
- </body>
+<?php
+#$Id: mod_digitize_tab.php,v 1.39 2006/04/07 15:48:13 c_baudson Exp $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_digitize_tab.php,v 1.39 2006/04/07 15:48:13 c_baudson Exp $
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+session_start();
+import_request_variables("PG");
+require_once("../php/mb_validateSession.php");
+require_once("../../conf/mapbender.conf");
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+$gui_id = $_SESSION["mb_user_gui"];
+?>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+ <html>
+ <head>
+ <meta http-equiv="cache-control" content="no-cache">
+ <meta http-equiv="pragma" content="no-cache">
+ <meta http-equiv="expires" content="0">
+ <?php
+ echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';
+ ?>
+ <title>Digitize</title>
+ <?php
+ include '../include/dyn_css.php';
+
+
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ db_select_db(DB,$con);
+ $sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'digitize' AND fkey_gui_id = '".$gui_id."'";
+ $res = db_query($sql);
+ $cnt = 0;
+ while($row = db_fetch_array($res)){
+ $e_src = $row["e_src"];
+ $e_target = explode(",",$row["e_target"]);
+ $cnt++;
+ }
+ if($cnt > 1){ echo "alert('digitize_button: ID not unique!');";}
+# echo $e_target[0] . "<br>";
+# echo $e_target[1];
+ echo "<script language='JavaScript'>";
+ echo "var mod_digitize_target = '".$e_target[0]."';";
+ echo "var mod_digitize_frame = '".$e_target[1]."';";
+
+?>
+
+// var mod_digitize_status = 0;
+
+ //public
+
+ var mod_digitize_color1 = "white";
+ var mod_digitize_color2 = "black";
+ var mod_digitize_font = "Arial, Helvetica, sans-serif";
+ var mod_digitize_fontsize = "9px";
+ var mod_digitize_basepoint = "#8a2be2";
+ var mod_digitize_linepoint = "#ff00ff";
+ var mod_digitize_bg = "";
+
+ var mod_digitize_elName = "digitize";
+ var mod_digitize_frameName = "";
+
+ var wfsWindow;
+
+
+ var snappingCoordinates = new Array();
+ var snappingTolerance = 12;
+ var snappedMember = -1;
+ var snappedGeometry = -1;
+ var snappedPoint = -1;
+ var snapped = false;
+
+ // canvas contains circles around snapping target
+ var canvas = new Array();
+
+ var wfs_conf = new Array();
+
+ var D = new Array();
+
+ var activeButton = null; // contains id of active button
+ var isOn = true;
+ var mod_digitize_width;
+ var mod_digitize_height;
+ var mod_digitize_Dist = new Array();
+ var mod_digitize_TotalDist = new Array();
+ var mod_digitizeSubFunctions = new Array();
+ var mod_digitizeEvent = false;
+
+ //currently selected basepoint
+ var basepointObject = false;
+
+ // stores the number of geometries in the geometry list
+ var numberOfGeometries = 0;
+
+ //indices of the geometry associated with a certain basepoint
+ var basepointMemberIndex = false;
+ var basepointGeometryIndex = false;
+ var basepointPointIndex = false;
+
+ //when a basepoint is being dragged, the coordinates are stored
+ var basepointDragActive = false;
+ var basepointDragStartX = false;
+ var basepointDragStartY = false;
+ var basepointDragEndX = false;
+ var basepointDragEndY = false;
+
+ //indices of the geometry that is currently built
+ var currentMemberIndex = -1;
+ var currentGeometryIndex = -1;
+
+
+
+ var canvas = new Array();
+
+
+
+ // ------------------------------------------------------------------------------------------------------------------------
+ // --- registered functions (begin) ---------------------------------------------------------------------------------------
+
+ //
+ // this method is called onload. these functions will be invoked whenever they are triggered by the mapObj
+ //
+ function registerFunctions(){
+ parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].setStyleForTargetFrame()");
+ parent.mb_registerInitFunctions("window.frames['"+ mod_digitize_elName + "'].checkTag()");
+ parent.mb_registerSubFunctions("window.frames['"+ mod_digitize_elName + "'].drawDashedLine()");
+ }
+
+ //
+ // checks if a div tag with id "digitize" exists in frame mod_digitize_target.
+ // if yes, these element's attributes are set and itself is returned
+ // if not, it is created (with attributes) and returned
+ // if an element with id "digitize" exists and it is not a div tag, false is returned
+ //
+ function checkTag () {
+ var attributes = new Array();
+ attributes[0] = new Array();
+ attributes[0][0] = "style";
+ attributes[0][1] = "position:absolute; top:0px; left:0px; z-index:26; font-size:10px";
+ node = parent.mb_checkTag(mod_digitize_target, "div", "digitize", "body", attributes);
+ if (node == false) {
+ alert("Fatal error: Element id 'digitize' is already taken!");
+ }
+ }
+
+ //
+ // this adds the stylesheet to the map frame
+ //
+ function setStyleForTargetFrame() {
+ var cssLink = parent.window.frames[mod_digitize_target].document.createElement("link");
+ cssLink.setAttribute("href", cssUrl);
+ cssLink.setAttribute("type", "text/css");
+ cssLink.setAttribute("rel", "stylesheet");
+ var cssTmp = parent.window.frames[mod_digitize_target].document.getElementsByTagName("head")[0];
+ cssTmp.appendChild(cssLink);
+ }
+
+ // --- registered functions (end) -----------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------------------------------------------------
+
+/*
+ function const_D(id,type){
+ this.id = id;
+ this.type = type;
+ this.x = new Array();
+ this.y = new Array();
+ this.label = "";
+
+ var ind = parent.getMapObjIndexByName(mod_digitize_target);
+ this.epsg = parent.mb_mapObj[ind].epsg;
+ this.units = "";
+ this.dist = new Array();
+ this.totaldist = new Array();
+ this.complete = false;
+ }
+*/
+
+
+ // ------------------------------------------------------------------------------------------------------------------------
+ // --- preload images (begin) ---------------------------------------------------------------------------------------------
+
+ // up
+ var digitize_point_up = new Image(); digitize_point_up.src = "../img/button_digitize/text_up.png";
+ var digitize_line_up = new Image(); digitize_line_up.src = "../img/button_digitize/line_up.png";
+ var digitize_poly_up = new Image(); digitize_poly_up.src = "../img/button_digitize/poly_up.png";
+ var digitize_move_up = new Image(); digitize_move_up.src = "../img/button_digitize/move_up.png";
+ var digitize_addNode_up = new Image(); digitize_addNode_up.src = "../img/button_digitize/newNode_up.png";
+ var digitize_delNode_up = new Image(); digitize_delNode_up.src = "../img/button_digitize/delNode_up.png";
+ // down
+ var digitize_point_down = new Image(); digitize_point_down.src = "../img/button_digitize/text_down.png";
+ var digitize_line_down = new Image(); digitize_line_down.src = "../img/button_digitize/line_down.png";
+ var digitize_poly_down = new Image(); digitize_poly_down.src = "../img/button_digitize/poly_down.png";
+ var digitize_move_down = new Image(); digitize_move_down.src = "../img/button_digitize/move_down.png";
+ var digitize_addNode_down = new Image(); digitize_addNode_down.src = "../img/button_digitize/newNode_down.png";
+ var digitize_delNode_down = new Image(); digitize_delNode_down.src = "../img/button_digitize/delNode_down.png";
+
+ // --- preload images (end) -----------------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------------------------------------------------
+
+
+ // ------------------------------------------------------------------------------------------------------------------------
+ // --- button handling (begin) --------------------------------------------------------------------------------------------
+
+ function register_button(obj) {
+ parent.mb_regButton_frame("init_digitize_button", obj, mod_digitize_elName);
+ }
+
+ function init_digitize_button(obj, ind){
+ parent.mb_button[ind] = obj;
+ parent.mb_button[ind].img_over = obj.src;
+
+ if (obj.id == "dragBasePoint") {
+ parent.mb_button[ind].img_on = digitize_move_down.src;
+ parent.mb_button[ind].img_off = digitize_move_up.src;
+ }
+ else if (obj.id == "setBasePoint"){
+ parent.mb_button[ind].img_on = digitize_addNode_down.src;
+ parent.mb_button[ind].img_off = digitize_addNode_up.src;
+ }
+ else if (obj.id == "delBasePoint"){
+ parent.mb_button[ind].img_on = digitize_delNode_down.src;
+ parent.mb_button[ind].img_off = digitize_delNode_up.src;
+ }
+ else if (obj.id == "Point"){
+ parent.mb_button[ind].img_on = digitize_point_down.src;
+ parent.mb_button[ind].img_off = digitize_point_up.src;
+ }
+ else if (obj.id == "Line"){
+ parent.mb_button[ind].img_on = digitize_line_down.src;
+ parent.mb_button[ind].img_off = digitize_line_up.src;
+ }
+ else if (obj.id == "Polygon"){
+ parent.mb_button[ind].img_on = digitize_poly_down.src;
+ parent.mb_button[ind].img_off = digitize_poly_up.src;
+ }
+ parent.mb_button[ind].status = 0;
+ parent.mb_button[ind].elName = obj.id;
+ parent.mb_button[ind].fName = "";
+ parent.mb_button[ind].go = new Function ("digitize_click(parent.mb_button["+ind+"])");
+ parent.mb_button[ind].stop = new Function ("digitize_disable(parent.mb_button["+ind+"])");
+ }
+
+ function digitize_click(obj) {
+ if (obj.id == "dragBasePoint") {
+ activeButton = obj.id;
+ setEvent(obj);
+ }
+ else if (obj.id == "setBasePoint"){
+ activeButton = obj.id;
+ setEvent(obj);
+ }
+ else if (obj.id == "delBasePoint"){
+ activeButton = obj.id;
+ setEvent(obj);
+ }
+ else if (obj.id == "Point"){
+ activeButton = obj.id;
+ obj.title = "Finish editing";
+ currentMemberIndex = -1;
+ registerGeometry(obj);
+ storeSnappingCoordinates();
+ var el = parent.frames[mod_digitize_target].document;
+ el.onmousemove = mod_digitize_go;
+ }
+ else if (obj.id == "Line"){
+ activeButton = obj.id;
+ obj.title = "Finish editing";
+ currentMemberIndex = -1;
+ registerGeometry(obj);
+ storeSnappingCoordinates();
+ var el = parent.frames[mod_digitize_target].document;
+ el.onmousemove = mod_digitize_go;
+ }
+ else if (obj.id == "Polygon"){
+ activeButton = obj.id;
+ obj.title = "Finish editing";
+ currentMemberIndex = -1;
+ registerGeometry(obj);
+ storeSnappingCoordinates();
+ var el = parent.frames[mod_digitize_target].document;
+ el.onmousemove = mod_digitize_go;
+ }
+ }
+
+ function digitize_disable(obj) {
+ if (obj.id == "dragBasePoint") {
+ }
+ else if (obj.id == "setBasePoint"){
+ }
+ else if (obj.id == "delBasePoint"){
+ }
+ else if (obj.id == "Point"){
+ activeButton = null;
+ obj.title = "Add point";
+ closeGeometry(obj.id);
+ mod_digitize_timeout();
+ }
+ else if (obj.id == "Line"){
+ activeButton = null;
+ obj.title = "Add line";
+ closeGeometry(obj.id);
+ mod_digitize_timeout();
+ }
+ else if (obj.id == "Polygon"){
+ activeButton = null;
+ obj.title = "Add polygon";
+ closeGeometry(obj.id);
+ mod_digitize_timeout();
+ }
+ }
+
+ // --- button handling (end) ----------------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------------------------------------------------
+
+
+ var dwin = null;
+
+ function mod_saveGeom() {
+ dwin = window.open("../php/mod_wfs_save.php","dwin","width=300,height=200");
+ }
+
+
+
+ // ------------------------------------------------------------------------------------------------------------------------
+ // --- snapping (begin) ----------------------------------------------------------------------------------------------
+
+ //
+ // deletes all snapping areas from the canvas
+ //
+ function cleanCanvas () {
+ var el = parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw');
+ if (el) el.innerHTML = "";
+ }
+
+ //
+ // checks if the canvas for snapping areas is present
+ // if not, it is being generated
+ //
+ function checkCanvasTag () {
+ var isTag = (parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw'))?1:0;
+ if(isTag == 0){
+ var draw = parent.window.frames[mod_digitize_target].document.createElement("div");
+ var tmp = parent.window.frames[mod_digitize_target].document.getElementsByTagName("body")[0].appendChild(draw);
+ tmp.setAttribute("id","mod_digi_draw");
+ tmp.setAttribute("style","position:absolute;top:0px;left:0px;width:0px;height:0px;z-index:100");
+ }
+ canvas[mod_digitize_target] = new parent.jsGraphics('mod_digi_draw', parent.window.frames[mod_digitize_target]);
+ canvas[mod_digitize_target].setStroke(3);
+ }
+
+ //
+ // draws a snapping area around a given point
+ //
+ function drawSnappingArea (centerX,centerY,radius,size) {
+ canvas[mod_digitize_target].setColor("#ff0000");
+ canvas[mod_digitize_target].drawEllipse(centerX-(size/2)*radius,centerY-(size/2)*radius,size*radius,size*radius);
+ canvas[mod_digitize_target].paint();
+ }
+
+ //
+ // stores the coordinates of points that may be used for snapping
+ // in respect to the current point (the point being moved or inserted)
+ //
+ function storeSnappingCoordinates() {
+ snappingCoordinates = new Array();
+
+ // copy coordinates of other geometries in another array
+ var im = -1;
+
+ var cnt = 0;
+ for (var i = 0; i < D.length ; i++) {
+ for (var j = 0 ; j < D[i]['geometry'].length ; j++) {
+ for (var k = 0 ; k < D[i]['geometry'][j]['x'].length ; k++) {
+ var pos = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k], D[i]['geometry'][j]['y'][k]);
+
+ // snap only if the two points have different coordinates
+ if (basepointDragActive == false || basepointDragActive == true && (D[i]['geometry'][j]['x'][k] != D[basepointMemberIndex]['geometry'][basepointGeometryIndex]['x'][basepointPointIndex] || D[i]['geometry'][j]['y'][k] != D[basepointMemberIndex]['geometry'][basepointGeometryIndex]['y'][basepointPointIndex])) {
+
+ snappingCoordinates[cnt] = new Array();
+ snappingCoordinates[cnt]['map_x'] = pos[0];
+ snappingCoordinates[cnt]['map_y'] = pos[1];
+ snappingCoordinates[cnt]['member'] = i;
+ snappingCoordinates[cnt]['geometry'] = j;
+ snappingCoordinates[cnt]['point'] = k;
+ cnt++;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+ //
+ // checks if a point is in snapping range
+ // if yes, the snapping area is highlighted and the snapped point is stored
+ //
+ function checkSnapped (basepointDragEndX, basepointDragEndY, defaultMouseCursor) {
+
+ var minDist = false;
+ var min_i = -1;
+ for (var i = 0 ; i < snappingCoordinates.length ; i++) {
+ var aDist = dist(basepointDragEndX, basepointDragEndY, snappingCoordinates[i]['map_x'], snappingCoordinates[i]['map_y']);
+ if (aDist < snappingTolerance) {
+ if (minDist == false || aDist < minDist) {
+ minDist = aDist;
+ snappedMember = snappingCoordinates[i]['member'];
+ snappedGeometry = snappingCoordinates[i]['geometry'];
+ snappedPoint = snappingCoordinates[i]['point'];
+ min_i = i;
+ }
+ }
+ }
+
+ if (minDist == false || minDist > snappingTolerance) {
+ snapped = false;
+ var el = parent.window.frames[mod_digitize_target].document.getElementById('mod_digi_draw');
+ if (el) el.innerHTML = "";
+ }
+ else {
+ snapped = true;
+
+ checkCanvasTag();
+ cleanCanvas();
+ drawSnappingArea(snappingCoordinates[min_i]['map_x'], snappingCoordinates[min_i]['map_y'], snappingTolerance, 3);
+ }
+
+ if (basepointObject != false) {
+ if (snapped == true) {
+ basepointObject.style.cursor = 'crosshair';
+ }
+ else {
+ basepointObject.style.cursor = defaultMouseCursor;
+ }
+
+ if (defaultMouseCursor == 'move') {
+ // replace basepoint by transparent blob
+ basepointObject.style.width = mod_digitize_width;
+ basepointObject.style.height = mod_digitize_height;
+ basepointObject.style.left = 0;
+ basepointObject.style.top = 0;
+
+ if (parent.ie) {
+ // ie cannot handle backgroundColor = 'transparent'
+ basepointObject.style.background = "url(/../img/button_digitize/trans.png)";
+ }
+ else{
+ basepointObject.style.backgroundColor = 'transparent';
+ }
+ }
+ }
+ }
+
+ // --- snapping (end) ----------------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------------------------------------------------
+
+ function mod_digitize_go(e){
+ parent.mb_registerGML(mod_digitize_target,D);
+ parent.document.getElementById(mod_digitize_elName).style.visibility = 'visible';
+
+ // snapping
+ if (e) {
+ // track mouse position
+ parent.mb_getMousePos(e, mod_digitize_target);
+ checkSnapped(parent.clickX, parent.clickY, 'default');
+ }
+
+ var el = parent.frames[mod_digitize_target].document;
+ el.onmousedown = mod_digitize_start;
+ //el.onmousemove = mod_digitize_run;
+
+ var ind = parent.getMapObjIndexByName(mod_digitize_target);
+ mod_digitize_width = parent.mb_mapObj[ind].width;
+ mod_digitize_height = parent.mb_mapObj[ind].height;
+ mod_digitize_epsg = parent.mb_mapObj[ind].epsg;
+ }
+
+
+ function mod_digitize_timeout(){
+// isOn = false;
+// parent.document.getElementById(mod_digitize_elName).style.visibility = 'hidden';
+ var el = parent.frames[mod_digitize_target].document;
+ el.onmousedown = null;
+ el.onmouseup = null;
+ el.onmousemove = null;
+// drawDashedLine();
+ }
+
+
+ //
+ // a new member is being generated and attached to the array D
+ //
+ function registerGeometry(type){
+
+ // a new geometry will be inserted
+ if (currentMemberIndex == -1) {
+ currentMemberIndex = D.length;
+
+ // generate a new member
+ D[currentMemberIndex] = new Array();
+ D[currentMemberIndex]['geometry'] = new Array();
+ D[currentMemberIndex]['element'] = new Array();
+ D[currentMemberIndex]['wfs_conf'] = -1;
+ D[currentMemberIndex]['geomtype'] = type.id;
+
+ // attach a new geometry
+ var geomInd = D[currentMemberIndex]['geometry'].length;
+ D[currentMemberIndex]['geometry'][geomInd] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['x'] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['y'] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['complete'] = false;
+
+ currentGeometryIndex = 0;
+ }
+ // a geometry will be added to an existing geometry
+ else {
+
+ // FIXME: check if geometry types match
+
+ // attach a new geometry
+ var geomInd = D[currentMemberIndex]['geometry'].length;
+ D[currentMemberIndex]['geometry'][geomInd] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['x'] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['y'] = new Array();
+ D[currentMemberIndex]['geometry'][geomInd]['complete'] = false;
+
+ currentGeometryIndex = geomInd;
+ }
+ }
+
+ //
+ // adds a new basepoint to the geometry
+ //
+ function mod_digitize_start(e){
+ isOn = true;
+
+ if (currentMemberIndex != -1) {
+
+ // select the last geometry of the current member
+ var geomInd = D[currentMemberIndex]['geometry'].length - 1;
+
+ // check if a proper geometry is selected
+ if(D[currentMemberIndex]['geometry'][geomInd]['complete'] == true || (D.length == 0)){
+
+ if (activeButton != null) {
+ alert("No geometry selected!");
+ }
+ return true;
+ }
+
+ // get the mouse position and calculate real world position
+ if (snapped == true) {
+ cleanCanvas();
+
+ var realWorldPos = new Array();
+ realWorldPos[0] = D[snappedMember]['geometry'][snappedGeometry]['x'][snappedPoint];
+ realWorldPos[1] = D[snappedMember]['geometry'][snappedGeometry]['y'][snappedPoint];
+
+ }
+ else {
+ parent.mb_getMousePos(e,mod_digitize_target);
+ var realWorldPos = parent.makeClickPos2RealWorldPos(mod_digitize_target,parent.clickX,parent.clickY);
+ }
+ snapped = false;
+
+ if (D[currentMemberIndex]['geomtype'].toLowerCase() == 'polygon'
+ && D[currentMemberIndex]['geometry'][geomInd]['x'].length > 1
+ && D[currentMemberIndex]['geometry'][geomInd]['x'][0] == realWorldPos[0]
+ && D[currentMemberIndex]['geometry'][geomInd]['y'][0] == realWorldPos[1]) {
+
+ // close the polygon
+ parent.mb_disableThisButton('Polygon');
+ }
+ else {
+ // set the calculated real world position as point of the geometry
+ xInd = D[currentMemberIndex]['geometry'][geomInd]['x'].length;
+ yInd = D[currentMemberIndex]['geometry'][geomInd]['y'].length;
+ D[currentMemberIndex]['geometry'][geomInd]['x'][xInd] = realWorldPos[0];
+ D[currentMemberIndex]['geometry'][geomInd]['y'][yInd] = realWorldPos[1];
+
+ // if the current geometry is a point, attach a label to it
+ if(D[currentMemberIndex]['geomtype'].toLowerCase() == 'point'){
+ parent.mb_disableThisButton('Point');
+ }
+
+ // add first point of polygon to snapping list (if three points have been inserted).
+ if (D[currentMemberIndex]['geomtype'].toLowerCase() == 'polygon'
+ && D[currentMemberIndex]['geometry'][geomInd]['x'].length == 3) {
+ var tempInd = snappingCoordinates.length;
+ var pos = parent.makeRealWorld2mapPos(mod_digitize_target, D[currentMemberIndex]['geometry'][geomInd]['x'][0], D[currentMemberIndex]['geometry'][geomInd]['y'][0]);
+ snappingCoordinates[tempInd] = new Array();
+ snappingCoordinates[tempInd]['map_x'] = pos[0];
+ snappingCoordinates[tempInd]['map_y'] = pos[1];
+ snappingCoordinates[tempInd]['member'] = currentMemberIndex;
+ snappingCoordinates[tempInd]['geometry'] = geomInd;
+ snappingCoordinates[tempInd]['point'] = 0;
+ }
+ }
+ drawDashedLine();
+ }
+
+ return true;
+ }
+
+ //
+ // finishes a geometry by labelling it complete.
+ // if no coordinates have been added, the geometry is discarded.
+ //
+ // when a polygon is built and the polygon button is clicked again, the
+ // polygon will be closed by connecting the last to the first point.
+ // Actually, the first point is stored twice at index '0' and index 'length'
+ //
+ function closeGeometry(obj_id){
+ var i = currentMemberIndex;
+ var j = currentGeometryIndex;
+
+ if(!isOn){ return; };
+
+ D[i]['geometry'][j]['complete'] = true;
+
+ var tmpLength = D[i]['geometry'][j]['x'].length;
+
+ // if no geometries have been inserted, delete the geometry or member
+ if (tmpLength == 0) {
+ if (j == 0) {
+ D.length--;
+ }
+ else {
+ D[i]['geometry'].length--;
+ }
+ }
+ if (obj_id == "Polygon") {
+ if (tmpLength > 0) {
+ D[i]['geometry'][j]['x'][tmpLength] = D[i]['geometry'][j]['x'][0];
+ D[i]['geometry'][j]['y'][tmpLength] = D[i]['geometry'][j]['y'][0];
+ }
+ }
+ drawDashedLine();
+ }
+
+ function calculateDashes(pos0, pos1) {
+ // pos0 is leftmost point
+ if (pos0[0] > pos1[0]) {
+ var pos_temp = new Array();
+ pos_temp = pos0;
+ pos0 = pos1;
+ pos1 = pos_temp;
+ }
+
+ var p = pos0;
+ var q = pos1;
+
+ var m;
+ var draw = true;
+
+ // if line is not vertical
+ if (pos1[0] != pos0[0]) {
+
+ // calculate slope
+ m = -(pos1[1]-pos0[1])/(pos1[0]-pos0[0]);
+
+ // check if p is left of the right vertical of the screen && the line is not above or below the screen
+ if (pos0[0] < mod_digitize_width && pos1[0] > 0
+ && !(pos0[1] < 0 && pos1[1] < 0) && !(pos0[1] > mod_digitize_height && pos1[1] > mod_digitize_height) ) {
+
+ // if p is left of the screen
+ if (pos0[0] < 0) {
+
+ //calculate intersection of line with left vertical of screen
+ var iy = pos0[1] - m*(0-pos0[0]);
+
+ // if intersection is visible
+ if (iy > 0 && iy < mod_digitize_height) {
+ p[0] = 0;
+ p[1] = iy;
+ }
+ // if intersection is below the screen
+ else if (iy > mod_digitize_height) {
+ // calculate intersection with lower horizontal
+ var ix = pos0[0]+((pos0[1] - mod_digitize_height)/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ p[0] = ix;
+ p[1] = mod_digitize_height;
+ }
+ else {
+ draw = false;
+ }
+ }
+ // if intersection is above the screen
+ else if (iy < 0) {
+ // calculate intersection with upper horizontal
+ var ix = pos0[0]+(pos0[1]/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ p[0] = ix;
+ p[1] = 0;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else {
+ draw = false;
+ }
+
+ }
+ else if (pos0[1] > 0 && pos0[1] < mod_digitize_height) {
+ p[0] = pos0[0];
+ p[1] = pos0[1];
+ }
+ else if (pos0[1] < 0) {
+ // calculate intersection with upper horizontal
+ var ix = pos0[0]+(pos0[1]/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ p[0] = ix;
+ p[1] = 0;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else if (pos0[1] > mod_digitize_height && m > 0) {
+ // calculate intersection with lower horizontal
+ var ix = pos0[0]+((pos0[1] - mod_digitize_height)/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ p[0] = ix;
+ p[1] = mod_digitize_height;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else {
+ draw = false;
+ }
+
+ // calculate q coordinates
+ if (draw == true) {
+
+ // q is right of the screen
+ if (pos1[0] > mod_digitize_width) {
+ // calculate intersection with right vertical of the screen
+ var iy = pos1[1] - m*(mod_digitize_width-pos1[0]);
+
+ if (iy > 0 && iy < mod_digitize_height) {
+ q[0] = mod_digitize_width;
+ q[1] = iy;
+ }
+ else if (iy < 0) {
+ // calculate intersection with upper horizontal
+ var ix = pos0[0]+(pos0[1]/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ q[0] = ix;
+ q[1] = 0;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else if (iy > mod_digitize_height) {
+ // calculate intersection with lower horizontal
+ var ix = pos0[0]+((pos0[1] - mod_digitize_height)/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ q[0] = ix;
+ q[1] = mod_digitize_height;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else {
+ draw = false;
+ }
+ }
+ else if (pos1[1] > 0 && pos1[1] < mod_digitize_height) {
+ q[0] = pos1[0];
+ q[1] = pos1[1];
+ }
+ else if (pos1[1] < 0) {
+ // calculate intersection with upper horizontal
+ var ix = pos1[0]+(pos1[1]/m);
+ if (ix > 0 && ix < mod_digitize_width) {
+ q[0] = ix;
+ q[1] = 0;
+ }
+ else {
+ draw = false;
+ }
+ }
+ else if (pos1[1] > mod_digitize_height) {
+ // calculate intersection with lower horizontal
+ var ix = pos1[0]+((pos1[1]- mod_digitize_height)/m) ;
+ if (ix > 0 && ix < mod_digitize_width) {
+ q[0] = ix;
+ q[1] = mod_digitize_height;
+ }
+ else {
+ draw = false;
+ }
+ }
+
+ }
+ }
+ else {
+ draw = false;
+ }
+
+
+ }
+ // the line is vertical
+ else {
+ // x-Coordinates remain
+ p[0] = pos0[0];
+ q[0] = pos0[0];
+
+ // check if line is not above or below the screen
+ if (!(pos0[1] < 0 && pos1[1] < 0) && !(pos0[1] > mod_digitize_height && pos1[1] > mod_digitize_height)) {
+ if (pos0[1] < 0) {
+ p[1] = 0;
+ }
+ else if (pos0[1] > mod_digitize_height) {
+ p[1] = mod_digitize_height;
+ }
+ else {
+ p[1] = pos0[1];
+ }
+ if (pos1[1] < 0) {
+ q[1] = 0;
+ }
+ else if (pos1[1] > mod_digitize_height) {
+ q[1] = mod_digitize_height;
+ }
+ else {
+ q[1] = pos1[1];
+ }
+ }
+ else {
+ draw = false;
+ }
+ }
+
+ if (draw == true) {
+ var points = new Array();
+ points[0] = Math.round(q[0]);
+ points[1] = Math.round(q[1]);
+ points[2] = Math.round(p[0]);
+ points[3] = Math.round(p[1]);
+ return points;
+ }
+ else {
+ return false;
+ }
+ }
+
+
+ //
+ // displays *all* digitized geometries
+ //
+ function drawDashedLine(){
+ 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>";
+
+ // *all* members will be painted
+ for(var i=0; i<D.length; i++){
+
+ // paint all geometries of member i
+ for(var j=0; j<D[i]['geometry'].length; j++){
+ //
+ // paint the basepoints
+ //
+ for(var k=0; k<D[i]['geometry'][j]['x'].length; k++){
+ // calculate screen position from real world coordinates
+ var pos = parent.makeRealWorld2mapPos(mod_digitize_target,D[i]['geometry'][j]['x'][k],D[i]['geometry'][j]['y'][k]);
+
+ // if this geometry is a point
+ if(D[i]['geomtype'].toLowerCase() == "point"){
+ // smP += "<div class='label' style='top:"+(pos[1]-6)+"px;left:"+(pos[0])+"px;z-index:50;'>"+D[i]['label']+"</div>";
+ }
+
+ smP += "<div class='bp' style='top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;z-index:50;'";
+ if(j==0 && D[i]['geomtype'].toLowerCase() == 'polygon' && D[i]['geometry'][j]['complete'] == false){
+ smP += " title='to close polygon, release the polygon button on the left' ";
+ }
+ if(isOn){
+ smP += " onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].handleBasepoint(this,"+i+","+j+","+k+")' ;";
+ }
+ smP += "></div>";
+ }
+ //
+ // paint the lines between basepoints
+ //
+ for(var k = 1; k < D[i]['geometry'][j]['x'].length; k++){
+
+ var pos0 = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k] , D[i]['geometry'][j]['y'][k]);
+ var pos1 = parent.makeRealWorld2mapPos(mod_digitize_target, D[i]['geometry'][j]['x'][k-1], D[i]['geometry'][j]['y'][k-1]);
+
+
+ points = calculateDashes(pos0, pos1);
+ if (points != false) {
+ smP += evaluateDashes(points[0], points[1], points[2], points[3], i, j, k);
+ }
+ }
+ }
+ }
+ parent.writeTag(mod_digitize_target,"digitize",smP);
+ updateListOfGeometries();
+ }
+
+
+ //
+ // this function calculates the line points between start and end
+ //
+ function evaluateDashes(startX, startY, endX, endY, memberIndex, geomIndex, pointIndex){
+ var str_dashedLine = "";
+ var deltaX = endX - startX;
+ var deltaY = endY - startY;
+
+ // s = distance between two linepoints
+ var s = 10;
+ var vecLength = dist(startX, startY, endX, endY);
+ var n = Math.round(vecLength/s);
+ var stepX = deltaX/n;
+ var stepY = deltaY/n;
+ for(var i=1; i<n; i++){
+ var x = Math.round(startX + i * stepX) - 2;
+ var y = Math.round(startY + i * stepY) - 2;
+ if(x >= 0 && x <= mod_digitize_width && y >= 0 && y <= mod_digitize_height){
+ str_dashedLine += "<div class='lp' style='top:"+y+"px;left:"+x+"px;z-index:50;' ";
+ if(isOn){
+ str_dashedLine += "onmouseover='parent.window.frames[\""+mod_digitize_elName+"\"].convertLinepointToBasepoint(this,"+memberIndex+","+geomIndex+","+pointIndex+")'>";
+ }
+ str_dashedLine += "</div>";
+ }
+ }
+ return str_dashedLine;
+ }
+
+
+ // ------------------------------------------------------------------------------------------------------------------------
+ // --- basepoint handling (begin) -----------------------------------------------------------------------------------------
+
+ //
+ // this function checks what to do with a basepoint that is currently under
+ // the mouse pointer.
+ // Depending on what action is intended, other methods are invoked.
+ //
+
+ function handleBasepoint(Obj,memberIndex,geometryIndex,pointIndex){
+ if(!isOn){ return false; };
+
+ // set the global variables that will be used in deleteBasepoint etc.
+ basepointObject = Obj;
+ basepointMemberIndex = memberIndex;
+ basepointGeometryIndex = geometryIndex;
+ basepointPointIndex = pointIndex;
+
+ if(mod_digitizeEvent == "dragBasePoint" && activeButton == 'dragBasePoint'){
+ mod_digitize_timeout();
+ basepointObject.style.cursor = 'move';
+ basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].selectBasepoint;
+ }
+/*
+ if(mod_digitizeEvent == false && D[memberIndex]['geomtype'].toLowerCase() == 'polygon' && D[memberIndex]['geometry'][geometryIndex].complete == false){
+ basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].closeGeometry("Polygon");
+ }
+*/
+ if(mod_digitizeEvent == "delBasePoint" && activeButton == 'delBasePoint'){
+ mod_digitize_timeout();
+ basepointObject.style.cursor = 'crosshair';
+ basepointObject.onmousedown = parent.window.frames[mod_digitize_elName].deleteBasepoint;
+ }
+ }
+
+ function deleteBasepoint(e){
+
+ var i = basepointMemberIndex;
+ var j = basepointGeometryIndex;
+ var k = basepointPointIndex;
+
+ var xCoord = D[i]['geometry'][j]['x'][k];
+ var yCoord = D[i]['geometry'][j]['y'][k];
+
+ var deleted = false;
+
+ while (deleted == false) {
+ var continueFor = true;
+ deleted = true;
+
+ //find points of other geometries with the same coordinates and delete them as well
+ for (var l = 0 ; l < D.length && continueFor == true; l ++) {
+ for (var m = 0; m < D[l]['geometry'].length && continueFor == true; m++) {
+ for (var n = 0; n < D[l]['geometry'][m]['x'].length && continueFor == true ; n++) {
+ if (D[l]['geometry'][m]['x'][n] == xCoord && D[l]['geometry'][m]['y'][n] == yCoord) {
+ deletePoint(l,m,n);
+ continueFor = false;
+ deleted = false;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //
+ // deletes the point at the i-th member, j-th geometry, k-th point
+ //
+ function deletePoint (i,j,k) {
+ //
+ // the last point is being deleted...
+ //
+ if ( (k == 0 || (D[i]['geometry'][j]['x'].length - k) == 1) && D[i]['geomtype'].toLowerCase() == 'polygon') {
+ // if the last basepoint of a polygon is being deleted,
+ // the first basepoint is now set to be the last but one as well,
+ // in order to close the polygon
+
+ // Shorten the array by one
+ D[i]['geometry'][j]['x'].length = D[i]['geometry'][j]['x'].length - 1;
+ D[i]['geometry'][j]['y'].length = D[i]['geometry'][j]['y'].length - 1;
+
+ // if only one point is left (which has been stored twice), remove it as well
+ if (D[i]['geometry'][j]['x'].length == 1) {
+ D[i]['geometry'][j]['x'].length = 0;
+ D[i]['geometry'][j]['y'].length = 0;
+ }
+ // point that will be deleted is not the only point of the geometry
+ else {
+
+ // place a copy of the last point at index 0
+ var tmpIndex = D[i]['geometry'][j]['x'].length - 1;
+ D[i]['geometry'][j]['x'][0] = D[i]['geometry'][j]['x'][tmpIndex];
+ D[i]['geometry'][j]['y'][0] = D[i]['geometry'][j]['y'][tmpIndex];
+ }
+ }
+ //
+ // a point that is *not* the last point of a geometry is being deleted
+ //
+ else {
+
+ // move basepoints behind deleted basepoints up by one...
+ for(var z= k; z<D[i]['geometry'][j]['x'].length-1; z++){
+ D[i]['geometry'][j]['x'][z] = D[i]['geometry'][j]['x'][z+1];
+ D[i]['geometry'][j]['y'][z] = D[i]['geometry'][j]['y'][z+1];
+ }
+ // ...and adjust length of the array
+ D[i]['geometry'][j]['x'].length = D[i]['geometry'][j]['x'].length - 1;
+ D[i]['geometry'][j]['y'].length = D[i]['geometry'][j]['y'].length - 1;
+ }
+
+ //
+ // if all basepoints of this geometry have been deleted...
+ //
+
+ if (D[i]['geometry'][j]['x'].length == 0) {
+ deleteGeometry(i, j);
+ }
+ else {
+ drawDashedLine();
+ //resetButtonsIfNoMembersLeft();
+ }
+ }
+
+ //
+ // deletes the geometry at index 'indexGeometry' of member at index 'indexmember' of D
+ //
+ function deleteGeometry (indexMember, indexGeometry) {
+ var i = indexMember;
+ var j = indexGeometry;
+
+ //
+ // check whether the deleted geometry is the only geometry of the member...
+ //
+ if (D[i]['geometry'].length == 1) {
+ deleteMember(i);
+ }
+ //
+ // ...if not, move other geometries one spot up
+ //
+ else {
+ var tmpLength = D[i]['geometry'].length - 1;
+ for (var z = j; z < tmpLength ; z ++) {
+ D[i]['geometry'][z] = D[i]['geometry'][z+1];
+ D[i]['element'][z] = D[i]['element'][z+1];
+ }
+ D[i]['geometry'].length -= 1;
+
+ drawDashedLine();
+ resetButtonsIfNoMembersLeft();
+ }
+ }
+
+ //
+ // deletes the member of D at index 'index''
+ //
+ function deleteMember (index) {
+ // delete geometry itself...
+ for(var z = index ; z < D.length - 1; z++){
+ D[z] = D[z+1];
+ }
+ // ... and adjust length of geometry array
+ D.length -= 1;
+
+ drawDashedLine();
+ }
+
+
+ //
+ // this function is invoked when the mouse is over a linepoint.
+ // When the mouse is clicked, the method insert basepoint is
+ // called.
+ //
+ function convertLinepointToBasepoint(obj, memberIndex, geomIndex, pointIndex){
+ if(!isOn){ return false; };
+
+ if(mod_digitizeEvent == "setBasePoint" && activeButton == 'setBasePoint'){
+ mod_digitize_timeout();
+ obj.style.cursor = 'crosshair';
+ obj.onclick = insertBasepoint;
+
+ basepointObject = obj;
+ basepointMemberIndex = memberIndex;
+ basepointGeometryIndex = geomIndex;
+ basepointPointIndex = pointIndex;
+ }
+ }
+
+ //
+ // this function inserts a new basepoint into the geometry.
+ // the basepoint is a former linepoint.
+ //
+ function insertBasepoint(e){
+ var i = basepointMemberIndex;
+ var j = basepointGeometryIndex;
+ var k = basepointPointIndex;
+
+ parent.mb_getMousePos(e, mod_digitize_target);
+ var pos = parent.makeClickPos2RealWorldPos(mod_digitize_target,parent.clickX, parent.clickY);
+
+ for(var z = D[i]['geometry'][j]['x'].length; z > k; z--){
+ D[i]['geometry'][j]['x'][z] = D[i]['geometry'][j]['x'][z-1];
+ D[i]['geometry'][j]['y'][z] = D[i]['geometry'][j]['y'][z-1];
+ }
+
+ D[i]['geometry'][j]['x'][k] = pos[0];
+ D[i]['geometry'][j]['y'][k] = pos[1];
+
+ drawDashedLine();
+ }
+
+ //
+ // when a basepoint move is intended, this function is invoked when the mouse button
+ // is pressed. It stores the start coordinates in a global variable and sets
+ // the global basepointDragActive to true, so other modules know that a basepoint is
+ // currently being dragged
+ //
+
+ function selectBasepoint(e){
+ if(basepointDragActive == false && mod_digitizeEvent == "dragBasePoint"){
+ basepointDragActive = true;
+ storeSnappingCoordinates();
+ basepointObject.onmouseup = releaseBasepoint;
+ basepointObject.onmousemove = dragBasepoint;
+ }
+ }
+
+ function dist (startX, startY, endX, endY) {
+ var deltaX = endX - startX;
+ var deltaY = endY - startY;
+
+ return Math.sqrt(Math.pow(deltaY,2) + Math.pow(deltaX,2)) ;
+ }
+
+
+ //
+ // when a basepoint is being dragged and the mouse button is down,
+ // this function will track the mouse position.
+ // instead of the basepoint, a transparent object the size of the
+ // mapframe is being displayed
+ //
+ function dragBasepoint(e){
+ if(basepointDragActive){
+ parent.mb_getMousePos(e, mod_digitize_target);
+ checkSnapped(parent.clickX, parent.clickY, 'move');
+ }
+ }
+
+
+ //
+ // checks if a geometry has identical neighbour points
+ //
+ function removeDuplicates(i, j) {
+ var length1 = D[i]['geometry'][j]['x'].length;
+ var continueFor = true;
+ for (var k = 2; k < length1 && continueFor == true ; k++) {
+ if (D[i]['geometry'][j]['x'][k] == D[i]['geometry'][j]['x'][k-1] && D[i]['geometry'][j]['y'][k] == D[i]['geometry'][j]['y'][k-1] ) {
+ deletePoint(i,j,k-1);
+ continueFor = false;
+ }
+ }
+ }
+
+
+ //
+ // when a basepoint is being dragged and the mouse button is released,
+ // this function is invoked and the geometry will be updated
+ //
+ function releaseBasepoint(e){
+
+ var i = basepointMemberIndex;
+ var j = basepointGeometryIndex;
+ var k = basepointPointIndex;
+
+ basepointDragActive = false;
+
+ parent.mb_getMousePos(e, mod_digitize_target);
+ basepointDragEndX = parent.clickX;
+ basepointDragEndY = parent.clickY;
+ basepointObject.onmousedown = null;
+ var pos = parent.makeClickPos2RealWorldPos(mod_digitize_target, basepointDragEndX, basepointDragEndY);
+
+ if (snapped == true) {
+ cleanCanvas();
+
+ pos[0] = D[snappedMember]['geometry'][snappedGeometry]['x'][snappedPoint];
+ pos[1] = D[snappedMember]['geometry'][snappedGeometry]['y'][snappedPoint];
+ }
+
+ if ( (k == D[i]['geometry'][j]['x'].length - 1 || k == 0) && D[i]['geometry'][j]['complete'] == true && D[i]['geomtype'].toLowerCase() == 'polygon') {
+ D[i]['geometry'][j]['x'][0] = pos[0];
+ D[i]['geometry'][j]['y'][0] = pos[1];
+ }
+
+ // check if there are points in other geometries with the same coordinates
+ for (var l = 0; l < D.length ; l++) {
+ for (var m = 0 ; m < D[l]['geometry'].length ; m++) {
+ for (n = 0 ; n < D[l]['geometry'][m]['x'].length ; n++) {
+// this line would enable merging of snapped points of the same geometry
+// if ((l != i || m != j) && D[i]['geometry'][j]['x'][k] == D[l]['geometry'][m]['x'][n] && D[i]['geometry'][j]['y'][k] == D[l]['geometry'][m]['y'][n]) {
+ if (D[i]['geometry'][j]['x'][k] == D[l]['geometry'][m]['x'][n] && D[i]['geometry'][j]['y'][k] == D[l]['geometry'][m]['y'][n]) {
+ D[l]['geometry'][m]['x'][n] = pos[0];
+ D[l]['geometry'][m]['y'][n] = pos[1];
+ if (snapped == true) {
+ removeDuplicates(l,m);
+ }
+ }
+ }
+ }
+ }
+
+ D[i]['geometry'][j]['x'][k] = pos[0];
+ D[i]['geometry'][j]['y'][k] = pos[1];
+ if (snapped == true) {
+ removeDuplicates(i,j);
+ }
+
+ snapped = false;
+ drawDashedLine();
+ }
+
+ // --- basepoint handling (end) -----------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------------------------------------------------------
+
+
+ //
+ // clones a given object
+ //
+
+ function cloneObject (someArray) {
+ var a = someArray;
+ var z = new Array();
+
+ for (attr in a) {
+ var b = a[attr];
+
+ if (typeof(b) == "object") {
+ z[attr] = cloneObject(b);
+ }
+ else {
+ z[attr] = b;
+ }
+ }
+ return z;
+ }
+
+
+ //
+ // clones a given geometry array
+ //
+
+ function cloneGeometryArray(originalArray) {
+ z = cloneObject(originalArray);
+
+ // add the attribute 'complete' for every geometry
+ for (var i = 0 ; i < originalArray['geometry'].length ; i ++) {
+ z['geometry'][i]['complete'] = true;
+ }
+ return z;
+ }
+
+
+ //
+ // a given geometry object is appended to the member array
+ //
+ function addMember(newMember) {
+ var index = D.length;
+ D[index] = new Array();
+
+ D[index] = cloneGeometryArray(newMember);
+
+ mod_digitize_go();
+ drawDashedLine();
+ }
+
+
+ function setEvent(obj){
+ mod_digitizeEvent = obj.id;
+ }
+
+ function delEvent(){
+ mod_digitizeEvent = false;
+ mod_digitize_go();
+ }
+
+ //
+ // displays an object
+ // (may not be essential, but useful for debugging)
+ //
+ function displayObject (someArray) {
+ var a = someArray;
+ var str = "";
+
+ for (attr in a) {
+ b = a[attr];
+
+ if (typeof(b) == "object") {
+ str += "<br>" + attr + "<br>";
+ str += displayObject(b);
+ }
+ else {
+ str += attr + ": " + b + "<br>";
+ }
+ }
+ return str;
+ }
+
+ //
+ // returns a form with the elements of a selected wfs
+ // (if the original wfs is the selected wfs, the values are set too)
+ //
+ function buildElementForm (wfsConfIndex, memberIndex) {
+ var selMember = memberIndex;
+ // if the selected wfs is not the original wfs,
+ // the form template, updating and deleting are disabled.
+ if (parseInt(D[memberIndex]['wfs_conf']) != parseInt(wfsConfIndex)) {
+ memberIndex = -1;
+ }
+
+ var str = "";
+
+ // the wfs conf needs to have a gid and a geom, otherwise saving does not work
+ var gid = false;
+ var geom = false;
+
+ var wfs = wfs_conf[wfsConfIndex];
+
+ var memEl;
+ if (parseInt(memberIndex) != -1) {
+ memEl = D[memberIndex]['element'];
+ }
+
+ // search attribute 'element' in wfsConfArray
+ for (attr in wfs) {
+ if (attr == "element") {
+ str += "<form id='wfs_conf'>\n\t<table>\n";
+
+ b = wfs[attr];
+
+ // get the 'element name' of wfsConfArray['element'][i]
+ for (var i = 0 ; i < b.length ; i ++) {
+ var c = b[i];
+
+ var wfsElementName = c['element_name'];
+
+ // don't display geoms
+ if (parseInt(c['f_geom']) != 1) {
+
+
+ if (parseInt(wfs['element'][i]['f_gid']) == 1) {
+ gid = wfsElementName;
+ }
+
+ //
+ // display the element name and an input row for its value
+ //
+ str += "\t\t<tr>\n\t\t\t<td>\n";
+ str += "\t\t\t\t" + wfsElementName + "\n\t\t\t</td>\n\t\t\t<td colspan = 2>\n";
+ str += "\t\t\t\t<input name='" + wfsElementName + "' type='text' size=20 ";
+
+ // only if the selected wfs is the original wfs!
+ if (parseInt(memberIndex) != -1) {
+ //
+ // get the 'element name' of memberArray['element'][j]
+ //
+ for (var j = 0 ; j < memEl.length ; j ++) {
+ currentElementName = memEl[j]['name'];
+ //
+ // if the element is in both objects, display the value as default
+ //
+ if (currentElementName == wfsElementName) {
+ str += "value = '" + memEl[j]['val'] + "' ";
+ }
+ }
+ }
+ str += ">\n";
+ str += "\t\t\t</td>\n\t\t</tr>\n";
+
+ }
+ else {
+ geom = wfsElementName;
+ }
+ }
+
+ //
+ // generating buttons "save", "update", "delete"
+ //
+
+ // a wfs_transaction url is required.
+ if (wfs['wfs_transaction']) {
+ str += "\t\t<tr>\n";
+
+ // if not all buttons will be generated, the missing columns will be generated afterwards.
+ var colspan = 0;
+
+ if (geom) {
+ str += "\t\t\t<td><input type='button' name='saveButton' value='Save' onclick='window.opener.saveGeom("+selMember+")' /></td>\n";
+ }
+ else {
+ colspan++;
+ }
+ if (parseInt(memberIndex) != -1 && gid) {
+ if (geom) {
+ str += "\t\t\t<td><input type='button' name='updateButton' value='Update' onclick='window.opener.updateGeom("+selMember+")'/></td>\n";
+ }
+ else {
+ colspan++;
+ }
+ str += "\t\t\t<td><input type='button' name='deleteButton' value='Delete' onclick='window.opener.deleteGeom("+selMember+")'/></td>\n";
+ }
+ else {
+ colspan++;
+ }
+
+ if (colspan > 0 && colspan < 3) {
+ str += "\t\t\t<td colspan = " + colspan + "></td>\n";
+ }
+
+ str += "\t\t</tr>";
+ }
+ str += "\t</table>\n";
+// str += "<input type='text' name='mb_geom'>";
+// str += "<input type='text' name='mb_wfs_conf'>";
+ str += "</form>\n";
+ }
+ }
+ return str;
+ }
+
+
+ //
+ // this method opens a new window and displays the attributes in wfs_conf
+ //
+ function showWfs(index) {
+
+ wfsWindow = open("", "wfsattributes", "width=300, height=300, resizable, dependent=yes, scrollbars=yes");
+ wfsWindow.document.open("text/html");
+ wfs_conf = parent.get_complete_wfs_conf();
+ var str = "";
+ var defaultIndex = -1;
+
+ str += "<form id='wfs'>\n\t<select name='wfs' size='" + wfs_conf.length + "'";
+ str += " onChange='document.getElementById(\"elementForm\").innerHTML = window.opener.buildElementForm(this.value , " + index + ")'";
+ str += ">\n\t\t";
+
+ for (var attr in wfs_conf) {
+ str += "<option value='" + attr + "'";
+
+ // if the geometry is already associated with a wfs
+ if (parseInt(D[index]['wfs_conf']) == parseInt(attr)) {
+ str += " selected";
+ defaultIndex = parseInt(attr);
+ }
+ str += ">" + wfs_conf[attr]['wfs_conf_abstract'];
+ str += "</option>\n\t\t";
+
+ }
+ str += "</select>\n\t\t</form>\n\t";
+ str += "<div id='elementForm'>\n</div>\n";
+
+ wfsWindow.document.write(str);
+ wfsWindow.document.close();
+
+ if (defaultIndex != -1) {
+ wfsWindow.document.getElementById("elementForm").innerHTML = buildElementForm(defaultIndex, index);
+ }
+ }
+
+
+
+ //
+ // updates the list of geometries.
+ // this function is invoked only at the end of drawDashedLines()
+ //
+ function updateListOfGeometries () {
+ var listOfGeom = "";
+
+ if (D.length > 0) {
+ listOfGeom += "<table>\n";
+ }
+
+ for (var i = 0 ; i < D.length; i ++) {
+ listOfGeom += "\t<tr>\n";
+ listOfGeom += "\t\t<td>\n";
+ listOfGeom += "\t\t\t<img src = '../img/button_digitize/geomInfo.png' title='WFS conf' onclick='showWfs("+i+")'>\n";
+ listOfGeom += "\t\t</td>\n";
+ listOfGeom += "\t\t<td>\n";
+ listOfGeom += "\t\t\t<img src = '../img/button_digitize/geomRemove.png' title='delete this " + D[i]['geomtype'] + "' onclick='deleteMember("+i+")'>\n";
+ listOfGeom += "\t\t</td>\n";
+ listOfGeom += "\t\t<td style = 'color:blue'>\n";
+ listOfGeom += "\t\t\t<div onmouseover='parent.mb_wfs_perform(\"over\",D["+i+"])' ";
+ listOfGeom += " onmouseout='parent.mb_wfs_perform(\"out\",D["+i+"])' ";
+
+ // if a geometry is a wfs result -> zoom to geometry
+
+ if (D[i]['wfs_conf'] != -1) {
+ listOfGeom += " onclick='parent.mb_wfs_perform(\"click\",D["+i+"]);' ";
+ }
+ // ... a geometry has been digitized by hand -> zoom to first point (FIXME: zooming to the entire geometry would be better)
+ else{
+ listOfGeom += " onclick='parent.zoom(mod_digitize_target,\"true\", 1.0, " + D[i]['geometry'][0]['x'][0] + ", " + D[i]['geometry'][0]['y'][0] + ");' ";
+ }
+ var geomName = parent.getElementValueByName(D, i, "name");
+ if (!geomName) {
+ geomName = "new";
+ }
+ var suffix = " ";
+ if (D[i]['geomtype'] == "Polygon") {
+ suffix += "(Py)";
+ }
+ else if (D[i]['geomtype'] == "Line") {
+ suffix += "(Li)";
+ }
+ if (D[i]['geomtype'] == "Point") {
+ suffix += "(Pt)";
+ }
+
+ listOfGeom += ">" + geomName + suffix +"</div>";
+ listOfGeom += "\t\t</td>\n";
+ }
+
+ if (D.length > 0) {
+ listOfGeom += "</table>\n";
+ }
+ parent.writeTag(mod_digitize_elName,"listOfGeometries",listOfGeom);
+ }
+function saveGeom(m){
+ var myform = wfsWindow.document.forms[0];
+ var ind = myform.wfs.selectedIndex;
+ var wfs = myform.wfs.options[ind].value;
+ myform = wfsWindow.document.forms[1];
+ D[m]['wfs_conf'] = wfs;
+ D[m]['element'] = new Array();
+ D[m]['element']['name'] = new Array();
+ D[m]['element']['val'] = new Array();
+ var cnt = 0;
+ for( var i=0; i<myform.length; i++){
+ if(myform.elements[i].type == 'text'){
+ D[m]['element'][cnt] = new Array();
+ D[m]['element'][cnt]['name'] = myform.elements[i].name;
+ D[m]['element'][cnt]['val'] = myform.elements[i].value;
+ cnt++;
+ }
+ }
+// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
+ var myconf = wfs_conf[D[m]['wfs_conf']];
+ alert(myconf['namespaces'][0]['name'] + " : " + myconf['namespaces'][0]['location']);
+ document.sendForm.url.value = myconf['wfs_transaction'];
+ var str = '<wfs:Transaction version="1.0.0" service="WFS" ';
+
+ for (var q = 0 ; q < myconf['namespaces'].length ; q++) {
+ str += 'xmlns:' + myconf['namespaces'][q]['name'] + '="' + myconf['namespaces'][q][location] + '" ';
+ }
+
+ str += 'xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd">';
+ str += '<wfs:Insert>';
+ str += '<'+ myconf['featuretype_name']+'>';
+ for(var i=0; i<D[m]['element'].length; i++){
+ if(D[m]['element'][i]['val'] != ""){
+ var tmp = D[m]['element'][i]['name'];
+ str += '<' + tmp + '>';
+ str += D[m]['element'][i]['val'];
+ str += '</' + tmp + '>';
+ }
+ }
+ for(var j=0; j<myconf['element'].length; j++){
+ if(myconf['element'][j]['f_geom'] == 1){
+ var el_geom = myconf['element'][j]['element_name'];
+ }
+ }
+ str += '<' + el_geom + '>';
+
+// if(dig.D[0].type == 'text'){
+// str += '<gml:Point srsName="epsg:4326">';
+// str += '<gml:coordinates>';
+// str += dig.D[0].x[0] + "," + dig.D[0].y[0];
+// str += '</gml:coordinates>';
+// str += '</gml:Point>';
+// }
+// if(dig.D[0].type == 'line'){
+// str += '<gml:MultiLineString srsName="epsg:4326">';
+// str += '<gml:lineStringMember>';
+// str += '<gml:LineString>';
+//
+// str += '<gml:coordinates>';
+// for(var k=0; k<dig.D[0].x.length; k++){
+// if(k>0){
+// str += " ";
+// }
+// str += dig.D[0].x[k] + "," + dig.D[0].y[k];
+// }
+// str += '</gml:coordinates>';
+// str += '</gml:LineString>';
+// str += '</gml:lineStringMember>';
+// str += '</gml:MultiLineString>';
+// }
+ if(D[m]['geomtype'] == 'Polygon'){
+ str += '<gml:MultiPolygon srsName="epsg:4326">';
+ str += '<gml:polygonMember>';
+ str += '<gml:Polygon>';
+ str += '<gml:outerBoundaryIs>';
+ str += '<gml:LinearRing>';
+
+ str += '<gml:coordinates>';
+ for(var k=0; k<D[m]['geometry'][0]['x'].length; k++){
+ if(k>0){
+ str += " ";
+ }
+ str += D[m]['geometry'][0]['x'][k] + "," + D[m]['geometry'][0]['y'][k];
+ }
+ str += '</gml:coordinates>';
+ str += '</gml:LinearRing>';
+ str += '</gml:outerBoundaryIs>';
+ str += '</gml:Polygon>';
+ str += '</gml:polygonMember>';
+ str += '</gml:MultiPolygon>';
+ }
+ str += '</' + el_geom + '>';
+ str += '</'+ myconf['featuretype_name']+'>';
+ str += '</wfs:Insert>';
+ str += '</wfs:Transaction>';
+ document.forms[1].filter.value = str;
+ document.forms[1].submit();
+ return false;
+}
+function updateGeom(m){
+ var myid_value;
+ var myform = wfsWindow.document.forms[0];
+ var ind = myform.wfs.selectedIndex;
+ var wfs = myform.wfs.options[ind].value;
+ myform = wfsWindow.document.forms[1];
+ D[m]['wfs_conf'] = wfs;
+ D[m]['element'] = new Array();
+ D[m]['element']['name'] = new Array();
+ D[m]['element']['val'] = new Array();
+ var cnt = 0;
+ for( var i=0; i<myform.length; i++){
+ if(myform.elements[i].type == 'text'){
+ D[m]['element'][cnt] = new Array();
+ D[m]['element'][cnt]['name'] = myform.elements[i].name;
+ D[m]['element'][cnt]['val'] = myform.elements[i].value;
+ if(D[m]['element'][cnt]['name'] == 'gid'){
+ myid_value = D[m]['element'][cnt]['val'];
+ }
+ cnt++;
+ }
+ }
+// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
+ var myconf = wfs_conf[D[m]['wfs_conf']];
+ document.sendForm.url.value = myconf['wfs_transaction'];
+ var str = '<wfs:Transaction version="1.0.0" service="WFS" xmlns="http://www.someserver.com/myns" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd" xmlns:topp="http://www.someserver.com/topp">';
+ str += '<wfs:Update typeName="'+ myconf['featuretype_name']+'">';
+ for(var i=0; i<D[m]['element'].length; i++){
+ if(D[m]['element'][i]['val'] != ""){
+ str += '<wfs:Property>';
+ str += '<wfs:Name>'+D[m]['element'][i]['name']+'</wfs:Name>';
+ str += '<wfs:Value>'+D[m]['element'][i]['val']+'</wfs:Value>';
+ str += '</wfs:Property>';
+ }
+ }
+ for(var j=0; j<myconf['element'].length; j++){
+ if(myconf['element'][j]['f_geom'] == 1){
+ var el_geom = myconf['element'][j]['element_name'];
+ }
+ }
+// str += '<' + el_geom + '>';
+
+// if(dig.D[0].type == 'text'){
+// str += '<gml:Point srsName="epsg:4326">';
+// str += '<gml:coordinates>';
+// str += dig.D[0].x[0] + "," + dig.D[0].y[0];
+// str += '</gml:coordinates>';
+// str += '</gml:Point>';
+// }
+// if(dig.D[0].type == 'line'){
+// str += '<gml:MultiLineString srsName="epsg:4326">';
+// str += '<gml:lineStringMember>';
+// str += '<gml:LineString>';
+//
+// str += '<gml:coordinates>';
+// for(var k=0; k<dig.D[0].x.length; k++){
+// if(k>0){
+// str += " ";
+// }
+// str += dig.D[0].x[k] + "," + dig.D[0].y[k];
+// }
+// str += '</gml:coordinates>';
+// str += '</gml:LineString>';
+// str += '</gml:lineStringMember>';
+// str += '</gml:MultiLineString>';
+// }
+ if(D[m]['geomtype'] == 'Polygon'){
+ str += '<wfs:Property>';
+ str += '<wfs:Name>' + el_geom + '</wfs:Name>';
+ str += '<wfs:Value>';
+ str += '<gml:MultiPolygon srsName="epsg:4326">';
+ str += '<gml:polygonMember>';
+ str += '<gml:Polygon>';
+ str += '<gml:outerBoundaryIs>';
+ str += '<gml:LinearRing>';
+
+ str += '<gml:coordinates>';
+ for(var k=0; k<D[m]['geometry'][0]['x'].length; k++){
+ if(k>0){
+ str += " ";
+ }
+ str += D[m]['geometry'][0]['x'][k] + "," + D[m]['geometry'][0]['y'][k];
+ }
+ str += '</gml:coordinates>';
+ str += '</gml:LinearRing>';
+ str += '</gml:outerBoundaryIs>';
+ str += '</gml:Polygon>';
+ str += '</gml:polygonMember>';
+ str += '</gml:MultiPolygon>';
+ str += '</wfs:Value>';
+ str += '</wfs:Property>';
+ }
+// str += '</' + el_geom + '>';
+ str += '<ogc:Filter>';
+ str += '<ogc:PropertyIsEqualTo>';
+ str += '<ogc:PropertyName>gid</ogc:PropertyName>';
+ str += '<ogc:Literal>'+myid_value+'</ogc:Literal>';
+ str += '</ogc:PropertyIsEqualTo>';
+ str += '</ogc:Filter>';
+ str += '</wfs:Update>';
+ str += '</wfs:Transaction>';
+ document.forms[1].filter.value = str;
+ //prompt("",str);
+ document.forms[1].submit();
+ return false;
+}
+function deleteGeom(m){
+ var myid_value;
+ var myform = wfsWindow.document.forms[0];
+ var ind = myform.wfs.selectedIndex;
+ var wfs = myform.wfs.options[ind].value;
+ myform = wfsWindow.document.forms[1];
+ D[m]['wfs_conf'] = wfs;
+ D[m]['element'] = new Array();
+ D[m]['element']['name'] = new Array();
+ D[m]['element']['val'] = new Array();
+ var cnt = 0;
+ for( var i=0; i<myform.length; i++){
+ if(myform.elements[i].type == 'text'){
+ D[m]['element'][cnt] = new Array();
+ D[m]['element'][cnt]['name'] = myform.elements[i].name;
+ D[m]['element'][cnt]['val'] = myform.elements[i].value;
+ if(D[m]['element'][cnt]['name'] == 'gid'){
+ myid_value = D[m]['element'][cnt]['val'];
+ }
+ cnt++;
+ }
+ }
+// alert(wfs_conf[D[m]['wfs_conf']]['wfs_transaction']);
+ var myconf = wfs_conf[D[m]['wfs_conf']];
+ document.sendForm.url.value = myconf['wfs_transaction'];
+ var str = '<wfs:Transaction version="1.0.0" service="WFS" xmlns="http://www.someserver.com/myns" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd" xmlns:topp="http://www.someserver.com/topp">';
+ str += '<wfs:Delete typeName="'+ myconf['featuretype_name']+'">';
+ for(var j=0; j<myconf['element'].length; j++){
+ if(myconf['element'][j]['f_geom'] == 1){
+ var el_geom = myconf['element'][j]['element_name'];
+ }
+ }
+
+ str += '<ogc:Filter>';
+ str += '<ogc:PropertyIsEqualTo>';
+ str += '<ogc:PropertyName>gid</ogc:PropertyName>';
+ str += '<ogc:Literal>'+myid_value+'</ogc:Literal>';
+ str += '</ogc:PropertyIsEqualTo>';
+ str += '</ogc:Filter>';
+ str += '</wfs:Delete>';
+ str += '</wfs:Transaction>';
+ document.forms[1].filter.value = str;
+ //prompt("",str);
+ document.forms[1].submit();
+ return false;
+}
+ </script>
+ </head>
+ <body onload="registerFunctions()">
+ <table cellpadding='0' cellspacing='0' align = center>
+ <tr>
+ <td>
+ <form name='dig'>
+ <table cellpadding='0' cellspacing='2'>
+ <tr>
+ <td>
+ <img name='Point' onmouseover='register_button(this)' id='Point' title="Add point" src = '../img/button_digitize/text_up.png'>
+ </td>
+ <td>
+ <img name='Line' onmouseover='register_button(this)' id='Line' title="Add line" src = '../img/button_digitize/line_up.png'>
+ </td>
+ <td>
+ <img name='Polygon' onmouseover='register_button(this)' id='Polygon' title="Add polygon" src = '../img/button_digitize/poly_up.png'>
+ </td>
+ <td>
+
+ </td>
+ <td>
+ <img name='dragBasePoint' onmouseover='register_button(this)' id='dragBasePoint' title="Move node" src = '../img/button_digitize/move_up.png'>
+ </td>
+ <td>
+ <img name='setBasePoint' onmouseover='register_button(this)' id='setBasePoint' title="Add node" src = '../img/button_digitize/newNode_up.png'>
+ </td>
+ <td>
+ <img name='delBasePoint' onmouseover='register_button(this)' id='delBasePoint' title="Delete node" src = '../img/button_digitize/delNode_up.png'>
+ </td>
+ </tr>
+ </table>
+ </form>
+ </td>
+ </tr>
+ </table>
+ <div id = 'listOfGeometries'></div>
+ <form name='sendForm' action='../extensions/geom2wfst.php' method='POST' TARGET='_blank'>
+ <input type='hidden' name='url'>
+ <input type='hidden' name='filter'>
+ </form>
+ </body>
</html>
\ No newline at end of file
More information about the Mapbender_commits
mailing list