ArcGIS Server without ADF (二)在Flash上看地图

上一次已经说了不用ADF开发ArcGIS Server
Web
应用的准备工作,有网友不明白为什么要这么做,其实我们的目标就是开发一个在Flash客户端的GIS系统,达到C/S级的交互效果,接近于C/S的功能(主要就看ArcGIS
Server
的功能了),但是客户端做到零部署。当然这个目标很艰巨,所以写点东西出来希望大家一起讨论,共同提高Rich Interactive WebGIS的开发水平。

       闲话不说了,开始先建立一个服务,为了以后编辑功能的实现,选择not pooled。成功之后新建一个Fluorine工程,在Web.Config文件中添加ArcGIS ServerIdentiy。在App_Code里面添加两个类MapFramework,MapService,然后添加ESRI的一系列引用,注意确保是Serve开发可以引用的程序集,具体可以看帮助里面每个接口的Available,其中MapService中添using com.TheSilentGroup.Fluorine;MapService类型就是为Flash文件提供服务的类型。其中Mapframework的代码如下

 

///
<summary>

 

/// MapFrameWork 的摘要说明

 

///
</summary>

 

public class MapFrameWork

 

{

 

    protected Identity m_id = null;

 

    protected string m_user;

 

    protected string m_pwd;

 

    protected string m_host;

 

    protected string m_service;

 

    protected int imgWidth;

 

    protected int imgHeight;

 

    protected IServerContext m_sc;

 

    protected IMapServer m_mapServer;

 

    protected IImageDisplay m_imgDisp;

 

    protected IImageDescription m_imgDesp;

 

    protected AGSServerConnection m_agsConn;

 

    protected string m_imgURL;

 

     public MapFrameWork()

 


{

 

         //

 

         // TODO: 在此处添加构造函数逻辑

 

         //

 


m_id =
new Identity();

 

 


}

 

 

 

public void InitMapServer(string user, string pwd, string host, string service, int imgWidth,int imgHeight)

 


{

 


m_id =
new Identity(user, pwd, host);

 


m_agsConn =
new AGSServerConnection(host, m_id);

 


m_agsConn.Connect();

 

        IServerObjectManager som = m_agsConn.ServerObjectManager;

 


m_sc = som.CreateServerContext(service,
"MapServer");

 


m_mapServer = m_sc.ServerObject
as IMapServer;

 

        IMapServerInfo serverInfo = m_mapServer.GetServerInfo(m_mapServer.DefaultMapName);

 


m_imgDesp = m_sc.CreateObject(
"esriCarto.ImageDescription") as IImageDescription;

 


m_imgDisp = m_sc.CreateObject(
"esriCarto.ImageDisplay") as IImageDisplay;

 


m_imgDesp.Display = m_imgDisp;

 


m_imgDisp.Width = imgWidth;

 


m_imgDisp.Height = imgHeight;

 


m_imgDisp.DeviceResolution = 100;

 

        IImageType imgType = m_sc.CreateObject("esriCarto.ImageType") as IImageType;

 


imgType.Format =
esriImageFormat.esriImageJPG;

 


imgType.ReturnType =
esriImageReturnType.esriImageReturnURL;

 


m_imgDesp.Type = imgType;

 


m_imgURL = m_mapServer.ExportMapImage(serverInfo.DefaultMapDescription, m_imgDesp).URL;

 


}

 


 

    public string ImgURL

 


{

 

        get

 


{

 

            return this.m_imgURL;

 


}

 


}

 

}

 



MapService的代码是酱紫的

[RemotingService("Fluorine sample service")]

 

public class MapService

 

{

 

    protected MapFrameWork m_frame;

 

     public MapService()

 


{

 

         //

 

         // TODO: 在此处添加构造函数逻辑

 

         //

 


m_frame =
new MapFrameWork();

 


}

 

    public string InitServer(string user, string pwd, string server, string service, int width, int height)

 


{

 


m_frame.InitMapServer(user, pwd, server, service, width, height);

 

        return m_frame.ImgURL;

 


}

 

}

万事俱备,开始做flash咯!

 

按照上篇的步骤创建好一个Flex Application 把下面的拷进mxml里面

 

<?xml version="1.0" encoding="utf-8"?>

 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creati>

 


<mx:Image x="25" y="21" width="640" height="480" id="imgMap"/>

 


<mx:Script>

 


<![CDATA[

 


import mx.controls.Alert;

 


import mx.rpc.events.ResultEvent;

 


import mx.rpc.events.FaultEvent;

 


import mx.rpc.remoting.mxml.RemoteObject;

 


protected var service:RemoteObject;

 


protected function Init():void

 


{

 


service = new RemoteObject("fluorine");

 


service.endpoint = "http://localhost/webwork/ESRIServer/Gateway.aspx";///ESRIServer/Gateway.aspx";

 


service.source = "MapService";

 


service.addEventListener( FaultEvent.FAULT, gotError );

 


service.InitServer.addEventListener( ResultEvent.RESULT, ServerInitComplete );

 



service.InitServer("username","pwd","host","mapServiceName",640,480);

 



//service.source = "ESRIServer.Sample";

 



 


//service.addEventListener( FaultEvent.FAULT, gotError );

 


// service.Echo.addEventListener( ResultEvent.RESULT, ServerInitComplete );

 



//service.Echo("brune");

 



 


}

 


 



private function gotError( fault:FaultEvent ):void

 


{

 


//serverResult.text = "Error";

 


Alert.show( "Server reported an error - " + fault.fault.faultString, "Error" );

 


}

 


 


private function ServerInitComplete( result:ResultEvent ):void

 


{

 


this.imgMap.source = result.result.toString();

 



//Alert.show(result.result.toString());

 


}

 


]]>

 


</mx:Script>

 

</mx:Application>

 

下面运行吧,很快就能看到在flash文件里面的地图了哦!

 

从上面代码看出,ArcGIS Server其实就是在服务器端运行的AO,根据ESRI的技术人员给我的解答,ADF命名空间下的功能几乎都是通过SOAP服务封装提供的,功能有限,大家做到高级功能的时候还是需要通过AO去解决!

 

posted @ 2007-08-21 08:43  四两  阅读(932)  评论(1编辑  收藏  举报
加油,哥们,现在开始!