Merge pull request #8809 from notnotse/issue/8800-configurable-interval-options
Configurable interval options
This commit is contained in:
+14
-3
@@ -107,6 +107,11 @@ const INTERVALS = [
|
|||||||
* Note that the default's `textAlign` configuration will not work well for
|
* Note that the default's `textAlign` configuration will not work well for
|
||||||
* `latLabelPosition` configurations that position labels close to the left of
|
* `latLabelPosition` configurations that position labels close to the left of
|
||||||
* the viewport.
|
* the viewport.
|
||||||
|
* @property {Array<number>} [intervals=[90, 45, 30, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.01, 0.005, 0.002, 0.001]]
|
||||||
|
* Intervals (in degrees) for the graticule. Example to limit graticules to 30 and 10 degrees intervals:
|
||||||
|
* ```js
|
||||||
|
* [30, 10]
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -319,6 +324,12 @@ class Graticule {
|
|||||||
this.parallelsLabels_ = [];
|
this.parallelsLabels_ = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array<number>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.intervals_ = options.intervals !== undefined ? options.intervals : INTERVALS;
|
||||||
|
|
||||||
this.setMap(options.map !== undefined ? options.map : null);
|
this.setMap(options.map !== undefined ? options.map : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,8 +541,8 @@ class Graticule {
|
|||||||
const p1 = [];
|
const p1 = [];
|
||||||
/** @type {Array<number>} **/
|
/** @type {Array<number>} **/
|
||||||
const p2 = [];
|
const p2 = [];
|
||||||
for (let i = 0, ii = INTERVALS.length; i < ii; ++i) {
|
for (let i = 0, ii = this.intervals_.length; i < ii; ++i) {
|
||||||
const delta = INTERVALS[i] / 2;
|
const delta = this.intervals_[i] / 2;
|
||||||
p1[0] = centerLon - delta;
|
p1[0] = centerLon - delta;
|
||||||
p1[1] = centerLat - delta;
|
p1[1] = centerLat - delta;
|
||||||
p2[0] = centerLon + delta;
|
p2[0] = centerLon + delta;
|
||||||
@@ -542,7 +553,7 @@ class Graticule {
|
|||||||
if (dist <= target) {
|
if (dist <= target) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
interval = INTERVALS[i];
|
interval = this.intervals_[i];
|
||||||
}
|
}
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,38 @@ describe('ol.Graticule', function() {
|
|||||||
expect(graticule.latLabelPosition_).to.be(0.1);
|
expect(graticule.latLabelPosition_).to.be(0.1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be configured with interval limits', function() {
|
||||||
|
graticule = new Graticule({
|
||||||
|
map: new Map({}),
|
||||||
|
showLabels: true,
|
||||||
|
lonLabelFormatter: function(lon) {
|
||||||
|
return lon.toString();
|
||||||
|
},
|
||||||
|
latLabelFormatter: function(lat) {
|
||||||
|
return lat.toString();
|
||||||
|
},
|
||||||
|
intervals: [10]
|
||||||
|
});
|
||||||
|
const extent = [-25614353.926475704, -7827151.696402049,
|
||||||
|
25614353.926475704, 7827151.696402049];
|
||||||
|
const projection = getProjection('EPSG:3857');
|
||||||
|
const resolution = 4891.96981025128;
|
||||||
|
const squaredTolerance = resolution * resolution / 4.0;
|
||||||
|
graticule.updateProjectionInfo_(projection);
|
||||||
|
graticule.createGraticule_(extent, [0, 0], resolution, squaredTolerance);
|
||||||
|
|
||||||
|
expect(graticule.meridiansLabels_[0].text).to.be('0');
|
||||||
|
expect(graticule.parallelsLabels_[0].text).to.be('0');
|
||||||
|
expect(graticule.meridiansLabels_[1].text).to.be('-10');
|
||||||
|
expect(graticule.parallelsLabels_[1].text).to.be('-10');
|
||||||
|
expect(graticule.meridiansLabels_[2].text).to.be('-20');
|
||||||
|
expect(graticule.parallelsLabels_[2].text).to.be('-20');
|
||||||
|
|
||||||
|
expect(graticule.getMeridians().length).to.be(37);
|
||||||
|
expect(graticule.getParallels().length).to.be(11);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user