Fixed tests & linting

This commit is contained in:
Olivier Guyot
2018-11-15 10:33:35 +01:00
parent 1b8a6baa35
commit d5c390e726
3 changed files with 43 additions and 31 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ export {default as Collection} from './Collection.js';
export {default as Disposable} from './Disposable.js'; export {default as Disposable} from './Disposable.js';
export {default as Feature} from './Feature.js'; export {default as Feature} from './Feature.js';
export {default as Geolocation} from './Geolocation.js'; export {default as Geolocation} from './Geolocation.js';
export {default as Graticule} from './Graticule.js'; export {default as Graticule} from './layer/Graticule.js';
export {default as Image} from './Image.js'; export {default as Image} from './Image.js';
export {default as ImageBase} from './ImageBase.js'; export {default as ImageBase} from './ImageBase.js';
export {default as ImageCanvas} from './ImageCanvas.js'; export {default as ImageCanvas} from './ImageCanvas.js';
+27 -22
View File
@@ -3,27 +3,27 @@
*/ */
import VectorLayer from './Vector.js'; import VectorLayer from './Vector.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {degreesToStringHDMS} from "../coordinate"; import {degreesToStringHDMS} from '../coordinate';
import Text from "../style/Text"; import Text from '../style/Text';
import Fill from "../style/Fill"; import Fill from '../style/Fill';
import Stroke from "../style/Stroke"; import Stroke from '../style/Stroke';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import VectorSource from "../source/Vector"; import VectorSource from '../source/Vector';
import { import {
equivalent as equivalentProjection, equivalent as equivalentProjection,
get as getProjection, get as getProjection,
getTransform, getTransform,
transformExtent transformExtent
} from "../proj"; } from '../proj';
import {getCenter, intersects, equals, getIntersection, isEmpty} from '../extent' import {getCenter, intersects, equals, getIntersection, isEmpty} from '../extent';
import {clamp} from "../math"; import {clamp} from '../math';
import Style from "../style/Style"; import Style from '../style/Style';
import Feature from "../Feature"; import Feature from '../Feature';
import {bbox} from "../loadingstrategy"; import {bbox} from '../loadingstrategy';
import {meridian, parallel} from "../geom/flat/geodesic"; import {meridian, parallel} from '../geom/flat/geodesic';
import GeometryLayout from "../geom/GeometryLayout"; import GeometryLayout from '../geom/GeometryLayout';
import Point from "../geom/Point"; import Point from '../geom/Point';
import Collection from "../Collection"; import Collection from '../Collection';
/** /**
@@ -313,16 +313,17 @@ class Graticule extends VectorLayer {
options.latLabelPosition; options.latLabelPosition;
/** /**
* @type {Object.<string,function(Feature):Style>} * @type {Object.<string,Style>}
* @private * @private
*/ */
this.lonLabelStyleCache_ = {}; this.lonLabelStyleCache_ = {};
/** /**
* @type {function(Feature):Style}
* @private * @private
* @param {import("../Feature").default} feature Feature
* @return {Style} style
*/ */
this.lonLabelStyle_ = function (feature) { this.lonLabelStyle_ = function(feature) {
const label = feature.get('graticule_label'); const label = feature.get('graticule_label');
if (!this.lonLabelStyleCache_[label]) { if (!this.lonLabelStyleCache_[label]) {
this.lonLabelStyleCache_[label] = new Style({ this.lonLabelStyleCache_[label] = new Style({
@@ -345,16 +346,17 @@ class Graticule extends VectorLayer {
}.bind(this); }.bind(this);
/** /**
* @type {Object.<string,function(Feature):Style>} * @type {Object.<string,Style>}
* @private * @private
*/ */
this.latLabelStyleCache_ = {}; this.latLabelStyleCache_ = {};
/** /**
* @type {function(Feature):Style}
* @private * @private
* @param {import("../Feature").default} feature Feature
* @return {Style} style
*/ */
this.latLabelStyle_ = function (feature) { this.latLabelStyle_ = function(feature) {
const label = feature.get('graticule_label'); const label = feature.get('graticule_label');
if (!this.latLabelStyleCache_[label]) { if (!this.latLabelStyleCache_[label]) {
this.latLabelStyleCache_[label] = new Style({ this.latLabelStyleCache_[label] = new Style({
@@ -430,6 +432,9 @@ class Graticule extends VectorLayer {
/** /**
* Update geometries in the source based on current view * Update geometries in the source based on current view
* @param {import("../extent").Extent} extent Extent
* @param {number} resolution Resolution
* @param {import("../proj/Projection.js").default} projection Projection
*/ */
loaderFunction(extent, resolution, projection) { loaderFunction(extent, resolution, projection) {
const source = /** @type import("../source/Vector").default} */ (this.getSource()); const source = /** @type import("../source/Vector").default} */ (this.getSource());
@@ -439,7 +444,7 @@ class Graticule extends VectorLayer {
const renderExtent = getIntersection(layerExtent, extent, this.tmpExtent_); const renderExtent = getIntersection(layerExtent, extent, this.tmpExtent_);
// we should not keep track of loaded extents // we should not keep track of loaded extents
setTimeout(function () { setTimeout(function() {
source.removeLoadedExtent(extent); source.removeLoadedExtent(extent);
}, 0); }, 0);
+15 -8
View File
@@ -1,15 +1,17 @@
import Graticule from '../../../src/ol/Graticule.js'; import Graticule from '../../../src/ol/layer/Graticule.js';
import Map from '../../../src/ol/Map.js'; import Map from '../../../src/ol/Map.js';
import {get as getProjection} from '../../../src/ol/proj.js'; import {get as getProjection} from '../../../src/ol/proj.js';
import Stroke from '../../../src/ol/style/Stroke.js'; import Stroke from '../../../src/ol/style/Stroke.js';
import Text from '../../../src/ol/style/Text.js'; import Text from '../../../src/ol/style/Text.js';
import Feature from '../../../src/ol/Feature';
describe('ol.Graticule', function() { describe('ol.layer.Graticule', function() {
let graticule; let graticule;
function createGraticule() { function createGraticule() {
graticule = new Graticule({ graticule = new Graticule();
map: new Map({}) new Map({
layers: [graticule]
}); });
} }
@@ -31,9 +33,11 @@ describe('ol.Graticule', function() {
it('creates a graticule with labels', function() { it('creates a graticule with labels', function() {
graticule = new Graticule({ graticule = new Graticule({
map: new Map({}),
showLabels: true showLabels: true
}); });
new Map({
layers: [graticule]
});
const extent = [-25614353.926475704, -7827151.696402049, const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049]; 25614353.926475704, 7827151.696402049];
const projection = getProjection('EPSG:3857'); const projection = getProjection('EPSG:3857');
@@ -75,6 +79,7 @@ describe('ol.Graticule', function() {
it('can be configured with label options', function() { it('can be configured with label options', function() {
const latLabelStyle = new Text(); const latLabelStyle = new Text();
const lonLabelStyle = new Text(); const lonLabelStyle = new Text();
const feature = new Feature();
graticule = new Graticule({ graticule = new Graticule({
map: new Map({}), map: new Map({}),
showLabels: true, showLabels: true,
@@ -98,15 +103,14 @@ describe('ol.Graticule', function() {
graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance); graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance);
expect(graticule.meridiansLabels_[0].text).to.be('lon: 0'); expect(graticule.meridiansLabels_[0].text).to.be('lon: 0');
expect(graticule.parallelsLabels_[0].text).to.be('lat: 0'); expect(graticule.parallelsLabels_[0].text).to.be('lat: 0');
expect(graticule.lonLabelStyle_).to.eql(lonLabelStyle); expect(graticule.lonLabelStyle_(feature).getText()).to.eql(lonLabelStyle);
expect(graticule.latLabelStyle_).to.eql(latLabelStyle); expect(graticule.latLabelStyle_(feature).getText()).to.eql(latLabelStyle);
expect(graticule.lonLabelPosition_).to.be(0.9); expect(graticule.lonLabelPosition_).to.be(0.9);
expect(graticule.latLabelPosition_).to.be(0.1); expect(graticule.latLabelPosition_).to.be(0.1);
}); });
it('can be configured with interval limits', function() { it('can be configured with interval limits', function() {
graticule = new Graticule({ graticule = new Graticule({
map: new Map({}),
showLabels: true, showLabels: true,
lonLabelFormatter: function(lon) { lonLabelFormatter: function(lon) {
return lon.toString(); return lon.toString();
@@ -116,6 +120,9 @@ describe('ol.Graticule', function() {
}, },
intervals: [10] intervals: [10]
}); });
new Map({
layers: [graticule]
});
const extent = [-25614353.926475704, -7827151.696402049, const extent = [-25614353.926475704, -7827151.696402049,
25614353.926475704, 7827151.696402049]; 25614353.926475704, 7827151.696402049];
const projection = getProjection('EPSG:3857'); const projection = getProjection('EPSG:3857');