Skip to content

Commit

Permalink
Move createDefaultEditingStyles() to ol.style
Browse files Browse the repository at this point in the history
  • Loading branch information
probins committed Aug 11, 2014
1 parent 9db936f commit ed2f2be
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 74 deletions.
68 changes: 0 additions & 68 deletions src/ol/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('ol.Object');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.GeometryType');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');


Expand Down Expand Up @@ -325,67 +321,3 @@ ol.feature.createFeatureStyleFunction = function(obj) {
}
return styleFunction;
};


/**
* Default styles for editing features.
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
*/
ol.feature.createDefaultEditingStyles = function() {
/** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */
var styles = {};
var white = [255, 255, 255, 1];
var blue = [0, 153, 255, 1];
var width = 3;
styles[ol.geom.GeometryType.POLYGON] = [
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 255, 255, 0.5]
})
})
];
styles[ol.geom.GeometryType.MULTI_POLYGON] =
styles[ol.geom.GeometryType.POLYGON];

styles[ol.geom.GeometryType.LINE_STRING] = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white,
width: width + 2
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue,
width: width
})
})
];
styles[ol.geom.GeometryType.MULTI_LINE_STRING] =
styles[ol.geom.GeometryType.LINE_STRING];

styles[ol.geom.GeometryType.POINT] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: width * 2,
fill: new ol.style.Fill({
color: blue
}),
stroke: new ol.style.Stroke({
color: white,
width: width / 2
})
}),
zIndex: Infinity
})
];
styles[ol.geom.GeometryType.MULTI_POINT] =
styles[ol.geom.GeometryType.POINT];

styles[ol.geom.GeometryType.GEOMETRY_COLLECTION] =
styles[ol.geom.GeometryType.POLYGON].concat(
styles[ol.geom.GeometryType.POINT]
);

return styles;
};
4 changes: 2 additions & 2 deletions src/ol/interaction/drawinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ goog.require('ol.Map');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.events.condition');
goog.require('ol.feature');
goog.require('ol.geom.GeometryType');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
Expand All @@ -21,6 +20,7 @@ goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Pointer');
goog.require('ol.source.Vector');
goog.require('ol.style.Style');


/**
Expand Down Expand Up @@ -208,7 +208,7 @@ goog.inherits(ol.interaction.Draw, ol.interaction.Pointer);
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Draw.getDefaultStyleFunction = function() {
var styles = ol.feature.createDefaultEditingStyles();
var styles = ol.style.createDefaultEditingStyles();
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/modifyinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ goog.require('ol.ViewHint');
goog.require('ol.coordinate');
goog.require('ol.events.condition');
goog.require('ol.extent');
goog.require('ol.feature');
goog.require('ol.geom.GeometryType');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
Expand All @@ -23,6 +22,7 @@ goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Pointer');
goog.require('ol.structs.RBush');
goog.require('ol.style.Style');


/**
Expand Down Expand Up @@ -772,7 +772,7 @@ ol.interaction.Modify.prototype.updateSegmentIndices_ = function(
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Modify.getDefaultStyleFunction = function() {
var style = ol.feature.createDefaultEditingStyles();
var style = ol.style.createDefaultEditingStyles();
return function(feature, resolution) {
return style[ol.geom.GeometryType.POINT];
};
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/selectinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.events.condition');
goog.require('ol.feature');
goog.require('ol.geom.GeometryType');
goog.require('ol.interaction.Interaction');
goog.require('ol.style.Style');



Expand Down Expand Up @@ -207,7 +207,7 @@ ol.interaction.Select.prototype.setMap = function(map) {
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Select.getDefaultStyleFunction = function() {
var styles = ol.feature.createDefaultEditingStyles();
var styles = ol.style.createDefaultEditingStyles();
goog.array.extend(styles[ol.geom.GeometryType.POLYGON],
styles[ol.geom.GeometryType.LINE_STRING]);
goog.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION],
Expand Down
65 changes: 65 additions & 0 deletions src/ol/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ goog.provide('ol.style.Style');

goog.require('goog.asserts');
goog.require('goog.functions');
goog.require('ol.geom.GeometryType');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Image');
Expand Down Expand Up @@ -178,3 +179,67 @@ ol.style.defaultStyleFunction = function(feature, resolution) {

return styles;
};


/**
* Default styles for editing features.
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
*/
ol.style.createDefaultEditingStyles = function() {
/** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */
var styles = {};
var white = [255, 255, 255, 1];
var blue = [0, 153, 255, 1];
var width = 3;
styles[ol.geom.GeometryType.POLYGON] = [
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 255, 255, 0.5]
})
})
];
styles[ol.geom.GeometryType.MULTI_POLYGON] =
styles[ol.geom.GeometryType.POLYGON];

styles[ol.geom.GeometryType.LINE_STRING] = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white,
width: width + 2
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue,
width: width
})
})
];
styles[ol.geom.GeometryType.MULTI_LINE_STRING] =
styles[ol.geom.GeometryType.LINE_STRING];

styles[ol.geom.GeometryType.POINT] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: width * 2,
fill: new ol.style.Fill({
color: blue
}),
stroke: new ol.style.Stroke({
color: white,
width: width / 2
})
}),
zIndex: Infinity
})
];
styles[ol.geom.GeometryType.MULTI_POINT] =
styles[ol.geom.GeometryType.POINT];

styles[ol.geom.GeometryType.GEOMETRY_COLLECTION] =
styles[ol.geom.GeometryType.POLYGON].concat(
styles[ol.geom.GeometryType.POINT]
);

return styles;
};

0 comments on commit ed2f2be

Please sign in to comment.