/* ************************************************* FILENAME: agsIdentify.js.php AUTHOR: André von Wartburg CREATED: 20. 07. 2010 COPYRIGHT: rawi-geo. Alle Rechte vorbehalten. DESCRIPTION: feature identify functionality CHANGES: 08. 05. 2012 JSLinted 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 identifyParams = []; var symbol; 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 = []; idServiceIds = ["uwe_div", "int_query"]; identifyTask[0] = new esri.tasks.IdentifyTask("http://svc.geo.lu.ch/main0/rest/services/uwe/uwe_div/MapServer"); identifyTask[1] = new esri.tasks.IdentifyTask("http://svc.geo.lu.ch/main0/rest/services/basis/int_query/MapServer"); idLayers[0] = [70]; idLayers[1] = [4]; idFieldInfo[0] = [ ["OBJECTID","Teildachfläche [m2]","Eignung","Mittlere Einstrahlung pro Jahr [kWh/m2/a]","Photovoltaikertrag pro Jahr [kWh/a]","Solarthermieertrag pro Jahr [kWh/a]"] ]; idFieldInfo[1] = [ ["OBJECTID","Nummer:Grundstücknummer","Gemeindename","BFS-Gemeindenummer:BFS-Nummer","Code Grundbuchperimeter:Grundbuchperimetercode","Fläche:Fläche (grundbuchlich):AREA"] ]; // secondary config params identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 1; // keep low for fewer results identifyParams.returnGeometry = true; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; //problem w/ _VISIBLE (scale dependency) var idDisplayOneResult = true; // if true, only first result is displayed // symbols for result highlighting 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 idSymbol = 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])); // add returned results to map - runs once per service function addToMap(idResults, currSvc) { var i, j, idResult, statusTxt, setPanel, idLayersPos; // setup array w/ returned features for for each identifiable layer for (j=0; j < idLayers[currSvc].length; j++) { idLayerResults[j] = {features:[]}; } // fill arrays with returned features for (i=0; i < idResults.length; i++) { idResult = idResults[i]; idLayersPos = esri.valueOf(idLayers[currSvc], idResult.layerId); //get position of idResult.layerId in array idLayers of currently id'd service. idLayerResults[idLayersPos].features.push(idResult.feature); } // DEBUG: IdentifyTask results if (internalDebug) { statusTxt = "STATUS: IdentifyTask returned " + idResults.length + " results. (By Id: "; for (j=0; j < idLayers[currSvc].length; j++) { statusTxt += idLayers[currSvc][j] + ": "+ idLayerResults[j].features.length + ", " ; } statusTxt += ")"; console.log(statusTxt); } // put content in precreated panels for (j=0; j < idLayers[currSvc].length; j++) { setPanel = "id_" + idServiceIds[currSvc] + "_" + idLayers[currSvc][j]; dijit.byId(setPanel).attr('content', idPanelContent(idLayerResults[j], j, currSvc)); // close panel with no hits and vice versa if ((idLayerResults[j].features.length == 0)) { dojo.byId(setPanel).style.display="none"; } if ((idLayerResults[j].features.length != 0)) { noResultsReturned = 1; // all panels open if (!(dijit.byId(setPanel).open)) { dijit.byId(setPanel).toggle(); } // all panels closed // if (dijit.byId(setPanel).open) { dijit.byId(setPanel).toggle(); } dojo.byId(setPanel).style.display="block"; } } dojo.byId("idResults").style.display = "block"; // call next id if services left if (idServiceIds[currSvc + 1]) { startIdTask(currSvc + 1); } else { if (noResultsReturned == 0) { dojo.byId("idResultsNone").style.display = "block"; } else { dojo.byId("idResultsNone").style.display = "none"; } dojo.byId("idResultsTitle").innerHTML = 'Abfrageresultate'; //dojo.byId("idResults").style.display = "block"; } } // call id server process function startIdTask(currSvc) { var visLyr, j, visState, idResultsDummy; // to catch: very special case: id sth that is not in biz lyr --> e.g. parcels from int_query. visLyr = []; // only query currently visible layers if ((idServiceIds[currSvc] != 'int_query') && (idServiceIds[currSvc] != 'rawi_av')) { for (j=0; j < idLayers[currSvc].length; j++) { visState = layerStore[idServiceIds[currSvc]][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]); } } identifyParams.layerIds = visLyr; } // svc whose lyrs are always invisible else { identifyParams.layerIds = idLayers[currSvc]; } // SOME identifiable lyrs visible: call server and handle results if (identifyParams.layerIds.length != 0) { identifyTask[currSvc].execute(identifyParams, function(idResults) { // DEBUG: idTask working if (internalDebug) { console.log("STATUS: id " + identifyParams.layerIds.length + " (Id: " + identifyParams.layerIds + ") of " + idLayers[currSvc].length + " lyrs (Id: " + idLayers[currSvc] + ") from svc " + idServiceIds[currSvc] + "(" + currSvc + ")." ); } addToMap(idResults, currSvc); }); } // NO identifiable lyrs visible: impersonate empty results else { idResultsDummy = []; addToMap(idResultsDummy, currSvc); } } // onclick identify event function doIdentify(evt) { var idLocationMarker, idLocationGraphic; map.graphics.clear(); featureDisplayStore.length = 0; // unset featureDisplayStore arr dojo.byId("idResultsTitle").innerHTML = ' Abfrage läuft ...'; noResultsReturned = 0; idLocationMarker = new esri.symbol.PictureMarkerSymbol("../../src/img/pin_identify.png", 30, 28); idLocationMarker.setOffset(15, 13); idLocationGraphic = new esri.Graphic(evt.mapPoint, idLocationMarker); map.graphics.add(idLocationGraphic); identifyParams.geometry = evt.mapPoint; // where the map was clicked identifyParams.mapExtent = map.extent; // map extent // SET REPORTING PARAMS reportOptions.report.mapCenter.x = identifyParams.geometry.x; reportOptions.report.mapCenter.y = identifyParams.geometry.y; startIdTask(0); // start at first service... } // render returned results for display function idPanelContent(idLayerResults, layerArrayPos, currentService) { var i, content, regularRendering, isSR, j, idFieldInfoChunk, idFieldInfoBit, OBJECTID, ART, NUMMER, GBPER_CODE, GBPER_NAME, GEMEINDE, BFSNR, FLAECHENMASS, KATEGORIE, HOEHE, LAGE_X, LAGE_Y, ZEICHEN, IDENTIFIKATOR, randomnumber, idFieldValue, featureDisplayStoreKey; content = ""; regularRendering = 1; // SOME results were returned if (idLayerResults.features.length > 0) { //tmp1 = idLayers[currentService]; // ++++++++++++++++++++++++++ // SPECIAL layer treatment // +++++++++++++++++++++++++++ //if ((idServiceIds[currentService] == 'rawi_av') && (idLayers[currentService][layerArrayPos] == 23)){ if (((idServiceIds[currentService] == 'rawi_av') || (idServiceIds[currentService] == 'int_query')) && ((layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'av_prz') || (layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'av_sr') || (layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'av_prz_proj') || (layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'av_sr_proj') )){ regularRendering = 0; isSR = 0; // render Selbstrechte differently if (layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'av_sr') {isSR = 1;} content += ""; // loop thru current layers layerFieldInfo array for (j=0; j < idFieldInfo[currentService][layerArrayPos].length; j++) { // 0 = FieldName, 1 = FieldNameAlias (optional) , 2 = Formatting Keyword (optional) idFieldInfoChunk = idFieldInfo[currentService][layerArrayPos][j]; idFieldInfoBit = idFieldInfoChunk.split(":"); // OBJECTID = idLayerResults.features[0].attributes["OBJECTID"]; 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"]; // SAREA = idLayerResults.features[0].attributes["SHAPE.AREA"]; // SET REPORTING PARAMS reportOptions.report.title = "Grundstück Nr. " + NUMMER + ", " + GEMEINDE + " (Grundbuch: " + GBPER_NAME + ")"; // SHOW SPECIAL INFO PANEL FOR STADT LUZERN if (GBPER_CODE == '111' || GBPER_CODE == '112') { dojo.byId("infoLUZE").style.display = "block"; dojo.byId("infoKT").style.display = "none"; } else { dojo.byId("infoLUZE").style.display = "none"; dojo.byId("infoKT").style.display = "block"; } } //content += " "; content += " "; randomnumber = Math.floor(Math.random()*100001); featureDisplayStore[randomnumber] = idLayerResults.features[0]; content += ""; if (isSR == 1) { content += ""; } content += ""; content += ""; content += ""; content += ""; content += ""; //content += ""; content += ""; content += "
Objekt '" + ID + "'
 zoom | zeigen | ausblenden"; content += "
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') + "
Fläche (gerechnet)" + formatIdResult(SAREA, 'AREA') + "
"; } if ((idServiceIds[currentService] == 'uwe_div') && (layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags == 'solarpot_katast')){ regularRendering = 0; content += ""; for (j=0; j < idFieldInfo[currentService][layerArrayPos].length; j++) { // 0 = FieldName, 1 = FieldNameAlias (optional) , 2 = Formatting Keyword (optional) idFieldInfoChunk = idFieldInfo[currentService][layerArrayPos][j]; idFieldInfoBit = idFieldInfoChunk.split(":"); OBJECTID = idLayerResults.features[0].attributes["OBJECTID"]; TDF_UID = idLayerResults.features[0].attributes["Teildachflächen-Identifikator"]; TD_FLAECHE = idLayerResults.features[0].attributes["Teildachfläche [m2]"]; EIGNUNG = idLayerResults.features[0].attributes["Eignung"]; MITTLERE_EINST = idLayerResults.features[0].attributes["Mittlere Einstrahlung pro Jahr [kWh/m2/a]"]; PV_ERTRAG = idLayerResults.features[0].attributes["Photovoltaikertrag pro Jahr [kWh/a]"]; ST_ERTRAG = idLayerResults.features[0].attributes["Solarthermieertrag pro Jahr [kWh/a]"]; // SET REPORTING PARAMS reportOptions.report.query.conditionFieldValue = TDF_UID; } content += " "; randomnumber = Math.floor(Math.random()*100001); featureDisplayStore[randomnumber] = idLayerResults.features[0]; content += ""; content += ""; content += ""; break; case "gut": content += " " + EIGNUNG + ""; break; case "mässig": content += " " + EIGNUNG + ""; break; case "schlecht": content += " " + EIGNUNG + ""; break; default: content += EIGNUNG + ""; } content += ""; content += ""; content += ""; content += ""; content += "
zoom | zeigen | ausblenden"; content += "
Teildachfläche" + parseInt(TD_FLAECHE).toFixed(2) + " m²
Eignung"; switch (EIGNUNG) { case "sehr gut": content += " " + EIGNUNG + "
Mittlere Einstrahlung pro Jahr" + MITTLERE_EINST + " kWh/m²/a
Photovoltaikertrag pro Jahr" + PV_ERTRAG + " kWh/a
Solarthermieertrag pro Jahr" + ST_ERTRAG + " kWh/a
"; content += ""; content += ""; content += ""; content += ""; content += ""; content += "
"; // SET REPORTING PARAMS graphic = idLayerResults.features[0]; addGraphicToReport(graphic); //console.log(graphic.geometry.toJson()); } // REGULAR layer treatment if (regularRendering == 1) { content += ""; // loop returned features (in this layers array...) for (i=0; i < idLayerResults.features.length; i++) { // DEBUG: No Fields specified if (internalDebug) { if (idFieldInfo[currentService][layerArrayPos].length == 0) { console.log("ERROR: Layer " + idLayers[currentService][layerArrayPos] + " is identifiable but no fields have been specified." ); } } // loop thru current layers layerFieldInfo array for (j=0; j< idFieldInfo[currentService][layerArrayPos].length; j++) { // 0 = FieldName, 1 = FieldNameAlias (optional) , 2 = Formatting Keyword (optional) idFieldInfoChunk = idFieldInfo[currentService][layerArrayPos][j]; idFieldInfoBit = idFieldInfoChunk.split(":"); // assign FieldValue to var for ease of handling idFieldValue = idLayerResults.features[i].attributes[idFieldInfoBit[0]]; // DEBUG: specified fields not found if (internalDebug) { if (!(idFieldValue)) { console.log("WARNING: Defined field '" + idFieldInfoBit[0] + "' is not included in returned fields for layer " + idLayers[currentService][layerArrayPos] + " (may be NULL)." ); } } if (j == 0 ) { // TODO: make zoomLinkUnique featureDisplayStoreKey = idServiceIds[currentService] + "-" + layerStore[idServiceIds[currentService]][idLayers[currentService][layerArrayPos]].name_ags; //console.log("featureDisplayStoreKey: " + featureDisplayStoreKey); randomnumber = Math.floor(Math.random()*100001); featureDisplayStore[randomnumber] = idLayerResults.features[i]; //content += ""; content += ""; content += ""; } else { content += ""; } } // display first result only if (idDisplayOneResult) { break; } } content += "
Objekt '" + idFieldValue + "'
 zoom | zeigen | ausblenden"; content += "
"; // use FieldNameAlias if defined if (idFieldInfoBit[1]) { content += idFieldInfoBit[1]; } else { content += idFieldInfoBit[0]; } content += ""; // format content if keyword is specified if(idFieldInfoBit[2]) { content += formatIdResult(idFieldValue, idFieldInfoBit[2]); } else { // catch empty fields (string 'NULL' is returned) if(idFieldValue == "Null" ) { content += "-"; } else { content += idFieldValue; } } content += "
"; } } // NO results were returned else { content += "kein Treffer."; } return content; } // format field content specifically function formatIdResult(formatContent, formatKeyword) { var fNum, fHe, fAr, fM2, fContent, fNumTMP; // TODO: format values: AREA, ELEV, URL_, PDF_, DATE, PERCENT, METER, KM switch (formatKeyword) { // swiss style areas --> corrections needed ha/a/m2 case "AREA": fNumTMP = parseFloat(formatContent); fNum = fNumTMP.toFixed(0); // reduce to whole squaremetres fHe = Math.floor(fNum / 10000); // calc hectares fAr = Math.floor((fNum - (fHe * 10000))/100); // calc ares fM2 = fNum - (fHe * 10000) - (fAr * 100); // calc squaremeters if (fHe == 0){ if (fAr == 0){ fContent = fM2 + "m²"; } else { fContent = fAr + "a " + fM2 + "m² (" + fNum + "m²)"; } } else { fContent = fHe + "ha " + fAr + "a " + fM2 + "m² (" + fNum + "m²)"; } /* if (fNum < 1000) { fContent = fNum + " m²"; } else { if (fNum > 1000000) { rawNum = (fNum / 1000000); // km2/ha/a/m2 fContent = rawNum.toFixed(2) + " km²"; } else { rawNum = (fNum / 10000); fContent = rawNum.toFixed(2) + " ha"; } } */ break; case "METER": fContent = formatContent + " m"; break; case "ELEV": fContent = formatContent + " m.ü.M"; break; case "LINK": fContent = "Link"; break; case "PDF": fContent = "PDF-Dokument"; break; case "ZIP": fContent = "ZIP-Datei"; break; } return fContent; } // helper func: show feature on map function showFeature(feature) { map.graphics.clear(); if(feature.geometry.type == "point") { feature.setSymbol(idSymbolPoint); } else { feature.setSymbol(idSymbol); } map.graphics.add(feature); } // helper func: zoom and center feature on map function zoomFeature(feature) { var newCenter, newExtent; map.graphics.clear(); if(feature.geometry.type == "point") { feature.setSymbol(idSymbolPoint); map.graphics.add(feature); newCenter = new esri.geometry.Point(feature.geometry.x, feature.geometry.y, new esri.SpatialReference({ wkid: 21781 })); map.centerAndZoom(newCenter, 11); } else { feature.setSymbol(idSymbol); // TO-DO: Only zoom if getExtent bigger than current extent newExtent = feature.geometry.getExtent(); map.graphics.add(feature); map.setExtent(newExtent, true); } } // helper func: hide results panel function hideIdResults() { dojo.byId('idResults').style.display='none'; map.graphics.clear(); }