ArcGIS For JavaScript APi Map with scalebar(地圖比例尺 內/外)————(二十三)__Java

來源:互聯網
上載者:User

(1)內部比例尺

此樣本示範如何添加一個比例尺地圖。可以被添加到在地圖上,或在一個使用者指定的位置的比例尺。下面的程式碼片段顯示了預設的比例尺顯示在地圖的左下角。

var scalebar=new esri.dijit.Scalebar({
  map: map
});

您可以修改該位置的地圖由中設定attachTo選項之一以下值"top-right","bottom-right","top-center","bottom-center","bottom-left","top-left".

var scalebar=new esri.dijit.Scalebar({   map:map,
  attachTo:"bottom-left"
});

查看原文:ArcGIS For JavaScript APi Map with scalebar —— 地圖比例尺

引用聯結:http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/widget_scalebar

線上示範:http://help.arcgis.com/en/webapi/javascript/arcgis/samples/widget_scalebar/index.html

 

代碼如下:

<!DOCTYPE html><html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">    <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">    <title>Map with scalebar</title>    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">     <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">    <style>       html, body { height: 100%; width: 100%; margin: 0; padding: 0; }      #map{padding:0;}    </style>     <script>var dojoConfig = { parseOnLoad: true };</script>    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>    <script>       dojo.require("dojo.parser");      dojo.require("dijit.layout.BorderContainer");      dojo.require("dijit.layout.ContentPane");      dojo.require("esri.map");      dojo.require("esri.dijit.Scalebar");      var map;       function init() {        map = new esri.Map("map", {          basemap: "topo",          center: [-116.093, 34.218],          zoom: 7        });        dojo.connect(map, "onLoad", function(theMap) {          var scalebar = new esri.dijit.Scalebar({            map: map, // 必須的            scalebarUnit: "english"  // 指定比例尺單位,有效值是"english" or "metric".預設"english"          });        });      }       dojo.ready(init);  // 初始化載入    </script>   </head>     <body class="claro">     <div data-dojo-type="dijit.layout.BorderContainer"          data-dojo-props="design:'headline', gutters:false"         style="width: 100%; height: 100%; margin: 0;">       <div id="map"            data-dojo-type="dijit.layout.ContentPane"            data-dojo-props="region:'center'"            style="overflow:hidden;">       </div>     </div>   </body> </html>

效果如下:
 

(2)比例尺在外部

 

參考聯結:http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/widget_scalebarext

線上示範:http://help.arcgis.com/en/webapi/javascript/arcgis/samples/widget_scalebarExt/index.html

 

 此樣本示範如何顯示一個比例尺的地圖之外,在指定的位置。下面的程式碼片段建立了一個新的比例尺,並把它的比例尺的建構函式中指定的在div。

var scalebar=new esri.dijit.Scalebar({
    map: map,
    scalebarUnit:"metric"
}, dojo.byId("scalebar"));

代碼如下:

<!DOCTYPE html><html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">    <!--The viewport meta tag is used to improve the presentation and behavior of the samples       on iOS devices-->    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">    <title>Scalebar</title>    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">     <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">    <script>var dojoConfig = { parseOnLoad: true };</script>    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>    <script>       dojo.require("dojo.parser");      dojo.require("esri.dijit.Scalebar");      dojo.require("esri.map");      var map;       function initialize() {        map = new esri.Map("map", {          basemap: "topo",          center: [-116.093, 34.218],          zoom: 7        });        dojo.connect(map, "onLoad", function() {          var scalebar = new esri.dijit.Scalebar({            map: map,            scalebarUnit: "english"          }, dojo.byId("scalebar"));        });      }       dojo.ready(initialize);    </script>   </head>     <body class="claro">     <div id="map" style="position: relative; width: 900px; height: 500px; border: 1px solid #000;"></div>    <div id="scalebar" style="position:absolute;left:100px;top:530px;"></div>  </body>  </html>


效果如圖:

 

(3)問題:

 不知道什麼原因,很多樣本中都是第一次載入沒問題,重新整理頁面時候不會再顯示,比如這個比例尺也是一樣,我用的是IE9瀏覽器

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.