Showing posts with label ArcGISSOM. Show all posts
Showing posts with label ArcGISSOM. Show all posts

Wednesday, December 17, 2008

Print Map with ArcGIS Server

Last week, i was to do some simple map printing of an ArcGIS Server application, the first thing i thought of is Layout view of the map, why this approach won't do the job for me ??

the reason is that im calling SOAP API operation which are stateless operations and it won't effect the Mapservice so there is no way to get that done.

as a start i thought i will take the map image put and put it in another aspx and print it along with the legned that im generating dynamically.

in my application users don't want to display the whole legend, they want to display the legend of some specific layers.

one issue thta i faced in getting the Map Image is that i have 3 rourceitems
1- Graphics Layer
2- non-Cahced Service
3- Cached Service

getting the image the normal would get only the non-chached service image, but found a way to get the image from all the resources for printing.

soon i'll pasting the code with some screenshots.

stay tuned

UPDATE:

create a sub folder in ur project directory or anywhere you want and call it "tmp". the "tmp" folder will be used to save the generated image.

you an extra page lets call it PrintPage.aspx

<%@ Page language="c#" Inherits="Printing.PrintPage" CodeFile="PrintPage.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PrintPage</title>
<style type="text/css">

</style>
</head>
<body style="margin:0 0 0 0">
<form id="Form1" method="post" runat="server">
<table border="0" width="100%" align="center">
<tr>
<td style="width: 671px" align="left"><img src="GenerateImage.aspx" id="MapImage" Width="671" Height="606" runat="server" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid" /></td>
<td valign="top" align="left">
<asp:GridView id="GVLegend" runat="server" Width="129px" Height="63px" GridLines="Horizontal" EmptyDataText="No Legend" AutoGenerateColumns="False">
<Columns>
<asp:ImageField DataImageUrlField="LegendImage">
<ItemStyle Height="40px" Width="30px" />
</asp:ImageField>
<asp:BoundField DataField="LegendName" >
<ItemStyle Font-Size="Smaller" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>



the code behind PrintPage.aspx.cs


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ESRI.ArcGIS.ADF.Web;

namespace Printing
{
public partial class PrintPage : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
MapImage.Src = Session["MapImageURL"].ToString();
}
}

}



in you default.aspx add a button that causes a callback to this function

public void PrintMap()
{
string MapImageURL = GISFunctions.ExportMapImage(Map1, Page.Request.PhysicalApplicationPath + @"tmp\");
Session["MapImageURL"] = "tmp/" + MapImageURL;


Map1.CallbackResults.Add(GeneralUtilities.Utilities.GetCallBack(null,null,"javascript","window.open('" + "PrintPage.aspx', 'PrintWindow', 'dependent=yes ,width=800, height=500, status=no, toolbar=no, menubar=yes, location=no, resizable=yes, scrollbars=yes');"));
mapstring = Map1.CallbackResults.ToString();
}


the ExportMapImage function code

public static string ExportMapImage(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map ADFMap, string OutputPath)
{
System.Collections.Generic.List<System.Drawing.Image> bitmaps = new System.Collections.Generic.List<System.Drawing.Image>();
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf in ADFMap.GetFunctionalities())
{
if (mf != null)
{
ESRI.ArcGIS.ADF.Web.MapImage mapImage = mf.DrawExtent(ADFMap.Extent);

mapImage = mf.DrawExtent(ADFMap.Extent);
if (mapImage == null)
continue;
if (mapImage.GetImage() != null)
{
bitmaps.Add(mapImage.GetImage());
}
}
}

System.Drawing.Bitmap newImg = new System.Drawing.Bitmap(Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value));

System.Drawing.Graphics imgGraphics = System.Drawing.Graphics.FromImage(newImg);
int i = bitmaps.Count - 1;
while (i >= 0)
{
imgGraphics.DrawImage(bitmaps[i], 0, 0, Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value));
i += -1;
}
long Ticks = DateTime.Now.Ticks;
string ImagePath = OutputPath + "mapimage" + Ticks + ".jpg";
newImg.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);

return "mapimage" + Ticks + ".jpg";
}


in the same way, you can add the legend next to the map, the reason why i didn't add it in code in the im displaying the legend based on different criterias which i didn't want to confuse others including it my code, but still if u need to know how to generate the legend, can can mail me.

Thursday, December 11, 2008

"SERVICE_NAME.MapServer.cfg could not be started" Error Message

last week, we have a kind of distributed installation of a ArcGIS Server 9.3, one SOM and a SOC on another machine, no load balance or anything else, the installation was very smooth,

the SOC machine was intstalled and added to as a host to the SOM and it was publishing like a charm, then we thought of adding the a local SOC to the server, and then the fun started !!

after adding the Local SOC we are getting this message "SERVICE_NAME.MapServer.cfg could not be started" message made us feel really happy, solving this prblems took nearly 1.5 days experimneting and re-installation but WE "FORGOT" to take a look at the log.

the next day early in the morning, i took a look at the log and it was something silly,

when you install a SOC only on a standalone machine, it doesn't create "arcgisserver" that has the "arcgiscache" , "arcgisoutput" , and "arcgisjobs" and i really dunno why, it should create all this by it self and set the permissions

we created these things manually and everyhing worked after that, well i hope that this might be usefull to everyone else, something to note that if you ever get this message then the folder might be there but with a permission set to ArcGISSOC local account.

i hope it helps others