Use new ol.style in geojson example

This commit is contained in:
Éric Lemoine
2013-11-20 14:48:46 +01:00
parent db7ce8e657
commit 602fd7f13a

View File

@@ -9,52 +9,56 @@ goog.require('ol.layer.Vector');
goog.require('ol.shape'); goog.require('ol.shape');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
goog.require('ol.source.Vector'); goog.require('ol.source.Vector');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
var image = ol.shape.renderCircle(5, null, {color: 'red', width: 1}); var image = ol.shape.renderCircle(5, null,
new ol.style.Stroke({color: 'red', width: 1}));
var styleFunction = function(feature) { var styleFunction = function(feature) {
switch (feature.getGeometry().getType()) { switch (feature.getGeometry().getType()) {
case 'Point': case 'Point':
return { return new ol.style.Style({
image: image image: image
}; });
case 'Polygon': case 'Polygon':
return { return new ol.style.Style({
stroke: { stroke: new ol.style.Stroke({
color: 'blue', color: 'blue',
width: 3 width: 3
}, }),
fill: { fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)' color: 'rgba(0, 0, 255, 0.1)'
} })
}; });
case 'MultiLineString': case 'MultiLineString':
return { return new ol.style.Style({
stroke: { stroke: new ol.style.Stroke({
color: 'green', color: 'green',
width: 1 width: 1
} })
}; });
case 'MultiPolygon': case 'MultiPolygon':
return { return new ol.style.Style({
stroke: { stroke: new ol.style.Stroke({
color: 'yellow', color: 'yellow',
width: 1 width: 1
}, }),
fill: { fill: new ol.style.Fill({
color: 'rgba(255, 255, 0, 0.1)' color: 'rgba(255, 255, 0, 0.1)'
} })
}; });
default: default:
return { return new ol.style.Style({
stroke: { stroke: new ol.style.Stroke({
color: 'red', color: 'red',
width: 2 width: 2
}, }),
fill: { fill: new ol.style.Fill({
color: 'rgba(255, 0, 0, 0.1)' color: 'rgba(255, 0, 0, 0.1)'
} })
}; });
} }
}; };
@@ -125,10 +129,10 @@ var tmpFeature = new ol.Feature(
var tmpStyle = { var tmpStyle = {
fill: null, fill: null,
image: null, image: null,
stroke: { stroke: new ol.style.Stroke({
color: 'magenta', color: 'magenta',
width: 5 width: 5
} })
}; };
vectorLayer.on('postcompose', function(event) { vectorLayer.on('postcompose', function(event) {
var render = event.getRender(); var render = event.getRender();