Give vector image source a style option
This commit is contained in:
@@ -121,7 +121,7 @@ dragAndDropInteraction.on('addfeatures', function(event) {
|
||||
map.getLayers().push(new ol.layer.Image({
|
||||
source: new ol.source.ImageVector({
|
||||
source: vectorSource,
|
||||
styleFunction: styleFunction
|
||||
style: styleFunction
|
||||
})
|
||||
}));
|
||||
var view2D = map.getView().getView2D();
|
||||
|
||||
@@ -11,16 +11,6 @@ goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
var styleArray = [new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(255, 255, 255, 0.6)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
width: 1
|
||||
})
|
||||
})];
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
@@ -32,9 +22,15 @@ var map = new ol.Map({
|
||||
projection: 'EPSG:3857',
|
||||
url: 'data/geojson/countries.geojson'
|
||||
}),
|
||||
styleFunction: function(feature, resolution) {
|
||||
return styleArray;
|
||||
}
|
||||
style: new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(255, 255, 255, 0.6)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
width: 1
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
],
|
||||
|
||||
@@ -736,8 +736,8 @@
|
||||
* new canvases will be created for these resolutions only.
|
||||
* @property {ol.source.Vector} source The vector source from which the vector
|
||||
* features drawn in canvas elements are read.
|
||||
* @property {ol.feature.StyleFunction|undefined} styleFunction Style function
|
||||
* providing the styles to use when rendering features to the canvas.
|
||||
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style
|
||||
* Style to use when rendering features to the canvas.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,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.Style');
|
||||
goog.require('ol.vec.Mat4');
|
||||
|
||||
|
||||
@@ -40,12 +41,38 @@ ol.source.ImageVector = function(options) {
|
||||
*/
|
||||
this.source_ = options.source;
|
||||
|
||||
|
||||
/**
|
||||
* @type {ol.feature.StyleFunction}
|
||||
*/
|
||||
var styleFunction;
|
||||
|
||||
if (goog.isDef(options.style)) {
|
||||
if (goog.isFunction(options.style)) {
|
||||
styleFunction = /** @type {ol.feature.StyleFunction} */ (options.style);
|
||||
} else {
|
||||
/**
|
||||
* @type {Array.<ol.style.Style>}
|
||||
*/
|
||||
var styles;
|
||||
if (goog.isArray(options.style)) {
|
||||
styles = options.style;
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(options.style, ol.style.Style);
|
||||
styles = [options.style];
|
||||
}
|
||||
styleFunction = function(feature, resolution) {
|
||||
return styles;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!ol.feature.StyleFunction}
|
||||
*/
|
||||
this.styleFunction_ = goog.isDef(options.styleFunction) ?
|
||||
options.styleFunction : ol.feature.defaultStyleFunction;
|
||||
this.styleFunction_ = goog.isDef(styleFunction) ?
|
||||
styleFunction : ol.feature.defaultStyleFunction;
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user