Move defaults style into style.js
This commit is contained in:
@@ -10,7 +10,7 @@ goog.require('ol.CollectionEventType');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.render.EventType');
|
||||
goog.require('ol.renderer.vector');
|
||||
goog.require('ol.style.defaults');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ ol.FeatureOverlay = function(opt_options) {
|
||||
this.styleFunction_ = undefined;
|
||||
|
||||
this.setStyle(goog.isDef(options.style) ?
|
||||
options.style : ol.style.defaults.styleFunction);
|
||||
options.style : ol.style.defaultStyleFunction);
|
||||
|
||||
if (goog.isDef(options.features)) {
|
||||
if (goog.isArray(options.features)) {
|
||||
@@ -168,7 +168,7 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
|
||||
}
|
||||
var styleFunction = this.styleFunction_;
|
||||
if (!goog.isDef(styleFunction)) {
|
||||
styleFunction = ol.style.defaults.styleFunction;
|
||||
styleFunction = ol.style.defaultStyleFunction;
|
||||
}
|
||||
var replayGroup = /** @type {ol.render.IReplayGroup} */
|
||||
(event.replayGroup);
|
||||
|
||||
@@ -3,7 +3,6 @@ goog.provide('ol.layer.Vector');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.defaults');
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,7 +52,7 @@ ol.layer.Vector = function(opt_options) {
|
||||
this.styleFunction_ = undefined;
|
||||
|
||||
this.setStyle(goog.isDefAndNotNull(options.style) ?
|
||||
options.style : ol.style.defaults.styleFunction);
|
||||
options.style : ol.style.defaultStyleFunction);
|
||||
|
||||
};
|
||||
goog.inherits(ol.layer.Vector, ol.layer.Layer);
|
||||
|
||||
@@ -10,7 +10,7 @@ goog.require('ol.render.canvas.ReplayGroup');
|
||||
goog.require('ol.renderer.vector');
|
||||
goog.require('ol.source.ImageCanvas');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.defaults');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.vec.Mat4');
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ ol.source.ImageVector = function(options) {
|
||||
*/
|
||||
this.styleFunction_ = goog.isDefAndNotNull(options.style) ?
|
||||
ol.style.createStyleFunction(options.style) :
|
||||
ol.style.defaults.styleFunction;
|
||||
ol.style.defaultStyleFunction;
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
goog.provide('ol.style.defaults');
|
||||
|
||||
goog.require('ol.style.Circle');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array.<ol.style.Style>} Style.
|
||||
*/
|
||||
ol.style.defaults.styleFunction = function(feature, resolution) {
|
||||
var fill = new ol.style.Fill({
|
||||
color: 'rgba(255,255,255,0.4)'
|
||||
});
|
||||
var stroke = new ol.style.Stroke({
|
||||
color: '#3399CC',
|
||||
width: 1.25
|
||||
});
|
||||
var styles = [
|
||||
new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
radius: 5
|
||||
}),
|
||||
fill: fill,
|
||||
stroke: stroke
|
||||
})
|
||||
];
|
||||
|
||||
// now that we've run it the first time,
|
||||
// replace the function with a constant version
|
||||
ol.style.defaults.styleFunction =
|
||||
/** @type {function(this:ol.Feature):Array.<ol.style.Style>} */(
|
||||
function(resolution) {
|
||||
return styles;
|
||||
});
|
||||
|
||||
return styles;
|
||||
};
|
||||
@@ -2,8 +2,10 @@ goog.provide('ol.style.Style');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.style.Circle');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Image');
|
||||
goog.require('ol.style.Stroke');
|
||||
|
||||
|
||||
|
||||
@@ -139,3 +141,40 @@ ol.style.createStyleFunction = function(obj) {
|
||||
}
|
||||
return styleFunction;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array.<ol.style.Style>} Style.
|
||||
*/
|
||||
ol.style.defaultStyleFunction = function(feature, resolution) {
|
||||
var fill = new ol.style.Fill({
|
||||
color: 'rgba(255,255,255,0.4)'
|
||||
});
|
||||
var stroke = new ol.style.Stroke({
|
||||
color: '#3399CC',
|
||||
width: 1.25
|
||||
});
|
||||
var styles = [
|
||||
new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
radius: 5
|
||||
}),
|
||||
fill: fill,
|
||||
stroke: stroke
|
||||
})
|
||||
];
|
||||
|
||||
// now that we've run it the first time,
|
||||
// replace the function with a constant version
|
||||
ol.style.defaultStyleFunction =
|
||||
/** @type {function(this:ol.Feature):Array.<ol.style.Style>} */(
|
||||
function(resolution) {
|
||||
return styles;
|
||||
});
|
||||
|
||||
return styles;
|
||||
};
|
||||
|
||||
@@ -76,10 +76,10 @@ describe('ol.layer.Vector', function() {
|
||||
var layer = new ol.layer.Vector({
|
||||
source: source
|
||||
});
|
||||
expect(layer.getStyleFunction()).to.be(ol.style.defaults.styleFunction);
|
||||
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
|
||||
layer.setStyle(style);
|
||||
expect(layer.getStyleFunction()).not.to.be(
|
||||
ol.style.defaults.styleFunction);
|
||||
ol.style.defaultStyleFunction);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -94,7 +94,7 @@ describe('ol.layer.Vector', function() {
|
||||
source: source
|
||||
});
|
||||
|
||||
expect(layer.getStyle()).to.be(ol.style.defaults.styleFunction);
|
||||
expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction);
|
||||
|
||||
layer.setStyle(style);
|
||||
expect(layer.getStyle()).to.be(style);
|
||||
@@ -118,4 +118,3 @@ goog.require('ol.layer.Layer');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.defaults');
|
||||
|
||||
Reference in New Issue
Block a user