Rename _ol_Graticule_ to Graticule
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import _ol_Graticule_ from '../src/ol/Graticule.js';
|
import Graticule from '../src/ol/Graticule.js';
|
||||||
import _ol_Map_ from '../src/ol/Map.js';
|
import _ol_Map_ from '../src/ol/Map.js';
|
||||||
import _ol_View_ from '../src/ol/View.js';
|
import _ol_View_ from '../src/ol/View.js';
|
||||||
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
|
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
|
||||||
@@ -23,7 +23,7 @@ var map = new _ol_Map_({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create the graticule component
|
// Create the graticule component
|
||||||
var graticule = new _ol_Graticule_({
|
var graticule = new Graticule({
|
||||||
// the style to use for the lines, optional.
|
// the style to use for the lines, optional.
|
||||||
strokeStyle: new _ol_style_Stroke_({
|
strokeStyle: new _ol_style_Stroke_({
|
||||||
color: 'rgba(255,120,0,0.9)',
|
color: 'rgba(255,120,0,0.9)',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ol_Graticule_ from '../src/ol/Graticule.js';
|
import Graticule from '../src/ol/Graticule.js';
|
||||||
import _ol_Map_ from '../src/ol/Map.js';
|
import _ol_Map_ from '../src/ol/Map.js';
|
||||||
import _ol_View_ from '../src/ol/View.js';
|
import _ol_View_ from '../src/ol/View.js';
|
||||||
import _ol_format_GeoJSON_ from '../src/ol/format/GeoJSON.js';
|
import _ol_format_GeoJSON_ from '../src/ol/format/GeoJSON.js';
|
||||||
@@ -41,6 +41,6 @@ var map = new _ol_Map_({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
new _ol_Graticule_({
|
new Graticule({
|
||||||
map: map
|
map: map
|
||||||
});
|
});
|
||||||
|
|||||||
+39
-40
@@ -15,6 +15,25 @@ import _ol_style_Stroke_ from './style/Stroke.js';
|
|||||||
import _ol_style_Text_ from './style/Text.js';
|
import _ol_style_Text_ from './style/Text.js';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.style.Stroke}
|
||||||
|
* @private
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
|
var DEFAULT_STROKE_STYLE = new _ol_style_Stroke_({
|
||||||
|
color: 'rgba(0,0,0,0.2)'
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO can be configurable
|
||||||
|
* @type {Array.<number>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
var 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
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{map: (ol.PluggableMap|undefined),
|
* @typedef {{map: (ol.PluggableMap|undefined),
|
||||||
* maxLines: (number|undefined),
|
* maxLines: (number|undefined),
|
||||||
@@ -100,7 +119,7 @@ export var GraticuleOptions;
|
|||||||
* of the viewport.
|
* of the viewport.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
var _ol_Graticule_ = function(opt_options) {
|
var Graticule = function(opt_options) {
|
||||||
var options = opt_options || {};
|
var options = opt_options || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,8 +211,7 @@ var _ol_Graticule_ = function(opt_options) {
|
|||||||
* @type {ol.style.Stroke}
|
* @type {ol.style.Stroke}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.strokeStyle_ = options.strokeStyle !== undefined ?
|
this.strokeStyle_ = options.strokeStyle !== undefined ? options.strokeStyle : DEFAULT_STROKE_STYLE;
|
||||||
options.strokeStyle : _ol_Graticule_.DEFAULT_STROKE_STYLE_;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.TransformFunction|undefined}
|
* @type {ol.TransformFunction|undefined}
|
||||||
@@ -302,25 +320,6 @@ var _ol_Graticule_ = function(opt_options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {ol.style.Stroke}
|
|
||||||
* @private
|
|
||||||
* @const
|
|
||||||
*/
|
|
||||||
_ol_Graticule_.DEFAULT_STROKE_STYLE_ = new _ol_style_Stroke_({
|
|
||||||
color: 'rgba(0,0,0,0.2)'
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO can be configurable
|
|
||||||
* @type {Array.<number>}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_ol_Graticule_.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];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} lon Longitude.
|
* @param {number} lon Longitude.
|
||||||
* @param {number} minLat Minimal latitude.
|
* @param {number} minLat Minimal latitude.
|
||||||
@@ -331,7 +330,7 @@ _ol_Graticule_.intervals_ = [90, 45, 30, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05,
|
|||||||
* @return {number} Index.
|
* @return {number} Index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.addMeridian_ = function(lon, minLat, maxLat, squaredTolerance, extent, index) {
|
Graticule.prototype.addMeridian_ = function(lon, minLat, maxLat, squaredTolerance, extent, index) {
|
||||||
var lineString = this.getMeridian_(lon, minLat, maxLat,
|
var lineString = this.getMeridian_(lon, minLat, maxLat,
|
||||||
squaredTolerance, index);
|
squaredTolerance, index);
|
||||||
if (intersects(lineString.getExtent(), extent)) {
|
if (intersects(lineString.getExtent(), extent)) {
|
||||||
@@ -354,7 +353,7 @@ _ol_Graticule_.prototype.addMeridian_ = function(lon, minLat, maxLat, squaredTol
|
|||||||
* @return {ol.geom.Point} Meridian point.
|
* @return {ol.geom.Point} Meridian point.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getMeridianPoint_ = function(lineString, extent, index) {
|
Graticule.prototype.getMeridianPoint_ = function(lineString, extent, index) {
|
||||||
var flatCoordinates = lineString.getFlatCoordinates();
|
var flatCoordinates = lineString.getFlatCoordinates();
|
||||||
var clampedBottom = Math.max(extent[1], flatCoordinates[1]);
|
var clampedBottom = Math.max(extent[1], flatCoordinates[1]);
|
||||||
var clampedTop = Math.min(extent[3], flatCoordinates[flatCoordinates.length - 1]);
|
var clampedTop = Math.min(extent[3], flatCoordinates[flatCoordinates.length - 1]);
|
||||||
@@ -379,7 +378,7 @@ _ol_Graticule_.prototype.getMeridianPoint_ = function(lineString, extent, index)
|
|||||||
* @return {number} Index.
|
* @return {number} Index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.addParallel_ = function(lat, minLon, maxLon, squaredTolerance, extent, index) {
|
Graticule.prototype.addParallel_ = function(lat, minLon, maxLon, squaredTolerance, extent, index) {
|
||||||
var lineString = this.getParallel_(lat, minLon, maxLon, squaredTolerance,
|
var lineString = this.getParallel_(lat, minLon, maxLon, squaredTolerance,
|
||||||
index);
|
index);
|
||||||
if (intersects(lineString.getExtent(), extent)) {
|
if (intersects(lineString.getExtent(), extent)) {
|
||||||
@@ -403,7 +402,7 @@ _ol_Graticule_.prototype.addParallel_ = function(lat, minLon, maxLon, squaredTol
|
|||||||
* @return {ol.geom.Point} Parallel point.
|
* @return {ol.geom.Point} Parallel point.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getParallelPoint_ = function(lineString, extent, index) {
|
Graticule.prototype.getParallelPoint_ = function(lineString, extent, index) {
|
||||||
var flatCoordinates = lineString.getFlatCoordinates();
|
var flatCoordinates = lineString.getFlatCoordinates();
|
||||||
var clampedLeft = Math.max(extent[0], flatCoordinates[0]);
|
var clampedLeft = Math.max(extent[0], flatCoordinates[0]);
|
||||||
var clampedRight = Math.min(extent[2], flatCoordinates[flatCoordinates.length - 2]);
|
var clampedRight = Math.min(extent[2], flatCoordinates[flatCoordinates.length - 2]);
|
||||||
@@ -425,7 +424,7 @@ _ol_Graticule_.prototype.getParallelPoint_ = function(lineString, extent, index)
|
|||||||
* @param {number} squaredTolerance Squared tolerance.
|
* @param {number} squaredTolerance Squared tolerance.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.createGraticule_ = function(extent, center, resolution, squaredTolerance) {
|
Graticule.prototype.createGraticule_ = function(extent, center, resolution, squaredTolerance) {
|
||||||
|
|
||||||
var interval = this.getInterval_(resolution);
|
var interval = this.getInterval_(resolution);
|
||||||
if (interval == -1) {
|
if (interval == -1) {
|
||||||
@@ -519,7 +518,7 @@ _ol_Graticule_.prototype.createGraticule_ = function(extent, center, resolution,
|
|||||||
* @return {number} The interval in degrees.
|
* @return {number} The interval in degrees.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getInterval_ = function(resolution) {
|
Graticule.prototype.getInterval_ = function(resolution) {
|
||||||
var centerLon = this.projectionCenterLonLat_[0];
|
var centerLon = this.projectionCenterLonLat_[0];
|
||||||
var centerLat = this.projectionCenterLonLat_[1];
|
var centerLat = this.projectionCenterLonLat_[1];
|
||||||
var interval = -1;
|
var interval = -1;
|
||||||
@@ -529,8 +528,8 @@ _ol_Graticule_.prototype.getInterval_ = function(resolution) {
|
|||||||
var p1 = [];
|
var p1 = [];
|
||||||
/** @type {Array.<number>} **/
|
/** @type {Array.<number>} **/
|
||||||
var p2 = [];
|
var p2 = [];
|
||||||
for (i = 0, ii = _ol_Graticule_.intervals_.length; i < ii; ++i) {
|
for (i = 0, ii = INTERVALS.length; i < ii; ++i) {
|
||||||
delta = _ol_Graticule_.intervals_[i] / 2;
|
delta = 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;
|
||||||
@@ -541,7 +540,7 @@ _ol_Graticule_.prototype.getInterval_ = function(resolution) {
|
|||||||
if (dist <= target) {
|
if (dist <= target) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
interval = _ol_Graticule_.intervals_[i];
|
interval = INTERVALS[i];
|
||||||
}
|
}
|
||||||
return interval;
|
return interval;
|
||||||
};
|
};
|
||||||
@@ -552,7 +551,7 @@ _ol_Graticule_.prototype.getInterval_ = function(resolution) {
|
|||||||
* @return {ol.PluggableMap} The map.
|
* @return {ol.PluggableMap} The map.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getMap = function() {
|
Graticule.prototype.getMap = function() {
|
||||||
return this.map_;
|
return this.map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -566,7 +565,7 @@ _ol_Graticule_.prototype.getMap = function() {
|
|||||||
* @param {number} index Index.
|
* @param {number} index Index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getMeridian_ = function(lon, minLat, maxLat,
|
Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat,
|
||||||
squaredTolerance, index) {
|
squaredTolerance, index) {
|
||||||
var flatCoordinates = _ol_geom_flat_geodesic_.meridian(lon,
|
var flatCoordinates = _ol_geom_flat_geodesic_.meridian(lon,
|
||||||
minLat, maxLat, this.projection_, squaredTolerance);
|
minLat, maxLat, this.projection_, squaredTolerance);
|
||||||
@@ -582,7 +581,7 @@ _ol_Graticule_.prototype.getMeridian_ = function(lon, minLat, maxLat,
|
|||||||
* @return {Array.<ol.geom.LineString>} The meridians.
|
* @return {Array.<ol.geom.LineString>} The meridians.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getMeridians = function() {
|
Graticule.prototype.getMeridians = function() {
|
||||||
return this.meridians_;
|
return this.meridians_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -596,7 +595,7 @@ _ol_Graticule_.prototype.getMeridians = function() {
|
|||||||
* @param {number} index Index.
|
* @param {number} index Index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getParallel_ = function(lat, minLon, maxLon,
|
Graticule.prototype.getParallel_ = function(lat, minLon, maxLon,
|
||||||
squaredTolerance, index) {
|
squaredTolerance, index) {
|
||||||
var flatCoordinates = _ol_geom_flat_geodesic_.parallel(lat,
|
var flatCoordinates = _ol_geom_flat_geodesic_.parallel(lat,
|
||||||
minLon, maxLon, this.projection_, squaredTolerance);
|
minLon, maxLon, this.projection_, squaredTolerance);
|
||||||
@@ -612,7 +611,7 @@ _ol_Graticule_.prototype.getParallel_ = function(lat, minLon, maxLon,
|
|||||||
* @return {Array.<ol.geom.LineString>} The parallels.
|
* @return {Array.<ol.geom.LineString>} The parallels.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.getParallels = function() {
|
Graticule.prototype.getParallels = function() {
|
||||||
return this.parallels_;
|
return this.parallels_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -621,7 +620,7 @@ _ol_Graticule_.prototype.getParallels = function() {
|
|||||||
* @param {ol.render.Event} e Event.
|
* @param {ol.render.Event} e Event.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.handlePostCompose_ = function(e) {
|
Graticule.prototype.handlePostCompose_ = function(e) {
|
||||||
var vectorContext = e.vectorContext;
|
var vectorContext = e.vectorContext;
|
||||||
var frameState = e.frameState;
|
var frameState = e.frameState;
|
||||||
var extent = frameState.extent;
|
var extent = frameState.extent;
|
||||||
@@ -677,7 +676,7 @@ _ol_Graticule_.prototype.handlePostCompose_ = function(e) {
|
|||||||
* @param {ol.proj.Projection} projection Projection.
|
* @param {ol.proj.Projection} projection Projection.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.updateProjectionInfo_ = function(projection) {
|
Graticule.prototype.updateProjectionInfo_ = function(projection) {
|
||||||
var epsg4326Projection = getProjection('EPSG:4326');
|
var epsg4326Projection = getProjection('EPSG:4326');
|
||||||
|
|
||||||
var extent = projection.getExtent();
|
var extent = projection.getExtent();
|
||||||
@@ -722,7 +721,7 @@ _ol_Graticule_.prototype.updateProjectionInfo_ = function(projection) {
|
|||||||
* @param {ol.PluggableMap} map Map.
|
* @param {ol.PluggableMap} map Map.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_Graticule_.prototype.setMap = function(map) {
|
Graticule.prototype.setMap = function(map) {
|
||||||
if (this.map_) {
|
if (this.map_) {
|
||||||
this.map_.un(_ol_render_EventType_.POSTCOMPOSE,
|
this.map_.un(_ol_render_EventType_.POSTCOMPOSE,
|
||||||
this.handlePostCompose_, this);
|
this.handlePostCompose_, this);
|
||||||
@@ -735,4 +734,4 @@ _ol_Graticule_.prototype.setMap = function(map) {
|
|||||||
}
|
}
|
||||||
this.map_ = map;
|
this.map_ = map;
|
||||||
};
|
};
|
||||||
export default _ol_Graticule_;
|
export default Graticule;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ol_Graticule_ from '../../../src/ol/Graticule.js';
|
import Graticule from '../../../src/ol/Graticule.js';
|
||||||
import _ol_Map_ from '../../../src/ol/Map.js';
|
import _ol_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 _ol_style_Stroke_ from '../../../src/ol/style/Stroke.js';
|
import _ol_style_Stroke_ from '../../../src/ol/style/Stroke.js';
|
||||||
@@ -8,7 +8,7 @@ describe('ol.Graticule', function() {
|
|||||||
var graticule;
|
var graticule;
|
||||||
|
|
||||||
function createGraticule() {
|
function createGraticule() {
|
||||||
graticule = new _ol_Graticule_({
|
graticule = new Graticule({
|
||||||
map: new _ol_Map_({})
|
map: new _ol_Map_({})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ describe('ol.Graticule', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates a graticule with labels', function() {
|
it('creates a graticule with labels', function() {
|
||||||
graticule = new _ol_Graticule_({
|
graticule = new Graticule({
|
||||||
map: new _ol_Map_({}),
|
map: new _ol_Map_({}),
|
||||||
showLabels: true
|
showLabels: true
|
||||||
});
|
});
|
||||||
@@ -62,7 +62,7 @@ describe('ol.Graticule', function() {
|
|||||||
var customStrokeStyle = new _ol_style_Stroke_({
|
var customStrokeStyle = new _ol_style_Stroke_({
|
||||||
color: 'rebeccapurple'
|
color: 'rebeccapurple'
|
||||||
});
|
});
|
||||||
var styledGraticule = new _ol_Graticule_({
|
var styledGraticule = new Graticule({
|
||||||
map: new _ol_Map_({}),
|
map: new _ol_Map_({}),
|
||||||
strokeStyle: customStrokeStyle
|
strokeStyle: customStrokeStyle
|
||||||
});
|
});
|
||||||
@@ -75,7 +75,7 @@ describe('ol.Graticule', function() {
|
|||||||
it('can be configured with label options', function() {
|
it('can be configured with label options', function() {
|
||||||
var latLabelStyle = new _ol_style_Text_();
|
var latLabelStyle = new _ol_style_Text_();
|
||||||
var lonLabelStyle = new _ol_style_Text_();
|
var lonLabelStyle = new _ol_style_Text_();
|
||||||
graticule = new _ol_Graticule_({
|
graticule = new Graticule({
|
||||||
map: new _ol_Map_({}),
|
map: new _ol_Map_({}),
|
||||||
showLabels: true,
|
showLabels: true,
|
||||||
lonLabelFormatter: function(lon) {
|
lonLabelFormatter: function(lon) {
|
||||||
|
|||||||
Reference in New Issue
Block a user