OpenLayers 3 must be everything to everybody
Nobody individual will use more
than 15% of ol3's functionality
...except every individual
uses a different 15%
You don't have to use it in your application!
Raw JavaScript | ~1Mb + Closure library |
Whitespace only, gzip'd | ~290Kb |
Simple optimizations, gzip'd | ~180Kb |
Advanced optimizations, gzip'd | ~90Kb |
Application + ol3, gzip'd | ~32Kb |
ol.Map
1 × | ol.layer.LayerGroup |
1 × | ol.View |
N × | ol.control |
N × | ol.interaction |
1 × | ol.renderer |
ol.renderer
requestAnimationFrame
renderFrame
/ ol.FrameState
ol.animation
function fly(map, frameState) {
if (frameState.time < start) {
// before animation starts
// ...
return true;
} else if (frameState.time < start + duration) {
// animation running
var delta = easing((frameState.time - start) / duration);
var deltaResolution = resolution - frameState.view2DState.resolution;
frameState.animate = true;
frameState.view2DState.resolution += delta * deltaResolution;
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
return true;
} else {
// animation finished
return false;
}
};
Animation example ·
Composable example
Source | Source class | Layer | Renderer | |
---|---|---|---|---|
OSM, WMTS, XYZ, TileWMS | ol.source.Tile | ol.layer.Tile | Canvas, WebGL, DOM | |
ImageWMS, ImageStatic | ol.source.Image | ol.layer.Image | Canvas, WebGL, DOM | |
GeoJSON, GML, KML | ol.source.Vector | ol.layer.Vector | Canvas, WebGL*, |
ol.source.Tile
Tile grid | How tiles are laid out |
---|---|
Tile URL function | Converts tile coordinates to URLs |
Tile load function | For advanced use |
ol.source.Tile
var options = ol.source.WMTS.optionsFromCapabilities(
capabilities, 'fmzk');
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.WMTS(options)
}
]
// ...
});
Example
ol.Object and ol.Collection
ol.Object
var map = new ol.Map({
view: new ol.View2D({
center: [0, 0],
zoom: 2
})
// ...
});
var view = map.getView();
var rotationSlider = document.getElementById('rotation');
var rotation = new ol.dom.Input(rotationSlider);
rotation.bindTo('valueAsNumber', view, 'rotation');
Bind input example ·
Side-by-side example