Separate internal and API methods for the view
This commit is contained in:
13
examples/geographic.html
Normal file
13
examples/geographic.html
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
layout: example.html
|
||||
title: Geographic Coordinates
|
||||
shortdesc: Using geographic coordinates for the map view.
|
||||
docs: >
|
||||
Calling the <code>useGeographic</code> function in the <code>'ol/proj'</code> module
|
||||
makes it so the map view uses geographic coordinates (even if the view projection is
|
||||
not geographic).
|
||||
tags: "geographic"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<div id="info"></div>
|
||||
|
||||
27
examples/geographic.js
Normal file
27
examples/geographic.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import {useGeographic} from '../src/ol/proj.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import OSM from '../src/ol/source/OSM.js';
|
||||
|
||||
useGeographic();
|
||||
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new OSM()
|
||||
})
|
||||
],
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [-110, 45],
|
||||
zoom: 8
|
||||
})
|
||||
});
|
||||
|
||||
const info = document.getElementById('info');
|
||||
map.on('moveend', function() {
|
||||
const view = map.getView();
|
||||
const center = view.getCenter();
|
||||
info.innerText = `lon: ${center[0].toFixed(2)}, lat: ${center[1].toFixed(2)}`;
|
||||
});
|
||||
Reference in New Issue
Block a user