From 176a438a05be285aa6913aa3d4b6e8086827bfe5 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 8 Nov 2013 03:10:32 +0100 Subject: [PATCH] Add style function to GeoJSON demo --- examples/geojson.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/geojson.js b/examples/geojson.js index 5af1eb82d4..22f3b5758b 100644 --- a/examples/geojson.js +++ b/examples/geojson.js @@ -5,6 +5,22 @@ goog.require('ol.layer.Tile'); goog.require('ol.layer.Vector'); goog.require('ol.source.GeoJSON'); goog.require('ol.source.OSM'); +goog.require('ol.style.DefaultStyleFunction'); + + +var styleFunction = function(feature) { + switch (feature.getGeometry().getType()) { + case ol.geom.GeometryType.MULTI_LINE_STRING: + return { + stroke: { + color: 'green', + width: 1 + } + }; + default: + return ol.style.DefaultStyleFunction(feature); + } +}; var geoJSONSource = new ol.source.GeoJSON( /** @type {ol.source.GeoJSONOptions} */ ({ @@ -61,7 +77,8 @@ var map = new ol.Map({ source: new ol.source.OSM() }), new ol.layer.Vector({ - source: geoJSONSource + source: geoJSONSource, + styleFunction: styleFunction }) ], renderer: ol.RendererHint.CANVAS,