/* ************************************************* FILENAME: agsQuery.js.php AUTHOR: André von Wartburg CREATED: 28. 07. 2010 COPYRIGHT: rawi-geo. Alle Rechte vorbehalten. DESCRIPTION: fixed query (searches) functionality CHANGES: 08. 05. 2012 JSLinted ************************************************** */ pfrQueryTask = new esri.tasks.QueryTask("http://svc.geo.lu.ch/AGS/rest/services/ext/ext_div/MapServer/1"); gchQueryTask = new esri.tasks.QueryTask("http://svc.geo.lu.ch/AGS/rest/services/rawi/rawi_div/MapServer/3"); //build query filter query = new esri.tasks.Query(); query.returnGeometry = true; var queryId; // ID of the current query // result rendering var highlightPoly = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,255,255]), 4), new dojo.Color([255,255,0,0.0])); var highlightPoint = new esri.symbol.PictureMarkerSymbol("../../src/img/pin_target.png", 30, 28); highlightPoint.setOffset(15, 13); // startup queries (BFS, PARCEL) function setStartQueries() { // PARCEL: highlight and zoom 1-99 parcels (agsMap.js) if (paramParcel != "") { executeQueryTask("PARCEL", paramParcel); } // BFS: highlight and zoom 1-10 gemeinden (agsMap.js) if ((paramParcel == "") && (paramBfs != "")) { executeQueryTask("BFS", paramBfs); } // AMT: highlight and zoom 1-10 bezirke (agsMap.js) if ((paramParcel == "") && (paramBfs == "") && (paramAmt != "")) { executeQueryTask("AMT", paramAmt); } } // execute query function executeQueryTask(qKeyword, qString) { var x, parcelString, bfsString, queryLimit, parcelStringBits ; queryId = qKeyword; //set query where clause switch(qKeyword) { // STANDARD case "adr": query.where = "ADRESS_ID = " + dojo.byId('sADR_NUM').value; adrQueryTask.execute(query,showResults); break; case "gem": query.where = "BFS_NR = " + dojo.byId('sGEM_GEM').value ; gemQueryTask.execute(query,showResults); break; case "gch": query.where = "BFS_NR = " + dojo.byId('sGCH_GEM').value ; gchQueryTask.execute(query,showResults); break; case "prz": query.outFields = ["FLAECHENMASS", "GEMEINDE", "GBPER_NAME"]; query.where = "PRZNUMMER = " + dojo.byId('sPRZ_NUM').value + " AND GBPER_CODE = " + dojo.byId('sPRZ_GBP').value; przQueryTask.execute(query,showResults); break; case "sdr": query.where = "PRZNUMMER = " + dojo.byId('sSDR_NUM').value + " AND GBPER_CODE = " + dojo.byId('sSDR_GBP').value; sdrQueryTask.execute(query,showResults); break; case "law": if (dojo.byId('sLAWIS_TYP').value == 'KU') { query.where = "BPO_ID = " + dojo.byId('sLAWIS_OBJ').value + " AND BFS_NR = " + dojo.byId('sLAWIS_GEM').value; lawQueryTask.execute(query,showResults); } if (dojo.byId('sLAWIS_TYP').value == 'HS') { query.where = "BPO_ID = " + dojo.byId('sLAWIS_OBJ').value + " AND BFS_NR = " + dojo.byId('sLAWIS_GEM').value; law2QueryTask.execute(query,showResults); } break; case "gvl": query.where = "BBTEXT = '" + dojo.byId('sGVL_NUM').value + "' AND GBPER_CODE = " + dojo.byId('sGVL_ORT').value; gvlQueryTask.execute(query,showResults); break; case "bac": query.where = "GEW_ID = '" + dojo.byId('sBAC_NUM').value + "'"; bacQueryTask.execute(query,showResults); break; case "svo": query.where = "ID_SVO = '" + dojo.byId('sSVO_NAM').value + "'"; svoQueryTask.execute(query,showResults); break; case "bod": query.where = "PRJ_NR= " + dojo.byId('sBOD_NAM').value ; bodQueryTask.execute(query,showResults); break; case "gef": query.where = "GKNAME_SHORT = '" + dojo.byId('sGEF_NAM').value + "'"; gefQueryTask.execute(query,showResults); break; case "lmp": query.where = "GBPER_CODE = "+ dojo.byId('sLMP_GEM').value + " AND LMPNAME = '" + dojo.byId('sLMP_NAM').value + "'"; lmpQueryTask.execute(query,showResults); break; case "poi": query.where = "UUID = '"+ qString + "'"; console.log(query.where); poiQueryTask.execute(query,zoomAndCenterPOI); break; case "fln": query.outFields = ["OBJECTID", "FLURNAME"]; query.where = "OBJECTID = " + dojo.byId('sFLN_NAM').value; flnQueryTask.execute(query,showResults); break; case "pfr": query.where = "PFR_ID = '" + dojo.byId('sPFR_NAM').value + "'"; pfrQueryTask.execute(query,showResults); break; // CUSTOM queries are in mapCustom.js // URL params case "PARCEL": // crack parcelString = qString.split(":"); query.where = ""; // build SQL for (x in parcelString) { // hardcoded queryLimit queryLimit = 100; if (x <= queryLimit) { parcelStringBits = parcelString[x].split("."); dojo.byId("print_PRZ").value = parcelStringBits[0] + "." + parcelStringBits[1]; // save latest for printing (GB/PRZ) query.where += "(PRZNUMMER = " + parcelStringBits[1] + " AND GBPER_CODE = " + parcelStringBits[0] + " )"; if ( (x != parcelString.length - 1) && (x != 99)) { query.where += " OR "; } } } if(internalDebug) { console.log("INFO: startup param PARCEL detected"); } // execute Query przQueryTask.execute(query,showResults); break; case "BFS": // crack bfsString = qString.split(":"); query.where = ""; // build SQL for (x in bfsString) { // hardcoded queryLimit queryLimit = 10; if (x <= queryLimit) { query.where += "BFS_NR = " + bfsString[x] ; if ( (x != bfsString.length - 1) && (x != 9)) { query.where += " OR "; } } } if(internalDebug) { console.log("INFO: startup param BFS detected"); } // execute Query gemQueryTask.execute(query,showResults); break; case "AMT": query.where += "AMT = " + qString; if(internalDebug) { console.log("INFO: startup param AMT detected"); } amtQueryTask.execute(query,showResults); break; case "BPO_ID": break; } } // highlight query results on map function showResults(featureSet) { var i, resultFeatures, graphic, fExtent, extent; map.graphics.clear(); //flush graphics layer //QueryTask returns fSet. Loop through features in fSet and add them to the map. resultFeatures = featureSet.features; //Performance enhancer - assign featureSet array to a single variable. // Store info for display on prints (parcels only) if (typeof(printOptions) != "undefined") { if (queryId == "prz") { _areaTMP = formatIdResult(resultFeatures[0].attributes["FLAECHENMASS"], 'AREA'); _area_formatted = _areaTMP.replace("²", "2"); printOptions.print.comments = "Parzelle Nr. " + dojo.byId('sPRZ_NUM').value + " (Grundbuch " + resultFeatures[0].attributes["GBPER_NAME"] + " [" + dojo.byId('sPRZ_GBP').value + "])\r\nGemeinde: " + resultFeatures[0].attributes["GEMEINDE"] + "\r\nFläche: " + _area_formatted; console.log(printOptions.print.comments); } else { printOptions.print.comments = ""; } } for (i=0; i < resultFeatures.length; i++) { //Get the current feature from the featureSet, Feature is a graphic graphic = resultFeatures[i]; /* // detect geometry type //console.log(featureSet.geometryType); if (featureSet.geometryType == "esriGeometryPoint") { graphic.setSymbol(highlightPoint); } else { graphic.setSymbol(highlightPoly); } map.graphics.add(graphic); //add graphic to graphics layer. */ // POINT if (featureSet.geometryType == "esriGeometryPoint") { //newCenter = new esri.geometry.Point(graphic.geometry.x, graphic.geometry.y, new esri.SpatialReference({ wkid: 21781 })); //map.centerAndZoom(newCenter, 9); mapFocus(graphic.geometry.x, graphic.geometry.y, 1000); } // LINE, POLY else { // MANY results if (resultFeatures.length > 1) { // first think, then code! fExtent = esri.graphicsExtent(featureSet.features); map.setExtent(fExtent, true); } // ONE result else { extent = graphic.geometry.getExtent(); map.setExtent(extent, true); } } } }