/* ************************************************* FILENAME: agsMap.js.php AUTHOR: André von Wartburg CREATED: 28. 07. 2010 COPYRIGHT: rawi-geo. Alle Rechte vorbehalten. DESCRIPTION: map functionality CHANGES: 06-05-12: JSLinted ************************************************** */ var paramFocus = "593362:253017:17500"; var paramParcel = ""; var paramBasemap = ""; var paramBfs = ""; var paramAmt = ""; var currentBaseMap; // recenter map (still in use?) function recenterMap(evt){ map.centerAt(evt.mapPoint); } // handle resize of browser function resizeMap(){ var resizeTimer; clearTimeout(resizeTimer); resizeTimer = setTimeout(function(){ map.resize(); map.reposition(); }, 500); } // display coordinates in footer function showCoordinates(evt) { var mp = evt.mapPoint; dojo.byId("map-coord-x").value = mp.x.toFixed(0); dojo.byId("map-coord-y").value = mp.y.toFixed(0); } // zoom to new LOD, keep center function mapLevel(scale) { var tLOD, chkScale, lodCorrection, diffScale; tLOD = 0; chkScale = 999999; lodCorrection = 0; if (lodsArr[0].scale != 350000) { lodCorrection = 13 - lodsArr.length; } // correct shortened lodsArr dojo.forEach (lodsArr, function(LOD) { diffScale = Math.abs(scale - LOD.scale); if ((diffScale < chkScale) || (diffScale == 0)) { chkScale = diffScale; tLOD = LOD.level - lodCorrection;} if (internalDebug) { console.log("target scale: " + scale + ", check scale(LOD): " + LOD.scale + " (" + LOD.level + "), diff: " + diffScale + ", new scale(LOD): "+ chkScale + "(" + tLOD + ")"); } }); map.setLevel(tLOD); } // zoom to new center at given LOD function mapFocus(xcoor, ycoor, scale) { var d, fPoint, tLOD, chkScale, lodCorrection, diffScale; // if (internalDebug) { console.log("INFO: mapFocus (" + xcoor + ", " + ycoor + ", " + scale + ")"); } if ((isNaN(xcoor) || isNaN(ycoor)) || ( ((xcoor < 480000) || (xcoor > 865000)) || ((ycoor < 62000) || (ycoor > 302000)) )) { d = new dijit.Dialog({title: "Hinweis: Ungültige Koordinaten"}); d.setContent( "Bitte geben sie ganzzahlige Werte zwischen
480000 und 865000 bzw. 62000 und 302000 ein."); d.show(); } else { fPoint = new esri.geometry.Point(parseFloat(xcoor), parseFloat(ycoor), new esri.SpatialReference({ wkid: 21781 })); // look up closest available LOD tLOD = 0; chkScale = 999999; lodCorrection = 0; if (lodsArr[0].scale != 350000) { lodCorrection = 13 - lodsArr.length; } // correct shortened lods dojo.forEach (lodsArr, function(LOD) { diffScale = Math.abs(scale - LOD.scale); //console.log(scale, LOD.scale, diffScale, chkScale, LOD.level, lodsArr.length); if ((diffScale < chkScale) || (diffScale == 0)) { chkScale = diffScale; tLOD = LOD.level - lodCorrection;} }); map.centerAndZoom(fPoint, tLOD); } } // set start extent by param or defaults function setStartExtent(dx, dy, ds){ var pFocusParts, chkScale, tScale, d, diffScale, goScale; // param FOCUS is set if ((paramFocus != "") && (paramParcel == "")) { pFocusParts = paramFocus.split(":"); if (pFocusParts.length == 3) { chkScale = 999999; tScale = parseFloat(pFocusParts[2]); // validate entered scale if((isNaN(tScale)) || (tScale > 350000) || (tScale < 250)){ d = new dijit.Dialog({title: "Hinweis: Ungültiger Massstab"}); d.setContent( "Bitte geben einen Massstab zwischen 1:250 und 1:350000 an."); d.show(); tScale = 350000; } // look up closest available scale dojo.forEach (lodsArr, function(LOD) { diffScale = Math.abs(tScale - LOD.scale); if ((diffScale < chkScale) || (diffScale == 0)) { chkScale = diffScale; goScale = LOD.scale; } }); mapFocus(pFocusParts[0], pFocusParts[1], goScale); } else { mapFocus(dx, dy, ds); } } // DEFAULT startup extent and scale else { // only set startup extent when no query params are present if ((paramFocus == "") && (paramBfs == "") && (paramParcel == "") && (paramAmt == "")) { mapFocus(dx, dy, ds); } } } // toggle base maps ("row of buttons" - style) function toggleBaseLayer(layerToShow, theMap){ var baseChk, currLayer; if (theMap == null) { theMap = map; } // set background grif if layerToShow is "basis_none" if (layerToShow == "basis_none") { dojo.style('map', {'background': '#fff url(../../../src/img/bg_grid_el.png) repeat'}); } else { dojo.style('map', {'background': '#fff'}); } // only include actual base layers dojo.forEach(theMap.layerIds, function(baseLayerId){ // only include actual base layers baseChk = baseLayerId.substr(0, 6); if (baseChk == "basis_") { currLayer = theMap.getLayer(baseLayerId); if (baseLayerId == layerToShow) { currLayer.show(); currentBaseMap = baseLayerId; dojo.style('btnBase_' + baseLayerId,{'color':'#000', 'font':'bold 12px arial, helvetica, sans-serif'}); } else { currLayer.hide(); dojo.style('btnBase_' + baseLayerId,{'color':'#666', 'font':'normal 12px arial, helvetica, sans-serif'}); } } }); } // show / hide all business layers function toggleBizLayers() { var bizChk, currLayer; theMap = map; _state = dojo.byId("chkBoxBizLayerToggle").checked; //console.log(_state); // only include actual base layers dojo.forEach(theMap.layerIds, function(bizLayerId){ // only include actual base layers bizChk = bizLayerId.substr(0, 6); if (bizChk != "basis_") { currLayer = theMap.getLayer(bizLayerId); if (_state == true) { currLayer.hide(); } else { currLayer.show(); } dijit.byId("container").resize(); } }); } // set base map function setBaseMap(defaultStartMap) { var chk; if (paramBasemap != "") { switch (paramBasemap) { case "B": currentBaseMap = "basis_baspla"; break; case "G": currentBaseMap = "basis_gbplan"; break; case "K": currentBaseMap = "basis_raster"; break; case "L": currentBaseMap = "basis_ortho"; break; default: currentBaseMap = defaultStartMap; } // check if bkgr called by param is available chk = esri.valueOf(map.layerIds, currentBaseMap); if (!(chk)) { currentBaseMap = defaultStartMap; } } else { currentBaseMap = defaultStartMap; } toggleBaseLayer(currentBaseMap, null); } // call external map app function changeMap(baseUrl) { var xc, yc, lvl, foc, bm, conc; // build FOCUS param xc = map.extent.xmin + (( map.extent.xmax - map.extent.xmin) / 2); yc = map.extent.ymin + (( map.extent.ymax - map.extent.ymin) / 2); lvl = map.getLevel(); foc = xc.toFixed(0) + ":" + yc.toFixed(0) + ":" + lodsArr[lvl].scale; //console.log("changeMap: " + foc); // build BASEMAP param switch(currentBaseMap) { case "basis_gbplan": bm = "G"; break; case "basis_baspla": bm = "B"; break; case "basis_raster": bm = "K"; break; case "basis_ortho": bm = "L"; break; default: bm = "G"; } // concat n' go //thisHost = document.location.host; conc = "http://www.geo.lu.ch" + baseUrl + "?FOCUS=" + foc + "&BASEMAP=" + bm; window.open(conc); } // clear map graphics layer function clearMapSelection() { map.graphics.clear(); } // (triggerd by toolbar-'onDrawEnd'-Event; initiated in agsConfig.js) function processMeasurement(geometry) { map.graphics.clear(); // switch behaviour for lengths / area mode if (dojo.byId("measureRadioBtn1").checked == 1) { distGraphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol())); var lengthParams = new esri.tasks.LengthsParameters(); lengthParams.polylines = [geometry]; lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER; lengthParams.geodesic = true; geometrySvc.lengths(lengthParams); } else { graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleFillSymbol())); var areasAndLengthParams = new esri.tasks.AreasAndLengthsParameters(); areasAndLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER; areasAndLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_SQUARE_METERS; geometrySvc.simplify([ geometry ], function(simplifiedGeometries) { areasAndLengthParams.polygons = simplifiedGeometries; geometrySvc.areasAndLengths(areasAndLengthParams); }); } } // activate measuring of lengths function startMeasureLength() { //dojo.disconnect(idConnect); // deactivate id map.graphics.clear(); dojo.byId("measureResult").innerHTML = "0.0 m"; tb.activate(esri.toolbars.Draw.POLYLINE); } // activate measuring of areas function startMeasureArea() { //dojo.disconnect(idConnect); // deactivate id map.graphics.clear(); dojo.byId("measureResult").innerHTML = "0.0 m²"; tb.deactivate(esri.toolbars.Draw.POLYLINE); tb.activate(esri.toolbars.Draw.POLYGON); } // open measure floating panel, start measuring function showMapMeasure() { dojo.byId('mapMeasure').style.display='block'; dojo.byId('idResults').style.display='none'; map.graphics.clear(); dojo.disconnect(idConnect); // deactivate id dojo.byId("measureResult").innerHTML = "0.0 m"; dojo.byId("measureRadioBtn1").checked = true; startMeasureLength(); } // hide measure floating panel, stop measuring function hideMapMeasure() { dojo.byId('mapMeasure').style.display='none'; map.graphics.clear(); tb.deactivate(esri.toolbars.Draw.POLYLINE); idConnect = dojo.connect(map, "onClick", doIdentify); // activate id connect } function outputMeasureDistance(result) { var dist = (result.lengths[0]).toFixed(1); if (dist < 1000) { dojo.byId("measureResult").innerHTML = dist + " m"; } else { dojo.byId("measureResult").innerHTML = (dist / 1000).toFixed(2) + " km"; } } function outputAreaAndLength(result) { var fNumTMP, fNum, fHe, fAr, fM2, fContent; fNumTMP = result.areas[0]; 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 = fNum + " m²
"+ fAr + "a " + fM2 + "m²"; } } else { fContent = fNum + " m²
" + fHe + "ha " + fAr + "a " + fM2 + "m²"; } dojo.byId("measureResult").innerHTML = fContent; }