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="<Definition DataSourceDefinition="In Memory" DataSourceType="GraphicsLayer" Identity="" ResourceDefinition="" DataSourceShared="True" />"
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="<Definition DataSourceDefinition="localhost" DataSourceType="ArcGIS Server Local" Identity="To set, right-click project and 'Add ArcGIS Identity'" ResourceDefinition="Layers@HSGIS" DataSourceShared="True" />"
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>
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;
}