diff --git a/examples/topojson.js b/examples/topojson.js index babbce45ed..fe77568875 100644 --- a/examples/topojson.js +++ b/examples/topojson.js @@ -3,9 +3,8 @@ goog.require('ol.RendererHint'); goog.require('ol.View2D'); goog.require('ol.layer.Tile'); goog.require('ol.layer.Vector'); -goog.require('ol.parser.TopoJSON'); goog.require('ol.source.TileJSON'); -goog.require('ol.source.Vector'); +goog.require('ol.source.TopoJSON'); goog.require('ol.style.Fill'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); @@ -17,24 +16,23 @@ var raster = new ol.layer.Tile({ }) }); -var vector = new ol.layer.Vector({ - source: new ol.source.Vector({ - url: 'data/topojson/world-110m.json', - parser: new ol.parser.TopoJSON() +var styleArray = [new ol.style.Style({ + fill: new ol.style.Fill({ + color: 'rgba(255, 255, 255, 0.6)' }), - style: new ol.style.Style({ - symbolizers: [ - new ol.style.Fill({ - color: '#BADA55', - opacity: 0.5 - }), - new ol.style.Stroke({ - color: '#FFF', - opacity: 1, - width: 1.5 - }) - ] + stroke: new ol.style.Stroke({ + color: '#319FD3', + width: 1 }) +})]; + +var vector = new ol.layer.Vector({ + source: new ol.source.TopoJSON({ + url: 'data/topojson/world-110m.json' + }), + styleFunction: function(feature, resolution) { + return styleArray; + } }); var map = new ol.Map({ diff --git a/src/ol/source/topojsonsource.exports b/src/ol/source/topojsonsource.exports new file mode 100644 index 0000000000..d56afa819e --- /dev/null +++ b/src/ol/source/topojsonsource.exports @@ -0,0 +1 @@ +@exportSymbol ol.source.TopoJSON diff --git a/src/ol/source/topojsonsource.js b/src/ol/source/topojsonsource.js new file mode 100644 index 0000000000..2ca994b328 --- /dev/null +++ b/src/ol/source/topojsonsource.js @@ -0,0 +1,32 @@ +goog.provide('ol.source.TopoJSON'); + +goog.require('ol.format.TopoJSON'); +goog.require('ol.source.VectorFile'); + + + +/** + * @constructor + * @extends {ol.source.VectorFile} + * @param {olx.source.TopoJSONOptions=} opt_options Options. + */ +ol.source.TopoJSON = function(opt_options) { + + var options = goog.isDef(opt_options) ? opt_options : {}; + + goog.base(this, { + attributions: options.attributions, + extent: options.extent, + format: new ol.format.TopoJSON({ + defaultProjection: options.defaultProjection + }), + logo: options.logo, + object: options.object, + projection: options.projection, + reprojectTo: options.reprojectTo, + text: options.text, + url: options.url + }); + +}; +goog.inherits(ol.source.TopoJSON, ol.source.VectorFile);