-----------------------------------

Acquista i software ArcGIS tramite Studio A&T srl, rivenditore autorizzato dei prodotti Esri.

I migliori software GIS, il miglior supporto tecnico!

I migliori software GIS, il miglior supporto tecnico!
Azienda operante nel settore GIS dal 2001, specializzata nell’utilizzo della tecnologia ArcGIS e aderente ai programmi Esri Italia Business Network ed Esri Partner Network

-----------------------------------



domenica 28 novembre 2010

SQL Server Reporting services Map & ArcGIS Server

Con la nuova versione di SQL Server 2008 R2, possiamo visualizzare mappe nelle report che distribuiamo con RS (anche con la versione Express).

Questo è possibile grazie al nuovo controllo map. Qui potete trovare maggiori dettagli su tale controllo.

Contestualmente all'aggiunta in ArcGIS Server dei query layer,  possiamo effettuare una sorta di integrazione tra ArcGIS Server ed il controllo di mappa di RS senza utilizzare gli shapefile.

In questo video illustro una possibile integrazione:


Code:

<%@ WebHandler Language="C#" Class="rsMap" %>
 
using System;
using System.Web;
//Author: Domenico Ciavarella
//www.studioat.it
public class rsMap : IHttpHandler {
 
 public void ProcessRequest (HttpContext context) {
  
  bool isJson = false;
  bool isPrettyJson = false;
  string format = null;
  if (context.Request.QueryString["f"] != null)
  {
   format = context.Request.QueryString["f"].ToLower();
   if (format == "json" || format == "pjson")
   {
    isJson = true;
    isPrettyJson = format == "pjson";
   }
  }
 
  
  
  reportExecution.ReportExecutionService rs = new reportExecution.ReportExecutionService();
  rs.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings.Get("userReport"), System.Configuration.ConfigurationManager.AppSettings.Get("passwordReport"), System.Configuration.ConfigurationManager.AppSettings.Get("domain"));
  
  // Render arguments
  byte[] result = null;
  string reportPath = "/rsMappe/rsMap";
  string formatOutput = "PDF";
  string historyID = null;
 
  string encoding;
  string mimeType;
  string extension;
  reportExecution.Warning[] warnings = null;
  string[] streamIDs = null;
 
 
  
 
 
  reportExecution.ExecutionInfo execInfo = new reportExecution.ExecutionInfo();
  reportExecution.ExecutionHeader execHeader = new reportExecution.ExecutionHeader();
 
  rs.ExecutionHeaderValue = execHeader;
 
  execInfo = rs.LoadReport(reportPath, historyID);
  
  String SessionId = rs.ExecutionHeaderValue.ExecutionID;
 
  string oidValue = context.Server.HtmlEncode(context.Request.QueryString["oid"]);
  
  if (string.IsNullOrEmpty(oidValue))
  {
   context.Response.Write("Parametri non passati!");
   return;
  }
  
 
 
 
  reportExecution.ParameterValue[] parameters = new reportExecution.ParameterValue[1 ];
 
    
  parameters[0] = new reportExecution.ParameterValue();
  parameters[0].Name = "pFID";
  parameters[0].Value = oidValue;
  
  rs.SetExecutionParameters(parameters, "it-IT");
   
  result = rs.Render(formatOutput, nullout extension, out encoding, out mimeType, out warnings, out streamIDs);
 
 
  if (isJson)
  {
   string fileName = "_ags_" + Guid.NewGuid().ToString() + ".pdf";
   string pathfileName = @"c:\arcgisserver\arcgisoutput\" + fileName;
   string urlfileName = "http://localhost/arcgisoutput/" + fileName;
   using (System.IO.FileStream stream = System.IO.File.OpenWrite(pathfileName))
   {
    stream.Write(result, 0, result.Length);
   }
 
   GenerateJson(context, new Result() { url = urlfileName }, isPrettyJson);
   return;
  }
  
  
  context.Response.ClearContent();
  context.Response.AppendHeader("content-length", result.Length.ToString());
  context.Response.ContentType = "application/pdf";
  context.Response.BinaryWrite(result);
  context.Response.Flush();
  context.Response.Close();
 }
 
 public bool IsReusable {
  get {
   return false;
  }
 }
 
 
 private static void GenerateJson(HttpContext context, Result result, bool isPrettyJson)
 {
  context.Response.ContentType = "text/plain";
  string newLine = "\n";
  string tab = " ";
  if (!isPrettyJson)
  {
   newLine = tab = "";
  }
  context.Response.Write(string.Format("{{\"results\": {0}", newLine, tab));
 
  context.Response.Write(string.Format("{2}{1}{2}{2}{{\"url\":\"{0}\"}}{1}", result.url, newLine, tab));
    
  context.Response.Write(string.Format("{0}}}", newLine, tab));
 }
 
 public struct Result {
  public string url;
 }
 
 
}


page HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title>ArcGIS JavaScript API: LimitiComuni</title>
<style type="text/css">
  @import "http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/tundra/tundra.css";
htmlbody { height100%width100%margin0padding0; }
      .tundra .dijitSplitContainer-dijitContentPane.tundra .dijitBorderContainer-dijitContentPane#navtable { 
        PADDING-BOTTOM5pxMARGIN0px 0px 3pxPADDING-TOP0pxBORDER-BOTTOM#000 1px solidBORDER-TOP#000 1px solidBACKGROUND-COLOR#E5EFF7;
      }
      .tundra .dijitSplitContainer-dijitContentPane.tundra .dijitBorderContainer-dijitContentPane#map {
        overflow:hiddenborder:solid 1px blackpadding0;
      }
      #breadcrumbs {
        PADDING-RIGHT0pxPADDING-LEFT11pxFONT-SIZE0.8emFONT-WEIGHTboldPADDING-BOTTOM5pxMARGIN0px 0px 3pxPADDING-TOP0px;
      }
      #help {
        PADDING-RIGHT11pxPADDING-LEFT0pxFONT-SIZE0.70emPADDING-BOTTOM5pxMARGIN0px 0px 3pxPADDING-TOP3px</style>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis?v=2.1"></script>
<script type="text/javascript">
    dojo.require("esri.map");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.Dialog");
 
    var map;
    var printDlg;
 
    function Init() {
        dojo.style(dojo.byId("map"), { width: dojo.contentBox("map").w + "px", height: (esri.documentBox.h - dojo.contentBox("navTable").h - 40) + "px" });
        var initExtent = new esri.geometry.Extent({ "xmin": 6.55059928850006, "ymin": 45.0006208151578,
            "xmax": 8.22229873550003, "ymax": 45.6702338525465, "spatialReference": { "wkid": 4326 }
        });
        map = new esri.Map("map", { extent: initExtent });
        
        printDlg = new dijit.Dialog({
            title: "Stampa",
            style: "width: 825px; height: 650px"
        });
   
        var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost/ArcGIS/rest/services/LimitiComuni/MapServer", { "opacity": 0.5 });
        var layerBaseMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
        map.addLayer(layerBaseMap);
        map.addLayer(layer);
        var resizeTimer;
        dojo.connect(map, 'onLoad'function (theMap) {
            dojo.connect(map, "onClick", doIdentify);
 
            identifyTask = new esri.tasks.IdentifyTask("http://localhost/ArcGIS/rest/services/LimitiComuni/MapServer");
 
            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 3;
            identifyParams.returnGeometry = false;
            identifyParams.layerIds = [0];
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
            identifyParams.width = map.width;
            identifyParams.height = map.height;
            
            dojo.connect(dijit.byId('map'), 'resize'function () {
                clearTimeout(resizeTimer);
                resizeTimer = setTimeout(function () {
                    map.resize();
                    map.reposition();
                }, 500);
            });
        });
    }
    dojo.addOnLoad(Init);
 
 
    function doIdentify(evt) {
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        identifyTask.execute(identifyParams, function (idResults) { addToMap(idResults, evt); });
    }
    function addToMap(idResults, evt) {
        var idResult = idResults[0];
        print(idResult.feature.attributes.FID);
    }
 
    function print(id) {
   var url = esri.urlToObject("http://localhost/rsMap/rsMap.ashx?f=json&oidIndirizzo=" + id);

            var requestHandle = esri.request({
                url: url.path,
                content: url.query,
                handleAs: "json",
                load: function (data) {
                    printDlg.attr("content", "<div><object data='" + data.results.url + "' type='application/pdf' width='800' height='600'></object></div>");
                    printDlg.show();
                },
                error: function (error) {
                    alert("Errore di stampa");
                }
            });
}
 
 
</script>
</head>
<body class="tundra">
 
<table style="width:100%">
<tr>
<td>
<table id="navTable" width="100%">
<tbody>
<tr valign="top">
<td id="breadcrumbs">
ArcGIS JavaScript API: LimitiComuni
</td>
<td align="right" id="help">
Built using the  <a href="http://resources.esri.com/arcgisserver/apis/javascript/arcgis">ArcGIS JavaScript API</a>
</td>
</tr>
</tbody>
</table>
 
</td>
</tr>
</table>
<div id="map" style="margin:auto;width:97%;border:1px solid #000;"></div>
</body>
</html>