arcgis for javascriptAPI常用接口.docx
《arcgis for javascriptAPI常用接口.docx》由会员分享,可在线阅读,更多相关《arcgis for javascriptAPI常用接口.docx(11页珍藏版)》请在冰豆网上搜索。
![arcgis for javascriptAPI常用接口.docx](https://file1.bdocx.com/fileroot1/2023-2/10/f354bc6f-11b5-4dbd-ad21-bf0608111f8f/f354bc6f-11b5-4dbd-ad21-bf0608111f8f1.gif)
arcgisforjavascriptAPI常用接口
arcgisforjavascriptAPI常用接口
分类:
ArcGISJavascriptAPI2013-10-0813:
17 1736人阅读 评论
(1) 收藏 举报
varmap,navToolbar,editToolbar,tileLayer,toolbar;
//varmapBaseUrl="http:
//localhost:
8399/arcgis/rest/services/pdsTile/MapServer";
//varmapDyUrl="http:
//localhost:
8399/arcgis/rest/services/pds/MapServer";
//varmapDyUrl="http:
//10.19.110.130:
8080/arcgis/rest/services/BaseMAP/MapServer";
varmapDyUrl="http:
//10.19.110.130:
8080/arcgis/rest/services/baseMAP/MapServer";
varmapBjUrl="http:
//10.19.110.130:
8080/arcgis/rest/services/YCBJ/MapServer";
vardynamicMapServiceLayerBj;
functioninit(){
try{
map=newesri.Map("map");
//tileLayer=newesri.layers.ArcGISTiledMapServiceLayer(mapBaseUrl);
//map.addLayer(tileLayer);
vardynamicMapServiceLayer=newesri.layers.ArcGISDynamicMapServiceLayer(mapDyUrl);
map.addLayer(dynamicMapServiceLayer);
dynamicMapServiceLayerBj=newesri.layers.ArcGISDynamicMapServiceLayer(mapBjUrl);
map.addLayer(dynamicMapServiceLayerBj);
//初始化
dojo.connect(map,"onLoad",dxInit);
}catch(e){alert("地图初始化失败:
"+e.message);}
}
functiondxInit()
{
try{
//alert(map.isDoubleClickZoom);
//map.disableDoubleClickZoom();
//比例尺显示
//window.setTimeout("queryMapScale.init(map);",1000);
//禁止双击放大
map.disableDoubleClickZoom();
//初始化导航工具条
navToolbar=newesri.toolbars.Navigation(map);
dojo.connect(navToolbar,"onExtentHistoryChange",extentHistoryChangeHandler);
//初始化在线编辑工具条
editToolbar=newesri.toolbars.Edit(map);
dojo.connect(map.graphics,"onClick",function(evt){
dojo.stopEvent(evt);
activateToolbar(evt.graphic);
});
//初始化绘制工具条
toolbar=newesri.toolbars.Draw(map);
//dojo.connect(toolbar,"onDrawEnd",addToMap);
//显示坐标
dojo.connect(map,"onMouseMove",showCoordinates);
dojo.connect(map,"onMouseOut",hideCoordinates);
//加载鹰眼图、加载图层列表
dojo.connect(map,"onLayerAdd",showLayers);
//加载之前记录标注
//window.setTimeout("getBz();",1000);------------------------------
//地图窗口更新
//alert(document.getElementById('map1'));
resizeMap();
dojo.connect(document.getElementById('map1'),'resize',resizeMap);
//双击map,定位街景
dojo.connect(map,'onDblClick',zoomTo3D);
//图层控制
layersCotrol([0]);
}catch(e){
alert("地图初始化失败:
"+e.message);
}
}
//图层控制
functionlayersCotrol(visible){
try{
dynamicMapServiceLayerBj.setVisibleLayers(visible);
}catch(e){
alert(e.message);
}
}
//显示图层列表
functionshowLayers(){
try{
//在下拉框中显示所有图层名称
varlayers=dynamicMapServiceLayerBj.layerInfos;
varobj1=newOption("",-1);
for(vari=0;i varobj=newOption(layers[i].name,i);
dojo.byId("layers").add(obj);
}
}catch(e){
alert(e.message);
}
}
//选择图层
functionselectLayer(){
try{
layersCotrol([dojo.byId("layers").value]);
}catch(e){
alert(e.message);
}
}
//刷新map
functionresizeMap(){
map.resize();
map.reposition();
}
//定位街景
functionzoomTo3D(evt)
{
varpoint=evt.mapPoint;
varx=point.x.toFixed(4);
vary=point.y.toFixed(4);
//window.top.addmark(x,y);
//alert(x+'|'+y);
//定位街景
LocationTrueMap(x,y);
}
//根据坐标加载街景
functionLocationTrueMap(x,y){
window.top.frames["mapframe"].frames["ldframe"].showVisionByLngLat(x,y);//定位到街景
}
//鹰眼图
functionshowOverview(){
varlayer=newesri.layers.ArcGISDynamicMapServiceLayer(mapDyUrl);
layer.setImageFormat("png24");
try{
varcreateOverviewMap=function(){
overviewMapDijit=newdijits.overview.OverviewMap({
map:
map,
baseLayer:
layer,
width:
150,
height:
150,
attachTo:
"bottom-right",
expandFactor:
1.42,
color:
"#80A8C1",
opacity:
0.5
});
overviewMapDijit.startup();
};
}catch(e){
alert("加载鹰眼图失败:
"+e.message);
}
if(layer.loaded){
createOverviewMap();
}
else{
dojo.connect(layer,"onLoad",createOverviewMap);
}
}
//前一视图、后一视图
functionextentHistoryChangeHandler(){
dijit.byId("zoomprev").disabled=navToolbar.isFirstExtent();
dijit.byId("zoomnext").disabled=navToolbar.isLastExtent();
}
//显示坐标值
functionshowCoordinates(evt)
{
try{
varmp=evt.mapPoint;
dojo.byId("info").innerHTML=mp.x.toFixed(4)+","+mp.y.toFixed(4);
}catch(e){
alert("显示坐标值错误:
"+e.message);
}
}
//隐藏坐标
functionhideCoordinates(evt){
dojo.byId("info").innerHTML="";
}
//平移
functionpan(){
try{
toolbar.deactivate();
map.setMapCursor('default');
navToolbar.activate(esri.toolbars.Navigation.PAN);
}catch(e){
alert(e.message);
}
}
//清空地图
functionclearMap(){
navToolbar.deactivate();
toolbar.deactivate();
map.graphics.clear();
map.setMapCursor('default');
}
//添加标注到地图方法1
varhandler;
functionaddBzToMap1(){
toolbar.deactivate();
map.setMapCursor('crosshair');
handler=dojo.connect(map,"onClick",addPoint);
}
functionadd(x,y){
window.parent.showdialog('add','',x,y);
}
functionmodify(id,x,y){
window.parent.showdialog('modify',id,x,y);
}
functiondel(id,x,y){
//alert(x+"--"+y);
window.parent.showdialog('del',id,x,y);
}
functionaddPoint(evt){
try{
varsymbol=newesri.symbol.PictureMarkerSymbol('images/nav/bz.png',25,25);
varpoint=newesri.geometry.Point(evt.mapPoint,newesri.SpatialReference({wkid:
4326}));
vargraphic=newesri.Graphic(point,symbol);
map.graphics.add(graphic);
map.infoWindow.setTitle("新标注");
vargeoPt=evt.mapPoint;
map.infoWindow.setContent("X坐标:
"+geoPt.y.toFixed(4)
+"
Y坐标:
"+geoPt.x.toFixed(4)
+"
"
+"
"
);
map.infoWindow.show(evt.mapPoint,map.getInfoWindowAnchor(evt.screenPoint));
map.setMapCursor('default');
dojo.disconnect(handler);
window.top.frames["mapframe"].frames["ldframe"].showVisionByLngLat(geoPt.x.toFixed(4),geoPt.y.toFixed(4));//定位到街景
}catch(e){
alert("添加标注出错:
"+e.message);
}
}
//定位
functionzoomToPoint(x,y){
vargeoPoint=newesri.geometry.Point({"x":
x,"y":
y},map.spatialReference);
map.centerAndZoom(geoPoint,3);
}
//小汽车定位
//zoomCar(113.32,23.12);
functionzoomCar(x,y){
navToolbar.deactivate();
map.graphics.clear();
try{
vargeoPoint=newesri.geometry.Point({"x":
x,"y":
y},map.spatialReference);
map.centerAndZoom(geoPoint);
varsymbol=newesri.symbol.PictureMarkerSymbol('images/nav/car.png',24,24);
vargraphic=newesri.Graphic(geoPoint,symbol);
map.graphics.add(graphic);
}catch(e){
alert("小汽车定位"+e.message);
}
}
varurl="http:
//192.168.1.11:
8080";
//接收主题名称、坐标值
functiongetBz(aa){
vargraphicsLayer=newesri.layers.GraphicsLayer();
try{
for(vari=0;i a_x=aa[i][1];
a_y=aa[i][2];
//alert(a_x+"---"+a_y);
varpoint=newesri.geometry.Point(a_x,a_y,map.spatialReference);
varsymbol=newesri.symbol.PictureMarkerSymbol('images/nav/bz.png',25,25);
vartextSym=newesri.symbol.TextSymbol(aa[i][0]);
textSym.setAlign(esri.symbol.TextSymbol.ALIGN_END);
vargraphic=newesri.Graphic(point,symbol);
varinfoTemplate=newesri.InfoTemplate();
infoTemplate.setTitle("广告信息");
infoTemplate.setContent(
// "center;'>100px;height:
42px;'/>