Openlayers顯示瓦片網(wǎng)格信息的方法
本文實(shí)例為大家分享了Openlayers顯示瓦片網(wǎng)格信息的具體代碼,供大家參考,具體內(nèi)容如下
1、新建一個(gè)html頁面,引入ol.js文件,然后在body中創(chuàng)建一個(gè)div標(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> <script type="text/javascript"> window.onload = function () { //實(shí)例化OSM圖層數(shù)據(jù)源對(duì)象 var osmSource = new ol.source.OSM(); //實(shí)例化地圖對(duì)象 var map = new ol.Map({ //目標(biāo)容器 target: 'map', //圖層 layers: [ //加載OSM瓦片圖層 new ol.layer.Tile({ //OSM數(shù)據(jù)源 source:osmSource }), //加載瓦片網(wǎng)格圖層 new ol.layer.Tile({ //瓦片網(wǎng)格數(shù)據(jù)源 source: new ol.source.TileDebug({ //投影 projection: 'EPSG:3857', //獲取瓦片網(wǎng)格信息 tileGrid:osmSource.getTileGrid() }) }) ], //實(shí)例化視圖對(duì)象 view: new ol.View({ //視圖中心 center: [12000000, 3000000], //視圖縮放等級(jí) zoom:10 }) }); }; </script> </head> <body> <div id="map"></div> </body> </html>
3、結(jié)果展示
地圖加載完畢后會(huì)在頁面中看見每張瓦片的網(wǎng)格信息,每張瓦片上都有三個(gè)參數(shù),這三個(gè)參數(shù)分別表示地圖的縮放級(jí)別、行號(hào)和列號(hào)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript實(shí)現(xiàn)顏色漸變的方法
這篇文章介紹了javascript實(shí)現(xiàn)顏色漸變的方法,有需要的朋友可以參考一下2013-10-10

javascript使用alert實(shí)現(xiàn)一個(gè)精美的彈窗

javascript+mapbar實(shí)現(xiàn)地圖定位

layui點(diǎn)擊按鈕頁面會(huì)自動(dòng)刷新的解決方案

javascript 常用驗(yàn)證函數(shù)總結(jié)