1. 程式人生 > >ArcGIS API for javascript Bookmarks(書簽)示例2

ArcGIS API for javascript Bookmarks(書簽)示例2

style gin spa -s java lin 事件 viewport cal

1、運行效果圖

技術分享圖片

說明:這篇博文介紹的書簽位於地圖之上

有關博文中引用的API文件 怎麽iis上部署,請參考我前面的博文

2、HTML代碼

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"
/> <title>Bookmark Widget (Editable)</title> <link rel="stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.3/jsapi/js/dojo/dijit/themes/nihilo/nihilo.css"/> <link rel="stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.3/jsapi/js/esri/css/esri.css" />
<style> html, body, #map { height: 100%; margin: 0; padding: 0; } .bookmark-container { position: absolute; top: 100px; left: 15px; padding: 1rem; background: #ffffff; border-radius: 4px; border
: 1px solid #eeeeee; } </style> <script> var dojoConfig = { parseOnLoad: true // 解析 }; </script> <script type="text/Javascript" src="http://localhost/arcgis_js_api/library/3.3/jsapi/init.js"></script> <script> // 導入包 dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("dijit.form.DropDownButton"); dojo.require("esri.map"); dojo.require("esri.dijit.Bookmarks"); var map, bookmarks; function init() { map = new esri.Map("map", { center: [-100, 40], zoom: 4 }); MyTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer ("http://localhost/arcgis/rest/services/DZDT2012/MapServer"); map.addLayer(MyTiledMapServiceLayer); // 書簽可以被指定為一個數組對象結構: // { extent: <esri.geometry.Extent>, name: <some string> } var bookmarks_list = [ ]; // 創建書簽組件 bookmarks = new esri.dijit.Bookmarks({ map: map, editable: true, // 可允許編輯。默認false則只讀模式 bookmarks: bookmarks_list // Array / JSON }, dojo.byId(bookmarks)); // Add bookmarks to the widget Object.keys(bookmarks_list).forEach(function (bookmark) { bookmarks.addBookmark(bookmarkJSON[bookmark]); }); // 綁定移除標簽事件 dojo.connect(bookmarks, "onRemove", function () { alert(刪除成功); }); } // 加載時顯示 dojo.ready(init); </script> </head> <body class="nihilo"> <div id="map"></div> <div class="bookmark-container"> <div id="bookmarks"></div> </div> </body> </html>

其中的代碼

 map = new esri.Map("map", { center: [-100, 40], zoom: 4 });
              MyTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer
              ("http://localhost/arcgis/rest/services/DZDT2012/MapServer");
              map.addLayer(MyTiledMapServiceLayer);

還可以替換為下面的形式:

map = new esri.Map("map", {
basemap: "topo",
center: [-100, 40],
zoom: 4
});

ArcGIS API for javascript Bookmarks(書簽)示例2