欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Openlayers學(xué)習(xí)之地圖比例尺控件

 更新時(shí)間:2020年09月28日 11:51:27   作者:桃李不言_下自成蹊  
這篇文章主要為大家詳細(xì)介紹了Openlayers學(xué)習(xí)之地圖比例尺控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Openlayers地圖比例尺控件的具體代碼,供大家參考,具體內(nèi)容如下

1、新建一個(gè)html頁(yè)面,引入ol.js和ol.css文件,然后在body中創(chuàng)建兩個(gè)div標(biāo)簽,分別用來(lái)作為地圖和比例尺控件的容器;

2、代碼實(shí)現(xiàn)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title></title>
 <script src="../lib/ol/ol.js"></script>
 <link href="../css/ol.css" rel="stylesheet" />
 <style type="text/css">
 #scalebar
 {
  float:left;
  margin-bottom:10px;
  z-index:2000;
 }
 </style>
 <script type="text/javascript">
 window.onload = function () {
  //實(shí)例化比例尺控件
  var scaleLineControl = new ol.control.ScaleLine({
  //設(shè)置度量單位為米
  units: 'metric',
  target: 'scalebar',
  className: 'ol-scale-line'
  });
  //實(shí)例化地圖控件
  var map = new ol.Map({
  target: 'map',
  layers: [
   new ol.layer.Tile({
   source:new ol.source.OSM()
   }),
  ],
  view: new ol.View({
   center: [0, 0],
   zoom:2
  }),
  });
  //將比例尺控件加入到map中
  map.addControl(scaleLineControl);
 };
 </script>
</head>
<body>
 <div id="map"></div>
 <div id="scalebar"></div>
</body>
</html>

3、運(yùn)行結(jié)果

地圖初始化的時(shí)候就能在左下角看見(jiàn)比例尺控件

隨著地圖的放大和縮小,比例尺的值也會(huì)發(fā)生相應(yīng)的改變

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論