Skip to content

Latest commit

Β 

History

History
216 lines (184 loc) Β· 18.1 KB

v4.3.0.md

File metadata and controls

216 lines (184 loc) Β· 18.1 KB

4.3.0

Summary

The v4.3.0 release includes features and fixes from 92 pull requests.

New map.getFeaturesAtPixel() method

When you want to get all features at a given pixel, use the new map.getFeaturesAtPixel() method.

Before:

var features = [];
map.forEachFeatureAtPixel(pixel, function(feature) {
  features.push(feature);
});

After:

var features = map.getFeaturesAtPixel(pixel);

ol.Sphere functions for spherical measures

The new ol.Sphere.getArea() and ol.Sphere.getLength() methods can be used to calculate spherical measures on geometries. This is the recommended over using the geometry.getArea() or geometry.getLength() methods.

Bad:

geometry.getArea();

Good:

ol.Sphere.getArea(geometry);

ol.interaction.DragAndDrop can be configured with a vector source

It is now possible to configure the drag and drop interaction with a vector source:

var dragAndDrop = new ol.interaction.DragAndDrop({source: source});

Any dropped features will replace all existing features on the source.

ol.interaction.Modify can be configured with a vector source

It is now possible to configure the modify interaction with a vector source (in addition to a feature collection):

var modify = new ol.interaction.Modify({source: source});

With this configuration, all features on the source are eligible for modification while the interaction is active.

ol.interaction.Modify deletes with alt key only

To delete features with the modify interaction, press the alt key while clicking on an existing vertex. If you want to configure the modify interaction with a different delete condition, use the deleteCondition option. For example, to allow deletion on a single click with no modifier keys, configure the interaction like this:

var interaction = new ol.interaction.Modify({
  source: source,
  deleteCondition: function(event) {
    return ol.events.condition.noModifierKeys(event) && ol.events.condition.singleClick(event);
  }
});

The motivation for this change is to make the modify, draw, and snap interactions all work well together. Previously, the use of these interactions with the default configuration would make it so you couldn't reliably add new vertices (click with no modifier) and delete existing vertices (click with no modifier).

ol.source.VectorTile no longer requires a tileGrid option

By default, the ol.source.VectorTile constructor creates an XYZ tile grid (in Web Mercator) for 512 pixel tiles and assumes a max zoom level of 22. If you were creating a vector tile source with an explicit tileGrid option, you can now remove this.

Before:

var source = new ol.source.VectorTile({
  tileGrid: ol.tilegrid.createXYZ({tileSize: 512, maxZoom: 22}),
  url: url
});

After:

var source = new ol.source.VectorTile({
  url: url
});

If you need to change the max zoom level, you can pass the source a maxZoom option. If you need to change the tile size, you can pass the source a tileSize option. If you need a completely custom tile grid, you can still pass the source a tileGrid option.

ol.source.VectorTile no longer has a tilePixelRatio option

The tilePixelRatio option was only used for tiles in projections with tile-pixels as units. For tiles read with ol.format.MVT and the default tile loader, or tiles with the default pixel size of 4096 pixels, no changes are necessary. For the very rare cases that do not fall under these categories, a custom tileLoadFunction now needs to be configured on the ol.source.VectorTile. In addition to calling tile.setFeatures() and tile.setProjection(), it also needs to contain code like the following:

var extent = tile.getFormat() instanceof ol.format.MVT ?
  tile.getLastExtent() :
  [0, 0, tilePixelRatio * tileSize, tilePixelRatio * tileSize];
tile.setExtent(extent);

ol.animate now takes the shortest arc for rotation animation

Usually rotation animations should animate along the shortest arc. There are rare occasions where a spinning animation effect is desired. So if you previously had something like

map.getView().animate({
  rotation: 2 * Math.PI,
  duration: 2000
});

we recommend to split the animation into two parts and use different easing functions. The code below results in the same effect as the snippet above did with previous versions:

map.getView().animate({
  rotation: Math.PI,
  easing: ol.easing.easeIn
}, {
  rotation: 2 * Math.PI,
  easing: ol.easing.easeOut
});

Full List of Changes