Separate internal and API methods for the view

This commit is contained in:
Tim Schaub
2019-08-11 17:28:28 -06:00
parent f73d0b16ec
commit c03c359a20
17 changed files with 214 additions and 69 deletions

13
examples/geographic.html Normal file
View 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
View 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)}`;
});