var map, navToolbar, editToolbar, tileLayer, toolbar;
//var mapBaseUrl = "http://localhost:8399/arcgis/rest/services/pdsTile/MapServer";
//var mapDyUrl = "http://localhost:8399/arcgis/rest/services/pds/MapServer";
//var mapDyUrl = "http://10.19.110.130:8080/arcgis/rest/services/BaseMAP/MapServer";
var mapDyUrl = "http://10.19.110.130:8080/arcgis/rest/services/baseMAP/MapServer";
var mapBjUrl = "http://10.19.110.130:8080/arcgis/rest/services/YCBJ/MapServer";
var dynamicMapServiceLayerBj;
function init() {
try{
map = new esri.Map("map");
//tileLayer = new esri.layers.ArcGISTiledMapServiceLayer(mapBaseUrl);
//map.addLayer(tileLayer);
var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapDyUrl);
map.addLayer(dynamicMapServiceLayer);
dynamicMapServiceLayerBj = new esri.layers.ArcGISDynamicMapServiceLayer(mapBjUrl);
map.addLayer(dynamicMapServiceLayerBj);
//初始化
dojo.connect(map, "onLoad", dxInit);
}catch(e){alert("地圖初始化失敗:"+e.message);}
}
function dxInit()
{
try{
//alert(map.isDoubleClickZoom);
//map.disableDoubleClickZoom();
//比例尺顯示
//window.setTimeout("queryMapScale.init(map);", 1000);
//禁止雙擊放大
map.disableDoubleClickZoom();
//初始化導航工具條
navToolbar = new esri.toolbars.Navigation(map);
dojo.connect(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);
//初始化在線編輯工具條
editToolbar = new esri.toolbars.Edit(map);
dojo.connect(map.graphics, "onClick", function(evt) {
dojo.stopEvent(evt);
activateToolbar(evt.graphic);
});
//初始化繪製工具條
toolbar = new esri.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);
}
}
//圖層控制
function layersCotrol(visible){
try{
dynamicMapServiceLayerBj.setVisibleLayers(visible);
}catch(e){
alert(e.message);
}
}
//顯示圖層列表
function showLayers(){
try{
//在下拉框中顯示所有圖層名稱
var layers = dynamicMapServiceLayerBj.layerInfos;
var obj1 = new Option("", -1);
for(var i=0; i<layers.length; i++){
var obj = new Option(layers[i].name, i);
dojo.byId("layers").add(obj);
}
}catch(e){
alert(e.message);
}
}
//選擇圖層
function selectLayer(){
try{
layersCotrol([dojo.byId("layers").value]);
}catch(e){
alert(e.message);
}
}
//刷新map
function resizeMap(){
map.resize();
map.reposition();
}
//定位街景
function zoomTo3D(evt)
{
var point = evt.mapPoint;
var x = point.x.toFixed(4);
var y = point.y.toFixed(4);
//window.top.addmark(x, y);
//alert(x + '|' + y);
// 定位街景
LocationTrueMap(x, y);
}
// 根據座標加載街景
function LocationTrueMap(x, y) {
window.top.frames["mapframe"].frames["ldframe"].showVisionByLngLat(x, y); //定位到街景
}
//鷹眼圖
function showOverview() {
var layer = new esri.layers.ArcGISDynamicMapServiceLayer(mapDyUrl);
layer.setImageFormat("png24");
try{
var createOverviewMap = function() {
overviewMapDijit = new dijits.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);
}
}
//前一視圖、後一視圖
function extentHistoryChangeHandler() {
dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();
}
//顯示座標值
function showCoordinates(evt)
{
try{
var mp = evt.mapPoint;
dojo.byId("info").innerHTML = mp.x.toFixed(4) +","+ mp.y.toFixed(4);
}catch(e){
alert("顯示座標值錯誤:"+e.message);
}
}
//隱藏座標
function hideCoordinates(evt){
dojo.byId("info").innerHTML = "";
}
//平移
function pan(){
try{
toolbar.deactivate();
map.setMapCursor('default');
navToolbar.activate(esri.toolbars.Navigation.PAN);
}catch(e){
alert(e.message);
}
}
//清空地圖
function clearMap(){
navToolbar.deactivate();
toolbar.deactivate();
map.graphics.clear();
map.setMapCursor('default');
}
//添加標註到地圖方法1
var handler;
function addBzToMap1(){
toolbar.deactivate();
map.setMapCursor('crosshair');
handler = dojo.connect(map, "onClick", addPoint);
}
function add(x, y) {
window.parent.showdialog('add','', x,y);
}
function modify(id, x, y) {
window.parent.showdialog('modify', id, x, y);
}
function del(id, x, y) {
//alert(x + "--" + y);
window.parent.showdialog('del', id, x, y);
}
function addPoint(evt) {
try{
var symbol = new esri.symbol.PictureMarkerSymbol('images/nav/bz.png', 25, 25);
var point = new esri.geometry.Point(evt.mapPoint, new esri.SpatialReference({ wkid: 4326 }));
var graphic = new esri.Graphic(point, symbol);
map.graphics.add(graphic);
map.infoWindow.setTitle("新標註");
var geoPt = evt.mapPoint;
map.infoWindow.setContent("<b>X座標: </b>" + geoPt.y.toFixed(4)
+ "<br><b>Y座標: </b>" + geoPt.x.toFixed(4)
+ "<table></table>"
+ "<br><input type='button' value='添加屬性' οnclick='window.top.addmark(" + geoPt.x.toFixed(4) + "," + geoPt.y.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);
}
}
//定位
function zoomToPoint(x, y){
var geoPoint = new esri.geometry.Point({"x":x,"y":y}, map.spatialReference);
map.centerAndZoom(geoPoint, 3);
}
//小汽車定位
//zoomCar(113.32,23.12);
function zoomCar(x, y) {
navToolbar.deactivate();
map.graphics.clear();
try{
var geoPoint = new esri.geometry.Point({"x":x,"y":y}, map.spatialReference);
map.centerAndZoom(geoPoint);
var symbol = new esri.symbol.PictureMarkerSymbol('images/nav/car.png', 24,24);
var graphic = new esri.Graphic(geoPoint, symbol);
map.graphics.add(graphic);
}catch(e){
alert("小汽車定位" + e.message);
}
}
var url = "http://192.168.1.11:8080";
//接收主題名稱、座標值
function getBz(aa) {
var graphicsLayer = new esri.layers.GraphicsLayer();
try {
for (var i = 0; i < aa.length; i++) {
a_x = aa[i][1];
a_y = aa[i][2];
// alert(a_x+"---"+a_y);
var point = new esri.geometry.Point(a_x, a_y, map.spatialReference);
var symbol = new esri.symbol.PictureMarkerSymbol('images/nav/bz.png', 25, 25);
var textSym = new esri.symbol.TextSymbol(aa[i][0]);
textSym.setAlign(esri.symbol.TextSymbol.ALIGN_END);
var graphic = new esri.Graphic(point, symbol);
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setTitle("廣告信息");
infoTemplate.setContent(
// "<div style='text-align:center;'><img src='" + url + aa[i][5] + "' alt='" + url + aa[i][5] + "' style='width:100px;height:42px;'/></div>" +
// "<b>廣告名稱: </b>" + aa[i][3] + "<br/>" +
// "<b>廣告位置: </b>" + aa[i][4] + "<br/>" +
//
"<br><input type='button' value='修改廣告' οnclick='map.infoWindow.hide();modify(" + aa[i][0] + "," + a_x + "," + a_y + ")'>" +
//
" <input type='button' value='刪除廣告' οnclick='map.infoWindow.hide();del(" + aa[i][0] + "," + a_x + "," + a_y + ")'>"
);
graphic.setInfoTemplate(infoTemplate);
var graphicText = new esri.Graphic(point, textSym);
graphicsLayer.add(graphic);
graphicsLayer.add(graphicText);
if (aa.length == 1) {
// zoomToPoint(a_x, a_y);
}
}
} catch (e) {
alert("獲取座標點數組出錯:" + e.message + "---aa:" + aa);
}
map.addLayer(graphicsLayer);
}
//在線編輯--移動要素
function activateToolbar(graphic) {
try{
var tool = 0;
tool = tool | esri.toolbars.Edit.MOVE;
//tool = tool | esri.toolbars.Edit.EDIT_VERTICES;
//tool = tool | esri.toolbars.Edit.SCALE;
//tool = tool | esri.toolbars.Edit.ROTATE;
var options = {
allowAddVertices: true,
allowDeleteVertices: true
};
editToolbar.activate(tool, graphic, options);
dojo.connect(map.graphics, "onDblClick", showInfoWindow);
}catch(e){
alert("移動要素問題:"+e.message);
}
}
function showInfoWindow(evt){
evt.stopPropagation();
map.infoWindow.setTitle("新標註");
var geoPt = evt.mapPoint;
map.infoWindow.setContent("<b>X座標: </b>" + geoPt.y.toFixed(4)
+ "<br><b>Y座標: </b>" + geoPt.x.toFixed(4)
+ "<table></table>"
+ "<br><input type='button' value='添加廣告' οnclick='map.infoWindow.hide();add(" + geoPt.x + "," + geoPt.y + ")'>"
);
map.infoWindow.show(evt.mapPoint,map.getInfoWindowAnchor(evt.screenPoint));
}
//框選
function queryBz()
{
map.setMapCursor('crosshair');
navToolbar.deactivate();
toolbar.activate(esri.toolbars.Draw.EXTENT);
toolbar.onDrawEnd = function doQueryExtent(extent) {
window.parent.stat(extent.xmin, extent.ymin, extent.xmax, extent.ymax);
// //獲取框選區域的座標範圍
// alert("xmax:"+extent.xmax+",xmin:"+extent.xmin+", ymax:"+extent.ymax+",ymin:"+extent.ymin);
};
}
arcgis for javascriptAPI常用接口
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
ArcGIS JavaScript API相關資料收集
碧海蓝天2015
2020-02-21 12:56:21
關於ArcGIS javascript API 使用arcgis server 發佈的服務無法在瀏覽器上顯示解決辦法
无心先生
2018-09-04 13:15:04
arcgis server 10.4 授權不成功解決辦法
无心先生
2018-09-04 13:15:03
arcgisAPI 4.5本地部署,圖標樣式訪問不到解決辦法!!
无心先生
2018-09-04 13:15:03
ArcGIS js api中關於比例尺單位改爲中文的方式
li55703833
2018-08-31 18:34:35