zoukankan      html  css  js  c++  java
  • arcgis api for flex 开发入门(九)webservices 的使用<转>

    arcgis api for flex 开发入门(九)webservices 的使用
    flex 本身对webservices有着良好的支持,我们可以调用互联网上的各种
    webservices来结合esri 的map 做出自己想要的东西
    我们就拿现在比较流行的天气预报来做例子,我们要实现的目标就是通过
    webservices查询到武汉的天气情况,然后使用infowindow 显示到esri 的map上
    ,在讲解过程中,我们会重点解释infowindow 的用法。
    现在提供天气预报的webservices很多,我们选用
    http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?
    来进行天气的查询。
    那么,在flex中如何使用webservices呢?
    只要使用 <mx:WebService>标签创建一个WebService就可以了,id唯一标识这个
    webservice,wsdl指向提供webservice的地址。
    <mx:WebService id="weatherWS"
    wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?WSDL"
    showBusyCursor="true"/>
    我们直接在application 创建完成的时候调用这个 webservice,得到结果后直接
    显示到map上 。
    private function Init():void
    {
      weatherWS.addEventListener(ResultEvent.RESULT,
    WSGetWeatherResult);
                weatherWS.getWeatherbyCityName("武汉");
    }
    private function WSGetWeatherResult(event:ResultEvent):void
              {
               weatherWS.removeEventListener
    (ResultEvent.RESULT,WSGetWeatherResult);
               var arrC:ArrayCollection =event.result as
    ArrayCollection;
               if(arrC.length > 0)
               {
                 var str:String = arrC.getItemAt(0).toString();
            //     var infWd :InfoWindow = new InfoWindow(EsriMap);
                  var str2:String = arrC.getItemAt(1).toString();
                 myMap.infoWindow.title= str+"."+str2;  
                 var vbox :VBox = new VBox();
                 var vbox2 :VBox = new VBox();
                 var hbox :HBox = new HBox();
                 var canvas:Canvas = new Canvas();
                 var path:String = "assets\\weather\\";
                 var img1 :Image = new Image;
                 img1.load(path+arrC.getItemAt(8).toString());
                 hbox.addChild(img1);
                 var img2 :Image = new Image;
                 img2.load(path+arrC.getItemAt(9).toString());
                 hbox.addChild(img2);
                
               
                 var txtTem :Text = new Text();
                 txtTem.text =  arrC.getItemAt(5).toString();
                 var txtWea :Text = new Text();
                 txtWea.text =  arrC.getItemAt(6).toString();
                 var txtWind :Text = new Text();
                 txtWind.text =  arrC.getItemAt(7).toString();
                 vbox.addChild(txtTem);
                 vbox.addChild(txtWea);
                 vbox.addChild(txtWind);
                 vbox2.addChild(hbox);
                 vbox2.addChild(vbox);
                 canvas.addChild(vbox2);
                
                 myMap.infoWindow.content = canvas;
                 var mapPnt2:MapPoint = new MapPoint
    (114.1547298,30.5127677);
                 myMap.infoWindow.show(mapPnt2);
                 myMap.centerAt(mapPnt2);                  
       
               }
              }
    设置infoWindow有两点需要注意,一是infoWindow不需要自己new一个,只需要把
    你要显示的内容赋值给myMap.infoWindow,二是显示的时候只需要调用
    myMap.infoWindow.show(mapPnt2);就可以了,把你想显示的位置告诉他。
    完整代码:

    Code

    原文地址:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35702&extra=page%3D3%26amp%3Borderby%3Ddateline

  • 相关阅读:
    在 kylin-v10环境中搭建 electron
    二叉树建树
    python 从txt文件中提取数据保存到 xlxs 文件中
    openpyxl 插件写入数据
    python时间格式转换
    vue-typescript-element-template使用总结
    vue3入门
    typescript入门
    记录下谷歌 浏览器请求数据时遇302,重新连接的问题
    uni使用render.js视图层与逻辑层传数据 的问题
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1517600.html
Copyright © 2011-2022 走看看