kmz_compressor 2.0.20 → 2.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cd1222730e62982f4c2cd8b6c9ee1589b7285e0
4
- data.tar.gz: 48ec32ef2f3812667804a0c5888c2d291db7f20c
3
+ metadata.gz: e22aba0509514efb8239afffafda9f4b54109f40
4
+ data.tar.gz: 7a21381d0c48f1136c234c2ee11efb423793963a
5
5
  SHA512:
6
- metadata.gz: 436b2c0df6239b37e859093542e040d7dd203f5372abf8f1027fdc20ad27b3d2db89a7050130180504328b61d28d231f498bf01a51db35960d04de74d30d7c51
7
- data.tar.gz: 45b8f0e3e8a1a87b7e5391d251d65fbd91214d12483c7709d38968eaa96b007469f2be3ff012ce496c796ad40169ecba0d7b17b9e1d3a3c38eb08b00c2ab9d2b
6
+ metadata.gz: c81b20493bd109cf7b692b16430aed4a5d47e32014c0c7e2bc7cbf2cdd36254f2ff30120ac45c080f40064d19471c59176d0c84174ab28f3cef9126331e59ab9
7
+ data.tar.gz: ceb030a69d360f877d38154d1aa081c86a00121cafea3dfef8ab59460fc9d68cfe800b9a2db07d0ff4833745662bf4dabc2cf440d54f3c210f16770b56936d23
@@ -10,16 +10,24 @@ window.MapLayerManager = function(map){
10
10
  var layerClickedEventName = 'map:layerClicked'
11
11
 
12
12
  // Prime the KMZ cache on the server before unleashing google's many tilemills
13
- function cacheAndLoadKMLLayer(kmlURL, layerName, options) {
13
+ function cacheAndLoadKMLLayer(kmlURL, layerName, options, retryDelay) {
14
14
  var requestTimestamp = new Date;
15
+ var retryDelay = retryDelay || 2000;
16
+
15
17
  kmlURL = sanitizeURI(kmlURL);
16
18
 
17
- $.ajax(kmlURL, {type:'head', complete:function(){
19
+ return $.ajax(kmlURL, {type:'head', statusCode:{
20
+ 202: function(){ setTimeout(function(){ cacheAndLoadKMLLayer(kmlURL, layerName, options, retryDelay * 2) }, retryDelay) },
21
+ 200: function(){
18
22
  if (!requestTimestamps[layerName] || requestTimestamps[layerName] < requestTimestamp){
19
23
  requestTimestamps[layerName] = requestTimestamp;
20
24
  loadKMLLayer(cachedKMZURL(kmlURL), layerName, options)
21
25
  }
22
- }});
26
+ }
27
+ }}).error(function(){
28
+ console.error("Server returned an error when checking if " + kmlURL + " was cached")
29
+ })
30
+
23
31
  }
24
32
 
25
33
  function loadKMLLayer(kmlURL, layerName, options) {
@@ -0,0 +1,8 @@
1
+ module KmzCompressor
2
+ module KmlHelper
3
+ # Converts KML colours which are BBGGRR into web colours which are RRGGBB
4
+ def kml_colour(html_hex_colour)
5
+ html_hex_colour.gsub(/([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])/i, '\3\2\1')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ require 'digest'
2
+
3
+ module KMZCompressor
4
+ module ControllerExtensions
5
+
6
+ module ClassMethods
7
+ def defer_until_kmz_cached(*actions)
8
+ around_filter :render_202_while_caching, :only => actions
9
+ end
10
+ end
11
+
12
+ module InstanceMethods
13
+ # Subsequent calls to this action return a 202 while the original result is being cached
14
+ def render_202_while_caching(&action)
15
+ cache_key = [:kmz_in_progress, Digest::SHA256.base64digest(params.inspect)]
16
+
17
+ if Rails.cache.exist?(cache_key)
18
+ render :status => 202, :nothing => true
19
+ else
20
+ begin
21
+ Rails.cache.write(cache_key, true, :expires_in => 1.hour) # Expire in case we somehow leave the cache key behind
22
+ action.call
23
+ ensure
24
+ # Rails.cache.delete(cache_key)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -1,4 +1,12 @@
1
+ require 'kmz_compressor/controller_extensions'
2
+
1
3
  module KMZCompressor
2
4
  class Engine < Rails::Engine
5
+
6
+ initializer 'kmz_compressor.extend_application_controller' do |app|
7
+ ApplicationController.extend ControllerExtensions::ClassMethods
8
+ ApplicationController.include ControllerExtensions::InstanceMethods
9
+ end
10
+
3
11
  end
4
12
  end
@@ -1,3 +1,3 @@
1
1
  module KMZCompressor
2
- VERSION = "2.0.20"
2
+ VERSION = "2.0.21"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kmz_compressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.20
4
+ version: 2.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wallace
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-31 00:00:00.000000000 Z
12
+ date: 2015-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,7 +59,9 @@ files:
59
59
  - app/assets/javascripts/kmz_compressor/map_layer_manager.js
60
60
  - app/assets/javascripts/kmz_compressor/polyfills.js
61
61
  - app/assets/javascripts/kmz_compressor/sha2.js
62
+ - app/helpers/kmz_compressor/kml_helper.rb
62
63
  - lib/kmz_compressor.rb
64
+ - lib/kmz_compressor/controller_extensions.rb
63
65
  - lib/kmz_compressor/engine.rb
64
66
  - lib/kmz_compressor/middleware.rb
65
67
  - lib/kmz_compressor/railtie.rb
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  version: '0'
84
86
  requirements: []
85
87
  rubyforge_project:
86
- rubygems_version: 2.4.1
88
+ rubygems_version: 2.2.2
87
89
  signing_key:
88
90
  specification_version: 4
89
91
  summary: Rack Middleware which retrieves KML from Rails and produces KMZ for the client.