Get rid of extra style arrays in examples

This commit is contained in:
Tim Schaub
2015-11-11 18:18:41 -07:00
parent e8c99e4e63
commit 99a902a311
19 changed files with 212 additions and 242 deletions
+37 -46
View File
@@ -107,75 +107,66 @@ var createTextStyle = function(feature, resolution, dom) {
// Polygons
var createPolygonStyleFunction = function() {
return function(feature, resolution) {
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
}),
text: createTextStyle(feature, resolution, myDom.polygons)
});
return [style];
};
};
function polygonStyleFunction(feature, resolution) {
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
}),
text: createTextStyle(feature, resolution, myDom.polygons)
});
}
var vectorPolygons = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'data/geojson/polygon-samples.geojson',
format: new ol.format.GeoJSON()
}),
style: createPolygonStyleFunction()
style: polygonStyleFunction
});
// Lines
var createLineStyleFunction = function() {
return function(feature, resolution) {
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'green',
width: 2
}),
text: createTextStyle(feature, resolution, myDom.lines)
});
return [style];
};
};
function lineStyleFunction(feature, resolution) {
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'green',
width: 2
}),
text: createTextStyle(feature, resolution, myDom.lines)
});
}
var vectorLines = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'data/geojson/line-samples.geojson',
format: new ol.format.GeoJSON()
}),
style: createLineStyleFunction()
style: lineStyleFunction
});
// Points
var createPointStyleFunction = function() {
return function(feature, resolution) {
var style = new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.1)'}),
stroke: new ol.style.Stroke({color: 'red', width: 1})
}),
text: createTextStyle(feature, resolution, myDom.points)
});
return [style];
};
};
function pointStyleFunction(feature, resolution) {
return new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.1)'}),
stroke: new ol.style.Stroke({color: 'red', width: 1})
}),
text: createTextStyle(feature, resolution, myDom.points)
});
}
var vectorPoints = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'data/geojson/point-samples.geojson',
format: new ol.format.GeoJSON()
}),
style: createPointStyleFunction()
style: pointStyleFunction
});
var map = new ol.Map({
@@ -195,15 +186,15 @@ var map = new ol.Map({
});
$('#refresh-points').click(function() {
vectorPoints.setStyle(createPointStyleFunction());
vectorPoints.setStyle(pointStyleFunction);
});
$('#refresh-lines').click(function() {
vectorLines.setStyle(createLineStyleFunction());
vectorLines.setStyle(lineStyleFunction);
});
$('#refresh-polygons').click(function() {
vectorPolygons.setStyle(createPolygonStyleFunction());
vectorPolygons.setStyle(polygonStyleFunction);
});