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

Openlayers顯示地理位置坐標(biāo)的方法

 更新時(shí)間:2020年09月28日 10:54:36   作者:桃李不言_下自成蹊  
這篇文章主要為大家詳細(xì)介紹了Openlayers顯示地理位置坐標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Openlayers顯示地理位置坐標(biāo)的具體代碼,供大家參考,具體內(nèi)容如下

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

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">
  #myposition
  {
   float:left;
   position:absolute;
   bottom:10px;
   width:400px;
   height:20px;
   z-index:2000;
  }
  .mosuePosition
  {
   color:blue;
   font-size:20px;
   font-family:'微軟雅黑';
  }
 </style>
 <script type="text/javascript">
  window.onload = function () {
   //初始化鼠標(biāo)位置控件
   var mousePositionControl = new ol.control.MousePosition({
    //樣式類名稱
    className: 'mosuePosition',
    //投影坐標(biāo)格式,顯示小數(shù)點(diǎn)后邊多少位
    coordinateFormat: ol.coordinate.createStringXY(8),
    //指定投影
    projection: 'EPSG:4326',
    //目標(biāo)容器
    target:document.getElementById('myposition')
   });
 
   //初始化地圖容器
   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:3
    })
   });
 
   //將鼠標(biāo)位置坐標(biāo)控件加入到map中
   map.addControl(mousePositionControl);
  }
 </script>
</head>
<body>
 <div id="map">
  <div id="myposition"></div>
 </div>
</body>
</html>

3、結(jié)果展示

當(dāng)鼠標(biāo)在地圖上移動(dòng)時(shí),會(huì)在左下角顯示當(dāng)前位置的地理坐標(biāo)

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

相關(guān)文章

最新評論