goog.require('ol.Map'); goog.require('ol.View'); goog.require('ol.format.GeoJSON'); goog.require('ol.layer.Vector'); goog.require('ol.proj'); goog.require('ol.source.Vector'); goog.require('ol.style.Fill'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); // Will contain ol.Style instances key by country. var styleLookup = {}; // Generate a rainbow gradient var gradient = (function() { var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); var grad = context.createLinearGradient(0,0,1000,0); grad.addColorStop(0, 'red'); grad.addColorStop(1 / 6, 'orange'); grad.addColorStop(2 / 6, 'yellow'); grad.addColorStop(3 / 6, 'green'); grad.addColorStop(4 / 6, 'aqua'); grad.addColorStop(5 / 6, 'blue'); grad.addColorStop(1, 'purple'); return grad; }()); // Generate a canvasPattern with two circles var pattern = (function() { var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); canvas.width = 11; canvas.height = 11; context.fillStyle = 'rgba(102, 0, 102, 0.5)'; context.beginPath(); context.arc(5, 5, 4, 0, 2 * Math.PI); context.fill(); context.fillStyle = 'rgb(55, 0, 170)'; context.beginPath(); context.arc(5, 5, 2, 0, 2 * Math.PI); context.fill(); return context.createPattern(canvas, 'repeat'); }()); // Generate a background style that all features will reuse var backgroundStyle = new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#333', width: 2 }), fill: new ol.style.Fill({ color: '#fff' }) }); /** * The styling function for the vector layer, will return an array of styles * which either contains the aboove gradient or pattern. * * @param {ol.Feature} feature the feature to style. * @return {Array