ArcGIS Api For Flex 动态画点和线(2)

2024-03-05 00:18
文章标签 动态 arcgis api flex 画点

本文主要是介绍ArcGIS Api For Flex 动态画点和线(2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

通过webservicesflex交互取得数据库中的gps坐标动态显示在地图上。

 

 

1.建立数据库:

 

 

2.建立webservices:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Data;

 

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//
若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。

// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    public Service () {

 

       //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }

 

    [WebMethod]
    public string HelloWorld() {
        return “Hello World”;
    }
    [WebMethod]
    public string GetGPS()
    {
        DataSet myDS;
        string strtemp = string.Empty;
        string myConStr =@”Provider=Microsoft.ACE.OLEDB.12.0;DataSource=D:databaseforgpsDatabase1.accdb;”;
        OleDbConnection myCon = newOleDbConnection(myConStr);
        try   //
异常处理语句

        {
           myCon.Open();
            stringcomStr = “Select * from gps”;
           OleDbDataAdapter myAD = new OleDbDataAdapter(comStr, myCon);
             myDS =new DataSet();
           myAD.Fill(myDS, “gps”);
        }
        catch (OleDbException oe)
        {
            throw oe;
        }
        finally
        {
            //
如果Connection是打开的,则关闭
            if(myCon.State == ConnectionState.Open)
               myCon.Close();
        }
        for (int i = 0; i <myDS.Tables[0].Rows.Count; i++)
        {
            strtemp +=myDS.Tables[0].Rows[i]["X"].ToString() + “,” +myDS.Tables[0].Rows[i]["Y"].ToString()+”/”;
        }
        return strtemp;
    }
   
}
3.
编写flex代码:

 

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”
http://ns.adobe.com/mxml/2009

      xmlns:s=”library://ns.adobe.com/flex/spark”
      xmlns:mx=”library://ns.adobe.com/flex/mx”xmlns:supportClasses=”com.esri.ags.skins.supportClasses.*” minWidth=”955″minHeight=”600″ xmlns:esri=”
http://www.esri.com/2008/ags

      initialize=”init()”
      >    
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.SpatialReference;
   importcom.esri.ags.components.supportClasses.InfoSymbolWindow;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.geometry.Polyline;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.symbols.InfoSymbol;
   import com.esri.ags.symbols.SimpleLineSymbol;
   import com.esri.ags.symbols.SimpleMarkerSymbol;
   import com.esri.ags.symbols.Symbol;
   
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.soap.WebService;
   private var arr:Array=new Array();
   private var arr2:Array = new Array();
   private var polyine:Polyline=new Polyline();
   private var graphicsLayer:GraphicsLayer=new GraphicsLayer();
   private var graphicsLayertxt:GraphicsLayer=newGraphicsLayer();
   private var grahpic:Graphic=new Graphic();
   private var grahpictxt:Graphic=new Graphic();
   private var strws:String=new String();
   
   private function init():void
   {
    graphicsLayer.add(grahpic);
    Map.addLayer(graphicsLayer);
    graphicsLayertxt.add(grahpictxt);
    Map.addLayer(graphicsLayertxt);
   }     
   private function PlayPoint(e:MouseEvent):void
   {
       var ws:WebService = new WebService();
    ws.loadWSDL("
http://localhost/gps/Service.asmx?wsdl
");
    ws.addEventListener(FaultEvent.FAULT,onFAULT);
    ws.addEventListener(ResultEvent.RESULT,onRESULT);
    ws.GetGPS();
    
   }
   private function PlayLine(e:MouseEvent):void
   {
    
    polyine=new Polyline();
    var i:int=0;
    var timer:Timer = new Timer(1000, arr.length-1);
    timer.addEventListener(TimerEvent.TIMER, TimerMethod);
    timer.start();
    function TimerMethod(event:TimerEvent):void
    {
     var mps:Array=new Array;
     var mpStat:MapPoint=arr[i] as MapPoint;
     var mpEnd:MapPoint=arr[i+1] as MapPoint;
     mps.push(mpStat);
     mps.push(mpEnd);
     polyine.addPath(mps);
       
     grahpic=new Graphic(polyine,sls);
     
     graphicsLayer.add(grahpic);
     i=i+1;
    }
   }
   internal function onFAULT(evt:FaultEvent):void
   {
      Alert.show(evt.fault.faultDetail.toString());
   }
   internal function onRESULT(evt:ResultEvent):void
   {
      //Alert.show(evt.result.toString());
    strws=evt.result.toString();
    arr2=strws.split(“/”);
    for(var j:int=0;j<arr2.length-1;j++)
       {
     varx:String=arr2[j].toString().substr(0,arr2[j].toString().indexOf(“,”));
     vary:String=arr2[j].toString().substr(arr2[j].toString().indexOf(“,”)+1,arr2[j].toString().length-x.length);
     var X:Number = Number(x);
     var Y:Number = Number(y);
     var pt:MapPoint = new MapPoint(X,Y,newSpatialReference(5326));
     arr.push(pt);
     //Alert.show(Y.toString());
    
    }
    
    graphicsLayer.clear();
    var i:int=0;
    var timer:Timer = new Timer(1000, arr.length-1);
    var tmp:MapPoint=arr[i] as MapPoint;
    Map.zoom(-10,tmp);
    timer.addEventListener(TimerEvent.TIMER, TimerMethod);
    timer.start();
    function TimerMethod(event:TimerEvent):void
    {
     var mps:Array=new Array;
     var mpStat:MapPoint=arr[i] as MapPoint;
     
     
     grahpic=new Graphic(mpStat,sps);
     var dt:Date = new Date();
     
     txts.text=”xxx”+”
于:
”+dt.fullYear.toString()+”-”+(dt.month+1).toString()+”-”+dt.date.toString()+”“+dt.hours.toString()+”:”+dt.minutes.toString()+”:”+dt.seconds.toString();
     grahpictxt = new Graphic(mpStat,txts);
     graphicsLayertxt.add(grahpictxt);
     graphicsLayer.add(grahpic);
     Map.centerAt(mpStat);
     i=i+1;
    }
     
   }
     

 

  ]]>
 </fx:Script>
 <fx:Declarations>
  
  <!–
将非可视元素(例如服务、值对象)放在此处
–>
  <!–<s:WebService id=”ws” wsdl=”
http://localhost/gps/Service.asmx?wsdl
“  useProxy=”false”>
   <s:operation name=”GetGPS” fault=”">
  
   </s:operation>

 

  </s:WebService>–>

 

  <esri:SimpleLineSymbolid=”sls”
          width=”3″
          color=”0x00FF00″/>
  <esri:SimpleMarkerSymbol id=”sms”
         color=”0x00FF00″
         size=”12″
         style=”square”/>
  <esri:PictureMarkerSymbol id=”sps” source=”
http://localhost/Red_glow.swf
“  width=”20″ height=”20″ />
  <esri:TextSymbol id=”txts” backgroundColor=”0x00FF00″ color=”0xFF0000″/>

 

 
 </fx:Declarations>
 <esri:Map id=”Map” >
  <esri:ArcGISTiledMapServiceLayer
   url=”
http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_ENG/ShenYang_Community_BaseMap_ENG/MapServer”/
>
  <!–<esri:ArcGISDynamicMapServiceLayer url=”
http://218.60.144.97:8080/RemoteRest/services/LN_SL/MapServer”/>–>

 

 </esri:Map>
 
 
 <mx:ControlBar  width=”100%” top=”0″ left=”0″ paddingTop=”0″paddingBottom=”0″   horizontalAlign=”left” >
  <mx:Button label=”
开始点轨迹
”  width=”100″ fontSize=”12″click=”PlayPoint(event)”/>
  <mx:Button label=”
开始线轨迹
”  width=”100″ fontSize=”12″click=”PlayLine(event)”/>
 </mx:ControlBar>

 

 
</s:Application>

 

这篇关于ArcGIS Api For Flex 动态画点和线(2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/774721

相关文章

springboot如何通过http动态操作xxl-job任务

《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

Java调用C#动态库的三种方法详解

《Java调用C#动态库的三种方法详解》在这个多语言编程的时代,Java和C#就像两位才华横溢的舞者,各自在不同的舞台上展现着独特的魅力,然而,当它们携手合作时,又会碰撞出怎样绚丽的火花呢?今天,我们... 目录方法1:C++/CLI搭建桥梁——Java ↔ C# 的“翻译官”步骤1:创建C#类库(.NET

MyBatis编写嵌套子查询的动态SQL实践详解

《MyBatis编写嵌套子查询的动态SQL实践详解》在Java生态中,MyBatis作为一款优秀的ORM框架,广泛应用于数据库操作,本文将深入探讨如何在MyBatis中编写嵌套子查询的动态SQL,并结... 目录一、Myhttp://www.chinasem.cnBATis动态SQL的核心优势1. 灵活性与可

Mybatis嵌套子查询动态SQL编写实践

《Mybatis嵌套子查询动态SQL编写实践》:本文主要介绍Mybatis嵌套子查询动态SQL编写方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、实体类1、主类2、子类二、Mapper三、XML四、详解总结前言MyBATis的xml文件编写动态SQL

SpringBoot实现Kafka动态反序列化的完整代码

《SpringBoot实现Kafka动态反序列化的完整代码》在分布式系统中,Kafka作为高吞吐量的消息队列,常常需要处理来自不同主题(Topic)的异构数据,不同的业务场景可能要求对同一消费者组内的... 目录引言一、问题背景1.1 动态反序列化的需求1.2 常见问题二、动态反序列化的核心方案2.1 ht

golang实现动态路由的项目实践

《golang实现动态路由的项目实践》本文主要介绍了golang实现动态路由项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习... 目录一、动态路由1.结构体(数据库的定义)2.预加载preload3.添加关联的方法一、动态路由1

使用Python实现调用API获取图片存储到本地的方法

《使用Python实现调用API获取图片存储到本地的方法》开发一个自动化工具,用于从JSON数据源中提取图像ID,通过调用指定API获取未经压缩的原始图像文件,并确保下载结果与Postman等工具直接... 目录使用python实现调用API获取图片存储到本地1、项目概述2、核心功能3、环境准备4、代码实现

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

python通过curl实现访问deepseek的API

《python通过curl实现访问deepseek的API》这篇文章主要为大家详细介绍了python如何通过curl实现访问deepseek的API,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编... API申请和充值下面是deepeek的API网站https://platform.deepsee