原文链接及内容
具有Gaticule层的球体Mollweide贴图的示例。
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 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 import GeoJSON from 'ol/format/GeoJSON.js' ;import Graticule from 'ol/layer/Graticule.js' ;import Map from 'ol/Map.js' ;import Projection from 'ol/proj/Projection.js' ;import VectorLayer from 'ol/layer/Vector.js' ;import VectorSource from 'ol/source/Vector.js' ;import View from 'ol/View.js' ;import proj4 from 'proj4' ;import {Fill , Style } from 'ol/style.js' ;import {register} from 'ol/proj/proj4.js' ;proj4.defs ( 'ESRI:53009' , '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 ' + '+b=6371000 +units=m +no_defs' ); register (proj4);const sphereMollweideProjection = new Projection ({ code : 'ESRI:53009' , extent : [ -18019909.21177587 , -9009954.605703328 , 18019909.21177587 , 9009954.605703328 , ], worldExtent : [-179 , -89.99 , 179 , 89.99 ], }); const style = new Style ({ fill : new Fill ({ color : '#eeeeee' , }), }); const map = new Map ({ keyboardEventTarget : document , layers : [ new VectorLayer ({ source : new VectorSource ({ url : 'https://openlayers.org/data/vector/ecoregions.json' , format : new GeoJSON (), }), style : function (feature ) { const color = feature.get ('COLOR_BIO' ) || '#eeeeee' ; style.getFill ().setColor (color); return style; }, }), new Graticule (), ], target : 'map' , view : new View ({ center : [0 , 0 ], projection : sphereMollweideProjection, zoom : 2 , }), });
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <title > Sphere Mollweide</title > <link rel ="stylesheet" href ="node_modules/ol/ol.css" > <style > .map { width : 100% ; height : 400px ; } </style > </head > <body > <div id ="map" class ="map" > </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 >