首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web开发 >

arcgis js 依据坐标画轨迹

2013-04-09 
arcgis js 根据坐标画轨迹bodyform idform1 runatserverscript typetext/javascriptfuncti

arcgis js 根据坐标画轨迹


<body>
    <form id="form1" runat="server">
    <script type="text/javascript">
        function GetCoord()
          {
              var AX=document.getElementById("TxtX").value;
              var AY=document.getElementById("TxtY").value;
              if(AX=='')
              {
                 alert('缺少经度坐标!');
                 return;
              }
              if(isNaN(AX))
              {
                 alert('经度坐标必须为数字!');
                 return;
              }
              if(AY=='')
              {
                 alert('缺少纬度坐标!');
                 return;
              }
              if(isNaN(AY))
              {
                 alert('纬度坐标必须为数字!');
                 return;
              }
              var message='X='+AX+'&Y='+AY;
              var context="MyMap";
              <%=m_LocateByXY%>         
           } 
                       
       function LinkLocate()
       {
           var taskId=document.getElementById("taskId").value;
           var taskLineId='taskId='+taskId;
           var context="MyMap";
          <%=m_TaskLine%>
       }    
    </script>    
    <div style="width: 100%">
        <div>
            <table>
                <tr>


                    <td align="left">
                        任务ID:<asp:TextBox ID="taskId" runat="server"></asp:TextBox>
                        <input id="linkLocateBtn" type="button" value="线路定位" onclick="LinkLocate()" />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        X坐标:<asp:TextBox ID="TxtX" runat="server"></asp:TextBox>
                        Y坐标:<asp:TextBox ID="TxtY" runat="server"></asp:TextBox>
                        <input id="btnLocateBtn" type="button" value="单点定位" onclick="GetCoord()" />
                    </td>
                </tr>
            </table>
        </div>
        <div style="float: right;">
            <esri:Toolbar ID="Toolbar1" runat="server" BuddyControlType="Map" Group="Toolbar1_Group"
                Height="28px" ToolbarItemDefaultStyle-BackColor="Transparent" ToolbarItemDefaultStyle-Font-Names="Arial"
                ToolbarItemDefaultStyle-Font-Size="Smaller" ToolbarItemDisabledStyle-BackColor="Transparent"
                ToolbarItemDisabledStyle-Font-Names="Arial" ToolbarItemDisabledStyle-Font-Size="Smaller"
                ToolbarItemDisabledStyle-ForeColor="Gray" ToolbarItemHoverStyle-BackColor="Transparent"
                ToolbarItemHoverStyle-Font-Bold="True" ToolbarItemHoverStyle-Font-Italic="True"
                ToolbarItemHoverStyle-Font-Names="Arial" ToolbarItemHoverStyle-Font-Size="Smaller"
                ToolbarItemSelectedStyle-BackColor="Transparent" ToolbarItemSelectedStyle-Font-Bold="True"
                ToolbarItemSelectedStyle-Font-Names="Arial" ToolbarItemSelectedStyle-Font-Size="Smaller"


                WebResourceLocation="/aspnet_client/ESRI/WebADF/" Width="300px">
                <ToolbarItems>
                    <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomIn.png" HoverImage="esriZoomIn.png"
                        JavaScriptFile="" Name="MapZoomIn" SelectedImage="esriZoomIn.png" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
                        ServerAction


                        Disabled="True" DisabledImage="images/backward_disabled.png" HoverImage="images/backward.png"
                        JavaScriptFile="" Name="MapBack" SelectedImage="images/backward.png" Text=" "
                        ToolTip="前一视野" />
                    <esri:Command BuddyItem="MapBack" ClientAction="ToolbarMapForward" DefaultImage="images/forward.png"
                        Disabled="True" DisabledImage="images/forward_disabled.png" HoverImage="images/forward.png"
                        JavaScriptFile="" Name="MapForward" SelectedImage="images/forward.png" Text=" "
                        ToolTip="后一视野" />
                </ToolbarItems>
                <BuddyControls>
                    <esri:BuddyControl Name="MyMap" />
                </BuddyControls>
            </esri:Toolbar>
        </div>
        <div style="position: relative; top: 0px;">
            <esri:Map ID="MyMap" runat="server" MapResourceManager="MapResourceManager1" Width="100%"
                Height="472px">
            </esri:Map>
            <esri:MapResourceManager ID="MapResourceManager1" runat="server">
                <ResourceItems>
                    <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;In Memory&quot; DataSourceType=&quot;GraphicsLayer&quot; Identity=&quot;&quot; ResourceDefinition=&quot;&quot; DataSourceShared=&quot;True&quot; /&gt;"
                        DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=:transbg=False:displayInToc=True:dynamicTiling="
                        LayerDefinitions="" Name="graph" />
                    <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;localhost&quot; DataSourceType=&quot;ArcGIS Server Local&quot; Identity=&quot;To set, right-click project and 'Add ArcGIS Identity'&quot; ResourceDefinition=&quot;Layers@HSGIS&quot; DataSourceShared=&quot;True&quot; /&gt;"


                        DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG32:height=100:width=100:dpi=96:color=-32513:transbg=True:displayInToc=True:dynamicTiling=True"
                        LayerDefinitions="" Name="MyLayers" />
                </ResourceItems>
            </esri:MapResourceManager>
        </div>
        <div style="position: absolute; top: 113px;">
            <table>
                <tr>
                    <td align="center">
                        <esri:Navigation ID="Navigation1" runat="server" Map="MyMap" DisplayImageUrl="images/directional_arrows_N.gif"
                            Height="52px" Width="52px" Size="44">
                            <DisplayCharacter FontName="ESRI North" CharacterIndex="58"></DisplayCharacter>
                        </esri:Navigation>
                        <esri:ZoomLevel ID="ZoomLevel1" runat="server" Map="MyMap" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
    <%--    鼠标移动,显示坐标,一定要放在MainMap定义之后--%>

    <script language="javascript" type="text/javascript">
        Sys.Application.add_init(initialize);

        function initialize() {
            m_MainMap = $find('MyMap');
            m_MainMap.add_mouseMove(MapCoordsMouseMove);
        }

        function MapCoordsMouseMove(sender, args) {
            var coords = args.coordinate;
            window.status = '经度X: ' +
            coords.get_x().toFixed(6) + ', 纬度Y:' +


            coords.get_y().toFixed(6);
        }             
    </script>
</body>



全部代码,单点定位,轨迹点回放,视野切换全部实现,可就是轨迹画不出来,帮看下到底是哪边的问题
[解决办法]
海绵宝宝,这个代码看着确实解决不了问题,我用的是JSP,也没法测试,要不你一点点测试代码,一处处alert,看这个画线的代码执行到哪步,是画了,还是画了又被清除掉了,另外我把我画线的函数给你贴出来,看对你有帮助没

function locatePathToMap(jsonObj){
  //参数为json格式:{mapxy,id,onmouseover,onclick,width,opacity,type,color,flashcolor}
  //type:solid,dash,dot,dashdot
  //flashcolor:闪烁颜色
  var arr_xys=jsonObj.mapxy.split(";"); //x1,y1;x2,y2;x3,y3
  var mobjid=jsonObj.id; //唯一关键字
  if (mobjid==null) mobjid="lineid";
  removeLocatorInMap(mobjid);
  var line = new esri.geometry.Polyline(); //map.spatialReference
  var points = [];
  for(var i=0;i<arr_xys.length;i++){
    mapxy=arr_xys[i].split(",");
    if (mapxy.length>1){
       points[i]=new esri.geometry.Point(mapxy[0],mapxy[1]);
    }
  }
  arr_xys=[];
  line.addPath(points);
  var sym = new esri.symbol.SimpleLineSymbol().setWidth(jsonObj.width);
  if (jsonObj.type=="dash"){
     sym.setStyle(esri.symbol.SimpleLineSymbol.STYLE_DASH);
  }else if (jsonObj.type=="dot"){
     sym.setStyle(esri.symbol.SimpleLineSymbol.STYLE_DOT);
  }else if (jsonObj.type=="dashdot"){
     sym.setStyle(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT);
  }else{
     sym.setStyle(esri.symbol.SimpleLineSymbol.STYLE_SOLID);
  }
  sym.setColor(new dojo.Color(jsonObj.color));
  var graphic1 = new esri.Graphic(line,sym);
  var infoTemplate = new esri.InfoTemplate();
  if (jsonObj.title) infoTemplate.setTitle(jsonObj.title); //标题
  if (jsonObj.onclick) infoTemplate.setContent(jsonObj.onclick);
  graphic1.setInfoTemplate(infoTemplate);
  graphic1.user_overtext = jsonObj.onmouseover;
  graphic1.user_id =mobjid;
  if (jsonObj.flashcolor && jsonObj.flashcolor!=""){
    graphic1.user_flashcolor=new dojo.Color(jsonObj.flashcolor);
    graphic1.user_color=new dojo.Color(jsonObj.color);
  }
  gApp.gDynLayer.add(graphic1);
  return graphic1;
}

热点排行