Adapt styleFunction in geojson example

This commit is contained in:
Éric Lemoine
2013-11-26 11:02:39 +01:00
parent 317294756a
commit 39af934e71
+26 -28
View File
@@ -17,31 +17,27 @@ goog.require('ol.style.Style');
var image = ol.shape.renderCircle(5, null, var image = ol.shape.renderCircle(5, null,
new ol.style.Stroke({color: 'red', width: 1})); new ol.style.Stroke({color: 'red', width: 1}));
var styleFunction = function(feature) {
switch (feature.getGeometry().getType()) { var styles = {
case 'Point': 'Point': [new ol.style.Style({
return new ol.style.Style({
image: image image: image
}); })],
case 'Polygon': 'LineString': [new ol.style.Style({
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
});
case 'MultiLineString':
return new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: 'green', color: 'green',
width: 1 width: 1
}) })
}); })],
case 'MultiPolygon': 'MultiLineString': [new ol.style.Style({
return new ol.style.Style({ stroke: new ol.style.Stroke({
color: 'green',
width: 1
})
})],
'MultiPoint': [new ol.style.Style({
image: image
})],
'MultiPolygon': [new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: 'yellow', color: 'yellow',
width: 1 width: 1
@@ -49,18 +45,20 @@ var styleFunction = function(feature) {
fill: new ol.style.Fill({ fill: new ol.style.Fill({
color: 'rgba(255, 255, 0, 0.1)' color: 'rgba(255, 255, 0, 0.1)'
}) })
}); })],
default: 'Polygon': [new ol.style.Style({
return new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: 'red', color: 'blue',
width: 2 width: 3
}), }),
fill: new ol.style.Fill({ fill: new ol.style.Fill({
color: 'rgba(255, 0, 0, 0.1)' color: 'rgba(0, 0, 255, 0.1)'
}) })
}); })]
} };
var styleFunction = function(feature, resolution) {
return styles[feature.getGeometry().getType()];
}; };
var vectorSource = new ol.source.Vector(); var vectorSource = new ol.source.Vector();