Skip to content

Commit

Permalink
adds in geojson download type
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Nov 27, 2014
1 parent ced46f6 commit e90527f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/download_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def check_type
response = ShapefileDownload.new(@document).get
when 'kmz'
response = KmzDownload.new(@document).get
when 'geojson'
response = GeojsonDownload.new(@document).get
end
response
end
Expand Down
1 change: 1 addition & 0 deletions lib/geoblacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Geoblacklight
require 'geoblacklight/wms_layer'
require 'geoblacklight/download'
require 'geoblacklight/download/shapefile_download'
require 'geoblacklight/download/geojson_download'
require 'geoblacklight/download/kmz_download'
require 'geoblacklight/reference'
require 'geoblacklight/references'
Expand Down
20 changes: 20 additions & 0 deletions lib/geoblacklight/download/geojson_download.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class GeojsonDownload < Download
GEOJSON_DOWNLOAD_PARAMS = {
service: 'wfs',
version: '2.0.0',
request: 'GetFeature',
srsName: 'EPSG:4326',
outputformat: 'application/json'
}

def initialize(document)
request_params = GEOJSON_DOWNLOAD_PARAMS.merge(typeName: document[:layer_id_s])
super(document, {
type: 'geojson',
extension: 'json',
request_params: request_params,
content_type: 'application/json',
service_type: 'wfs'
})
end
end
2 changes: 1 addition & 1 deletion lib/geoblacklight/references.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def file_download
def downloads_by_format
case format
when 'Shapefile'
{ shapefile: wfs.to_hash, kmz: wms.to_hash }
{ shapefile: wfs.to_hash, kmz: wms.to_hash, geojson: wfs.to_hash }
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/lib/geoblacklight/download/geojson_download_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

describe GeojsonDownload do
let(:document) { SolrDocument.new(layer_slug_s: 'test', solr_wfs_url: 'http://www.example.com/wfs', layer_id_s: 'stanford-test', solr_bbox: '-180 -90 180 90') }
let(:download) { GeojsonDownload.new(document) }
describe '#initialize' do
it 'should initialize as a GeojsonDownload object with specific options' do
expect(download).to be_an GeojsonDownload
options = download.instance_variable_get(:@options)
expect(options[:content_type]).to eq 'application/json'
expect(options[:request_params][:typeName]).to eq 'stanford-test'
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/geoblacklight/references_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
it 'should return available downloads by format' do
types = complex_shapefile.download_types
expect(types.first[1]).to eq wfs: 'http://hgl.harvard.edu:8080/geoserver/wfs'
expect(types.count).to eq 2
expect(types.count).to eq 3
expect(direct_download_only.download_types).to be_nil
end
it 'should only return available downloads if no direct is present' do
types = typical_ogp_shapefile.download_types
expect(types.first[1]).to eq wfs: "http://hgl.harvard.edu:8080/geoserver/wfs"
expect(types.count).to eq 2
expect(types.count).to eq 3
end
end
end

0 comments on commit e90527f

Please sign in to comment.