/* ************************************************* FILENAME: agsIdentify.js.php AUTHOR: André von Wartburg CREATED: 20. 07. 2010 COPYRIGHT: rawi-geo. Alle Rechte vorbehalten. DESCRIPTION: feature identify functionality CHANGES: 02. 2015 refactoring, JSHint TODO: - 3D panels (mammut.ch, me.com) - make id LOD-dependent - Pin should stay. Only show one feature at a time. - Checks - id services specified in app_config must exist in svc_config - Store highlight info in layer-specific uniquely identifibiable form (array / var?) ************************************************** */ var identifyTask = []; var idTaskParams = []; var idServiceIds = []; // arr w/ names of identifiable svc var idLayers = []; // 2-D arr w/ lyr ids (by sequential svc number) var idFieldInfo = []; // 2-D arr w/ field info (by sequential lyr number) var idLayerResults = []; var noResultsReturned = 0; var featureDisplayStore = []; var idDisplayOneResult = true; // if true, only first result is displayed idServiceIds = ["ext_div"]; identifyTask[0] = new esri.tasks.IdentifyTask("http://svc.geo.lu.ch/AGS/rest/services/ext/ext_div/MapServer"); idLayers[0] = [1]; idFieldInfo[0] = [ ["OBJECTID","Dekanat","Pastoralraumnummer","Kantonsnummer (Bistum Basel)","Pfarrei","Link der Pfarrei:Webseite Pfarrei:LINK"] ]; // identify task config params idTaskParams = new esri.tasks.IdentifyParameters(); idTaskParams.tolerance = 2; // keep low for fewer results idTaskParams.returnGeometry = true; idTaskParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; //problem w/ _VISIBLE (scale dependency) // symbol definitions var idSymbolPoint = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 3), new dojo.Color([255, 255, 255, 0.0])); var idSymbolFill = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 3), new dojo.Color([255, 255, 255, 0.0])); var idLocationMarker = new esri.symbol.PictureMarkerSymbol("../../src/img/pin_identify.png", 30, 28); idLocationMarker.setOffset(15, 13); // trigger identify process // evt: click on map (onclick evt) function doIdentify(evt) { if (typeof(printOptions) != "undefined") { printOptions.print.comments = ""; } // ??? featureDisplayStore.length = 0; // unset object noResultsReturned = 0; dojo.byId("idResultsTitle").innerHTML = ' Abfrage läuft ...'; idTaskParams.geometry = evt.mapPoint; // loaction where the map was clicked idTaskParams.mapExtent = map.extent; // current map extent markLocation(evt); // mark identify location on map executeIdTask(0); // start with first service... } // execute identify task // currSvc: svc to identify (number) function executeIdTask(currSvc) { var _visLyr = [], // currently visible layers (number array) _visState, // visbility of layer (bool) _taskResultsDummy = [], // dummy results for svc with no identifiable lyrs (empty array) _currSvcId = idServiceIds[currSvc]; // ID-name of current service (e.g 'rawi_av') // get currently visible layers (check TOC settings) if ((_currSvcId != 'int_query') && (_currSvcId != 'rawi_av')) { for (var j=0; j < idLayers[currSvc].length; j++) { _visState = layerStore[_currSvcId][idLayers[currSvc][j]].vis; //console.log("ID: " + layerStore[idServiceIds[currSvc]][idLayers[currSvc][j]].name_ags + "(id:" + idLayers[currSvc][j] +") , vis:" + _visState); if (_visState == 1) { _visLyr.push(idLayers[currSvc][j]); } } idTaskParams.layerIds = _visLyr; } // get lyrs for svc contents are always invisible (int_query, rawi_av) else { idTaskParams.layerIds = idLayers[currSvc]; } // SOME identifiable lyrs visible: call server and handle results if (idTaskParams.layerIds.length != 0) { identifyTask[currSvc].execute(idTaskParams, function(taskResults) { // DEBUG: idTask working if (internalDebug) { console.log("STATUS (executeIdTask): identify " + idTaskParams.layerIds.length + " (IDs: " + idTaskParams.layerIds + ") of " + idLayers[currSvc].length + " lyrs (IDs: " + idLayers[currSvc] + ") from svc " + idServiceIds[currSvc] + "(" + currSvc + ")." ); } addToMap(taskResults, currSvc); }); } // NO identifiable lyrs visible else { addToMap(_taskResultsDummy, currSvc); } } // add returned results to map - runs once per identified svc // idTaskRes: results of IdentifyTask (object) // currSvc: position of identified service in idLayers[] (number) function addToMap(idTaskRes, currSvc) { var _statusTxt, // status message for current service (string) _domId, // ID of layers panel div in DOM (string) _idLyrPos, // position of lyr in idLayers[currSvc] _rand, // random number _currSvcId = idServiceIds[currSvc]; // ID-name of current service (e.g 'rawi_av') // create empty object to hold returned features for each identifiable lyr for (var j=0; j < idLayers[currSvc].length; j++) { idLayerResults[j] = {features:[]}; } // fill idLayerResults with returned features per layer for (var i=0; i < idTaskRes.length; i++) { _idLyrPos = esri.valueOf(idLayers[currSvc], idTaskRes[i].layerId); //get position of idTaskRes[i].layerId in array idLayers of currently id'd service. idLayerResults[_idLyrPos].features.push(idTaskRes[i].feature); } // DEBUG: IdentifyTask results if (internalDebug) { if (idLayers[currSvc].length > 0) { _statusTxt = "STATUS (addToMap): IdentifyTask on svc "+ _currSvcId + " returned " + idTaskRes.length + " results (by Id: "; for (var m=0; m < idLayers[currSvc].length; m++) { _statusTxt += idLayers[currSvc][m] + ": "+ idLayerResults[m].features.length + ", " ; } _statusTxt += ")."; } else { _statusTxt = "STATUS (addToMap): IdentifyTask on svc "+ _currSvcId + " returned no results."; } console.log(_statusTxt); } // render content in precreated DOM-panels for (var k=0; k < idLayers[currSvc].length; k++) { _domId = "id_" + _currSvcId + "_" + idLayers[currSvc][k]; // +++ SPECIAL content (external file) +++ if ( ((_currSvcId == 'rawi_av') || (_currSvcId == 'int_query')) && (layerStore[_currSvcId][idLayers[currSvc][k]].name_ags == 'av_prz') ) { if (idLayerResults[k].features.length > 0) { _rand = Math.floor(Math.random() * 100001); featureDisplayStore[_rand] = idLayerResults[k].features[0]; var GBPER_CODE = idLayerResults[k].features[0].attributes["Code Grundbuchperimeter"]; var NUMMER = idLayerResults[k].features[0].attributes["Nummer"]; dijit.byId(_domId).attr('href', "../../src/inc/get_av_gsbeschrieb.php?GBP=" + GBPER_CODE + "&PRZ=" + NUMMER + "&FID=" + _rand); } } // +++ REGULAR content (identifyTask) +++ else { dijit.byId(_domId).attr('content', renderIdContent(idLayerResults[k], k, currSvc)); } // close panel with no hits and vice versa if ((idLayerResults[k].features.length == 0)) { dojo.byId(_domId).style.display = "none"; } if ((idLayerResults[k].features.length != 0)) { noResultsReturned = 1; dojo.byId(_domId).style.display = "block"; } } dojo.byId("idResults").style.display = "block"; // call next id if services left if (idServiceIds[currSvc + 1]) { executeIdTask(currSvc + 1); } else { if (noResultsReturned == 0) { dojo.byId("idResultsNone").style.display = "block"; } else { dojo.byId("idResultsNone").style.display = "none"; } dojo.byId("idResultsTitle").innerHTML = 'Abfrageresultate'; } } // render returned id results for display pre-created DOM containers // idLayerResults: returned id information for this layer (object) // idLyrPos: this layers position in idLayers array (integer) // idSvcPos: id of identifiebale svc containing this layer (integer) function renderIdContent(idLayerResults, idLyrPos, idSvcPos) { var _html = "", // HTML to insert in panel _currSvcId, // ID-name of current service (e.g 'rawi_av') _currLyrNum, // number of layer's position in service _isSR, // render 'AV Selbstrechte' differently _bits, _rand, _fieldName, // 0 = field name _fieldAlias, // 1 = field alias (optional) _fieldFormattingKeyword, // 2 = field formatting keyword (optional) _fieldValue; // field value (returned form IdentifyTask) var OBJECTID, ART, NUMMER, EGRIS_EGRID, GBPER_CODE, GBPER_NAME, GEMEINDE, BFSNR, FLAECHENMASS, KATEGORIE, HOEHE, LAGE_X, LAGE_Y, ZEICHEN, IDENTIFIKATOR; _currSvcId = idServiceIds[idSvcPos]; _currLyrNum = idLayers[idSvcPos][idLyrPos]; // SOME results were returned if (idLayerResults.features.length > 0) { _rand = Math.floor(Math.random( ) * 100001); // +++ SPECIAL rendering +++ //if (((_currSvcId == 'rawi_av') || (_currSvcId == 'int_query')) && ((layerStore[_currSvcId][_currLyrNum].name_ags == 'av_prz') || (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_sr') || (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_prz_proj') || (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_sr_proj') )){ if ((_currSvcId == 'rawi_av') && ((layerStore[_currSvcId][_currLyrNum].name_ags == 'av_sr') || (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_prz_proj') || (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_sr_proj') )){ featureDisplayStore[_rand] = idLayerResults.features[0]; _isSR = 0; if (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_sr') {_isSR = 1;} if (_isSR == 1) { ART = idLayerResults.features[0].attributes["Klasse"]; } NUMMER = idLayerResults.features[0].attributes["Nummer"]; EGRIS_EGRID = idLayerResults.features[0].attributes["ID el. Grundstückinformationssystem"]; GBPER_CODE = idLayerResults.features[0].attributes["Code Grundbuchperimeter"]; GBPER_NAME = idLayerResults.features[0].attributes["Grundbuchperimetername"]; GEMEINDE = idLayerResults.features[0].attributes["Gemeindename"]; BFSNR = idLayerResults.features[0].attributes["BFS-Gemeindenummer"]; FLAECHENMASS = idLayerResults.features[0].attributes["Fläche"]; _html += ""; _html += " "; _html += ""; if (_isSR == 1) { _html += ""; } _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; //_html += ""; _html += "
 zoom | zeigen | ausblenden"; _html += "
Art" + ART + "
Grundstücknummer" + NUMMER + "
Eidg. Grundstück-ID (EGRID)" + EGRIS_EGRID + "
Gemeinde (BfS-Nr.)" + GEMEINDE + " (" + BFSNR + ")
Grundbuch (GB-Nr.)" + GBPER_NAME + " (" + GBPER_CODE + ")
Fläche (grundbuchlich)" + formatIdResult(FLAECHENMASS, 'AREA') + "
 
"; } // +++ SPECIAL rendering +++ if ((_currSvcId == 'ext_div') && (layerStore[_currSvcId][_currLyrNum].name_ags == 'bistum_pfarreien')) { featureDisplayStore[_rand] = idLayerResults.features[0]; DEKANAT = idLayerResults.features[0].attributes["Dekanat"]; PFR = idLayerResults.features[0].attributes["Pfarrei"]; KT_BB = idLayerResults.features[0].attributes["KT_BB"]; PR_NR = idLayerResults.features[0].attributes["Pastoralraumnummer"]; PR = idLayerResults.features[0].attributes["Pastoralraum"]; PR_ID = idLayerResults.features[0].attributes["Code Grundbuchperimeter"]; PFR_LINK = idLayerResults.features[0].attributes["Link der Pfarrei"]; _html += ""; _html += " "; _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; _html += "
 zoom | zeigen | ausblenden"; _html += "
Dekanat" + DEKANAT + "
Pfarrei" + PFR + "
Pastoralraum" + KT_BB +" "+ PR_NR + " " + PR + "
Webseite Pfarrei" + PFR_LINK + "
"; } else if ((_currSvcId == 'rawi_av') && (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_fix')){ featureDisplayStore[_rand] = idLayerResults.features[0]; OBJECTID = idLayerResults.features[0].attributes["OBJECTID"]; NUMMER = idLayerResults.features[0].attributes["Nummer"]; GEMEINDE = idLayerResults.features[0].attributes["Gemeindename"]; KATEGORIE = idLayerResults.features[0].attributes["Fixpunktkategorie"]; ZEICHEN = idLayerResults.features[0].attributes["Punktzeichen"]; HOEHE = idLayerResults.features[0].attributes["Höhe ü. Meer [m]"]; LAGE_X = idLayerResults.features[0].attributes["X-Koordinate"]; LAGE_Y = idLayerResults.features[0].attributes["Y-Koordinate"]; _html += ""; _html += " "; _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; _html += "
Objekt '" + OBJECTID + "'zoom | zeigen | ausblenden"; _html += "
Nummer" + NUMMER + "
Gemeinde" + GEMEINDE + "
Kategorie/Art" + KATEGORIE + "
Punktzeichen" + ZEICHEN + "
Höhe" + formatIdResult(HOEHE, 'ELEV') + "
Lage" + LAGE_X + " / "+ LAGE_Y + "
"; } else if ((_currSvcId == 'rawi_av') && (layerStore[_currSvcId][_currLyrNum].name_ags == 'av_grenzpunkte')){ featureDisplayStore[_rand] = idLayerResults.features[0]; OBJECTID = idLayerResults.features[0].attributes["OBJECTID"]; IDENTIFIKATOR = idLayerResults.features[0].attributes["Identifikator"]; GEMEINDE = idLayerResults.features[0].attributes["Gemeindename"]; LAGE_X = idLayerResults.features[0].attributes["X-Koordinate"]; LAGE_Y = idLayerResults.features[0].attributes["Y-Koordinate"]; ZEICHEN = idLayerResults.features[0].attributes["Punktzeichen"]; _html += ""; _html += " "; _html += ""; _html += ""; _html += ""; _html += ""; _html += ""; _html += "
Objekt '" + OBJECTID + "'zoom | zeigen | ausblenden"; _html += "
Identifikator" + IDENTIFIKATOR + "
Gemeinde" + GEMEINDE + "
Punktzeichen" + ZEICHEN + "
Lage" + LAGE_X + " / "+ LAGE_Y + "
"; } // +++ REGULAR rendering +++ else { _html += ""; // loop returned features (in this layers array...) for (var i=0; i < idLayerResults.features.length; i++) { // DEBUG: No fields specified if (internalDebug) { if (idFieldInfo[idSvcPos][idLyrPos].length == 0) { console.log("ERROR: Layer " + _currLyrNum + " is identifiable but no fields have been specified." ); } } // loop thru current layers layerFieldInfo array for (var j=0; j< idFieldInfo[idSvcPos][idLyrPos].length; j++) { _bits = idFieldInfo[idSvcPos][idLyrPos][j].split(":"); _fieldName = _bits[0]; _fieldAlias = _bits[1]; _fieldFormattingKeyword = _bits[2]; _fieldValue = idLayerResults.features[i].attributes[_fieldName]; // assign FieldValue to var for ease of handling // DEBUG: specified fields not found if (internalDebug) { if (!(_fieldValue)) { console.log("WARNING (renderIdContent): specified field '" + _fieldName + "' is not included in returned fields for layer " + _currLyrNum + " (may be NULL)." ); } } if (j == 0 ) { featureDisplayStore[_rand] = idLayerResults.features[i]; _html += ""; _html += ""; } else { _html += ""; } } // display first result only if (idDisplayOneResult) { break; } } _html += "
 zoom | zeigen | ausblenden"; _html += "
"; // use FieldNameAlias if defined if (_fieldAlias) { _html += _fieldAlias; } else { _html += _fieldName; } _html += ""; // format content if keyword is specified if (_fieldFormattingKeyword) { _html += formatIdResult(_fieldValue, _fieldFormattingKeyword); } else { // catch empty fields (string 'NULL' is returned) if( _fieldValue == "Null" ) { _html += "-"; } else { _html += _fieldValue; } } _html += "
"; } } // NO results were returned else { _html += "kein Treffer."; } return _html; } // format string (e.g. a field value) by keyword function formatIdResult(content, keyword) { var _fContent, // the formatted content _number, // the string as number _He, // hectares _Ar, // ares _M2, // square meters _numberTMP; switch (keyword) { // AREA: swiss style areas // METER: add unit of measurement 'm' // ELEV: add unit of measurement for elevations 'm. ü. M.' // LINK: style as external link // PDF: style as link to PDF // ZIP: style as link to ZIP case "AREA": _number = parseFloat(content).toFixed(0); // reduce to whole squaremetres _He = Math.floor(_number / 10000); // calc hectares _Ar = Math.floor((_number - (_He * 10000))/100); // calc ares _M2 = _number - (_He * 10000) - (_Ar * 100); // calc squaremeters if (_number < 1000000) { if (_He == 0) { _fContent = _number + " m²"; } else { _numberTMP = (_number / 10000); // ha _fContent = _numberTMP.toFixed(2) + " ha"; } } else { _numberTMP = (_number / 1000000); // km2/ha/a/m2 _fContent = _numberTMP.toFixed(2) + " km²"; } break; case "METER": _fContent = parseInt(content).toFixed(2) + " m"; break; case "ELEV": _fContent = content + " m.ü.M"; break; case "LINK": if ((_fContent != "") || (_fContent != null)) { _fContent = "Link"; } else { _fContent = "nicht vorhanden"; } break; case "PDF": _fContent = "PDF-Dokument"; break; case "ZIP": _fContent = "ZIP-Datei"; break; } return _fContent; } /* ++++++++++++++++ helper functions ++++++++++++++++ */ // mark id location on map function markLocation(evt) { var _idLocationGraphic; // graphic containing location marker map.graphics.clear(); _idLocationGraphic = new esri.Graphic(evt.mapPoint, idLocationMarker); map.graphics.add(_idLocationGraphic); } // highlight single feature on map function showFeature(ft) { map.graphics.clear(); if (ft.geometry.type == "point") { ft.setSymbol(idSymbolPoint); } else { ft.setSymbol(idSymbolFill); } map.graphics.add(ft); } // zoom and center (and highlight) feature on map function zoomFeature(ft) { var _newCenter, _newExtent; showFeature(ft); if (ft.geometry.type == "point") { _newCenter = new esri.geometry.Point(ft.geometry.x, ft.geometry.y, new esri.SpatialReference({ wkid: 21781 })); map.centerAndZoom(_newCenter, 11); } else { // TO-DO: Only zoom if getExtent bigger than current extent _newExtent = ft.geometry.getExtent(); map.setExtent(_newExtent, true); } } // hide results panel function hideIdResults() { dojo.byId('idResults').style.display = 'none'; map.graphics.clear(); }