原文链接及内容
单击右上角的控件可全屏显示。再次点击可退出全屏显示。倘若地图上没有按钮,那么您的浏览器不支持全屏API 。
main.js
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import Map from 'ol/Map.js' ;import OSM from 'ol/source/OSM.js' ;import TileLayer from 'ol/layer/Tile.js' ;import View from 'ol/View.js' ;import {FullScreen , defaults as defaultControls} from 'ol/control.js' ;const view = new View ({ center : [-9101767 , 2822912 ], zoom : 14 , }); const map = new Map ({ controls : defaultControls ().extend ([ new FullScreen ({ source : 'fullscreen' , }), ]), layers : [ new TileLayer ({ source : new OSM (), }), ], target : 'map' , view : view, });
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <title > Full Screen Control with extended source element</title > <link rel ="stylesheet" href ="node_modules/ol/ol.css" > <style > .map { width : 100% ; height : 400px ; } .fullscreen :-webkit-full-screen { height : 100% ; margin : 0 ; } .fullscreen :fullscreen { height : 100% ; } .fullscreen { margin-bottom : 10px ; width : 100% ; height : 400px ; } .map .ol-rotate { top : 3em ; } .map { width : 80% ; height : 100% ; float : left; } .sidepanel { background : #1F6B75 ; width : 20% ; height : 100% ; float : left; } .sidepanel-title { width : 100% ; font-size : 3em ; color : #ffffff ; display : block; text-align : center; } </style > </head > <body > <div id ="fullscreen" class ="fullscreen" > <div id ="map" class ="map" > </div > <div class ="sidepanel" > <span class ="sidepanel-title" > Side Panel</span > </div > </div > <script src ="https://cdn.jsdelivr.net/npm/elm-pep@1.0.6/dist/elm-pep.js" > </script > <script type ="module" src ="main.js" > </script > </body > </html >