kmz_compressor 2.1.3 → 2.3.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d4150ed49c4d494b601e80fc834eedb42687448fabf2aa6ca15135f50a5704d
4
+ data.tar.gz: e69879f14f2795a1a8c81d3430ef38c2aaf88bda6f2e08bf03cc776770225a4b
5
+ SHA512:
6
+ metadata.gz: af42f8519f2f32894d9e767c88cf654d68c312af9c5d9b29c03259d5294e3c3dc637564d471a32c86ddabde57eae16a851ee0504bc275884828db9575e9720fd
7
+ data.tar.gz: 644b4b4841d7e3a25018afb468abe4a6142fcf005edbec11879ab6a653e864c01cea0ee1f0cfa7e4bba367e07165da44bdf7214efa7f994ef0ee138d099153c2
@@ -16,15 +16,16 @@ window.MapLayerManager = function(map){
16
16
  var requestTimestamp = new Date;
17
17
  var retryDelay = retryDelay || 2000;
18
18
 
19
- kmlURL = sanitizeURI(kmlURL);
20
- options = jQuery.extend(true, {zIndex:zIndexCount++}, options); // Deep copy the options in case they are changed between now and when the map is ready to load
19
+ kmlURL = prepareUrl(kmlURL);
20
+
21
+ options = jQuery.extend(true, {zIndex:getDrawOrder(layerName)}, options); // Deep copy the options in case they are changed between now and when the map is ready to load
21
22
 
22
23
  return $.ajax(kmlURL, {type:'head', statusCode:{
23
24
  202: function(){ setTimeout(function(){ cacheAndLoadKMLLayer(kmlURL, layerName, options, retryDelay * 2) }, retryDelay) },
24
25
  200: function(){
25
26
  if (!requestTimestamps[layerName] || requestTimestamps[layerName] < requestTimestamp){
26
27
  requestTimestamps[layerName] = requestTimestamp;
27
- loadKMLLayer(cachedKMZURL(kmlURL), layerName, options)
28
+ loadKMLLayerWithoutExtraParams(cachedKMZURL(kmlURL), layerName, options)
28
29
  }
29
30
  }
30
31
  }}).error(function(){
@@ -34,9 +35,12 @@ window.MapLayerManager = function(map){
34
35
  }
35
36
 
36
37
  function loadKMLLayer(kmlURL, layerName, options) {
37
- // Replace spaces with pluses so we don't have problems with some things turning them into %20s and some not
38
- kmlURL = sanitizeURI(kmlURL);
39
- options = jQuery.extend(true, {zIndex:zIndexCount++, map:map}, options);
38
+ kmlURL = prepareUrl(kmlURL);
39
+ loadKMLLayerWithoutExtraParams(kmlURL, layerName, options)
40
+ }
41
+
42
+ function loadKMLLayerWithoutExtraParams(kmlURL, layerName, options) {
43
+ options = jQuery.extend(true, {zIndex:getDrawOrder(layerName), map:map}, options);
40
44
 
41
45
  var kmlLayer = new google.maps.KmlLayer(kmlURL, options);
42
46
  var layer = addLayer(layerName, kmlLayer)
@@ -145,6 +149,17 @@ window.MapLayerManager = function(map){
145
149
  }
146
150
  }
147
151
 
152
+ // Returns the draw order for the layer if it exists,
153
+ // Else generates and returns a new draw order
154
+ function getDrawOrder(layerName){
155
+ var layer = getLayer(layerName)
156
+ if (layer){
157
+ return layer.kml.getZIndex()
158
+ } else {
159
+ return zIndexCount++
160
+ }
161
+ }
162
+
148
163
  function setKMLOptions(layerName, options){
149
164
  var layer = getLayer(layerName)
150
165
  if (layer){
@@ -171,7 +186,7 @@ window.MapLayerManager = function(map){
171
186
 
172
187
  for (var i = 0; i < layerNames.length; i++){
173
188
  var layer = getLayer(layerNames[i])
174
- if (layer.error){
189
+ if (!layer || layer.error){
175
190
  continue
176
191
  }
177
192
 
@@ -218,6 +233,8 @@ window.MapLayerManager = function(map){
218
233
  // Keep layers synced with their state
219
234
  function sweep(){
220
235
  var foundLayers = [];
236
+ var staleLayers = []
237
+
221
238
  eachLayer(function(layer, index){
222
239
  var kmlStatus = layer.kml ? layer.kml.getStatus() : null;
223
240
 
@@ -235,44 +252,77 @@ window.MapLayerManager = function(map){
235
252
  }
236
253
 
237
254
  // Remove old layers
238
- // Sweep through layers from the newest to oldest, if a layer name is seen more than once, delete all but the newest
255
+ // Sweep through layers from the newest to oldest, if a layer name is seen more than once, mark all but the newest for deletion
239
256
  // Don't delete an instance if we haven't yet seen a version of it with status 'OK'
240
257
  if ($.inArray(layer.name, foundLayers) > -1){
241
- layer.kml.setMap(null);
242
- layers.splice(index, 1);
258
+ staleLayers.push(layer)
243
259
  } else if (layer.loaded) {
244
260
  foundLayers.push(layer.name)
245
261
  }
246
262
  })
263
+
264
+ // Delete stale layers
265
+ $.each(staleLayers, function(_, staleLayer){
266
+ eachLayer(function(layer, index){
267
+ if (layer == staleLayer){
268
+ layer.kml.setMap(null);
269
+ layers.splice(index, 1)
270
+ return false
271
+ }
272
+ })
273
+ })
247
274
  }
248
275
 
249
- // Replace spaces with pluses so we don't have problems with some things turning them into %20s and some not
250
- // Matches the middleware process
251
- function sanitizeURI(uri){
276
+ function prepareUrl(kmlURL) {
277
+ kmlURL = sanitizeURI(kmlURL);
278
+ kmlURL = addExtraParams(kmlURL, window.MapLayerManager.extraParams);
279
+ return kmlURL;
280
+ }
281
+
282
+ function sanitizeURI(uri) {
252
283
  var url = urlToObject(uri)
253
- var pathname = ('/' + decodeURI(url.pathname)).replace(/^\/+/, '/').trim() // Ensure there is a leading slash (IE doesn't provide one, Chrome does, FF does)
254
- var search = decodeURIComponent(url.search.replace(/\+/g, '%20')).trim().replace(/^\?/, '') // Ensure all "plus spaces" are hex encoded spaces
284
+ var pathname = ('/' + decodeURI(url.pathname)).replace(/^\/+/, '/').trim() // Ensure there is a leading slash (IE doesn't provide one, Chrome does, FF does)
255
285
 
256
- output = pathname
286
+ var search = url.search.replace(/%26/g, '%2526').replace(/%3D/g, '%253D') // Double encode & and = or else we will be unable to tell them apart from unencoded ones
287
+ search = search.replace(/\+/g, '%20') // Ensure all "plus spaces" are hex encoded spaces
288
+ search = decodeURIComponent(search).trim().replace(/^\?/, '') // Remove any leading ?
257
289
 
258
- if (search !== ''){
259
- output += '?'
260
- }
290
+ output = pathname
291
+ if (search !== '') { output += '?' }
261
292
 
262
293
  // Encode the individual uri components
263
294
  output += $.map(search.split('&'), function(component){
264
295
  return $.map(component.split('='), function(kv){
296
+ // Unencode double encoded & and = from earlier
297
+ kv = kv.replace(/%26/g, '&').replace(/%3D/g, '=')
298
+
299
+ kv = encodeURIComponent(kv)
300
+
265
301
  // HACK: Firefox 'helps' us out by encoding apostrophes as %27 in AJAX requests, However its encodeURIcomponent method
266
302
  // does not. This difference causes a mismatch between the url we use to calculate the cache path in the browser
267
303
  // and on the server. This hack undoes the damage. See https://bugzilla.mozilla.org/show_bug.cgi?id=407172
268
- return encodeURIComponent(kv).replace(/'/g, '%27')
304
+ kv = kv.replace(/'/g, '%27')
305
+
306
+ return kv
269
307
  }).join('=')
270
308
  }).join('&')
309
+
271
310
  url.href = output
272
311
 
273
312
  return url.href
274
313
  }
275
314
 
315
+ function addExtraParams(url, extraParams) {
316
+ url = urlToObject(url)
317
+ var paramString = $.param(extraParams || {})
318
+
319
+ if (paramString) {
320
+ url.search = url.search ? url.search + '&' + paramString : paramString
321
+ }
322
+
323
+ return url.href
324
+ }
325
+
276
326
  function closeInfowindowsExcept(layerName){
277
327
  eachLayer(function(layer){
278
328
  if (layer.name != layerName){
@@ -317,6 +367,7 @@ window.MapLayerManager = function(map){
317
367
  $(manager).trigger(data).trigger(nameData)
318
368
  }
319
369
 
370
+
320
371
  // INIT
321
372
 
322
373
  // Because google events sometimes get missed, we ensure we're up to date every now and again
@@ -339,6 +390,7 @@ window.MapLayerManager = function(map){
339
390
  this.hideLayer = hideLayer,
340
391
  this.showLayer = showLayer,
341
392
  this.setDrawOrder = setDrawOrder,
393
+ this.getDrawOrder = getDrawOrder,
342
394
  this.eachLayer = eachLayer,
343
395
  this.setKMLOptions = setKMLOptions
344
396
  }
@@ -6,7 +6,7 @@ require 'kmz_compressor/middleware'
6
6
  module KMZCompressor
7
7
  class Railtie < Rails::Railtie
8
8
  initializer "kmz_compressor.init" do |app|
9
- app.config.middleware.use "KMZCompressor::Middleware"
9
+ app.config.middleware.use KMZCompressor::Middleware
10
10
 
11
11
  Mime::Type.register "application/vnd.google-earth.kml+xml", :kml
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module KMZCompressor
2
- VERSION = "2.1.3"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kmz_compressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
5
- prerelease:
4
+ version: 2.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ryan Wallace
@@ -10,34 +9,25 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2015-04-15 00:00:00.000000000 Z
12
+ date: 2020-06-25 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '3.1'
23
- - - "<"
24
- - !ruby/object:Gem::Version
25
- version: 4.2.0
26
21
  type: :runtime
27
22
  prerelease: false
28
23
  version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
24
  requirements:
31
25
  - - ">="
32
26
  - !ruby/object:Gem::Version
33
27
  version: '3.1'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: 4.2.0
37
28
  - !ruby/object:Gem::Dependency
38
29
  name: rubyzip
39
30
  requirement: !ruby/object:Gem::Requirement
40
- none: false
41
31
  requirements:
42
32
  - - "~>"
43
33
  - !ruby/object:Gem::Version
@@ -45,7 +35,6 @@ dependencies:
45
35
  type: :runtime
46
36
  prerelease: false
47
37
  version_requirements: !ruby/object:Gem::Requirement
48
- none: false
49
38
  requirements:
50
39
  - - "~>"
51
40
  - !ruby/object:Gem::Version
@@ -58,41 +47,39 @@ executables: []
58
47
  extensions: []
59
48
  extra_rdoc_files: []
60
49
  files:
50
+ - MIT-LICENSE
51
+ - README.rdoc
52
+ - app/assets/javascripts/kmz_compressor.js
61
53
  - app/assets/javascripts/kmz_compressor/map_layer_manager.js
62
54
  - app/assets/javascripts/kmz_compressor/polyfills.js
63
55
  - app/assets/javascripts/kmz_compressor/sha2.js
64
- - app/assets/javascripts/kmz_compressor.js
65
- - app/helpers/kmz_compressor/kml_helper.rb
56
+ - lib/kmz_compressor.rb
66
57
  - lib/kmz_compressor/controller_extensions.rb
67
58
  - lib/kmz_compressor/engine.rb
68
59
  - lib/kmz_compressor/middleware.rb
69
60
  - lib/kmz_compressor/railtie.rb
70
61
  - lib/kmz_compressor/version.rb
71
- - lib/kmz_compressor.rb
72
- - MIT-LICENSE
73
- - README.rdoc
74
62
  homepage: http://github.com/culturecode/kmz_compressor
75
63
  licenses: []
64
+ metadata: {}
76
65
  post_install_message:
77
66
  rdoc_options: []
78
67
  require_paths:
79
68
  - lib
80
69
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
70
  requirements:
83
71
  - - ">="
84
72
  - !ruby/object:Gem::Version
85
73
  version: '0'
86
74
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
75
  requirements:
89
76
  - - ">="
90
77
  - !ruby/object:Gem::Version
91
78
  version: '0'
92
79
  requirements: []
93
80
  rubyforge_project:
94
- rubygems_version: 1.8.25
81
+ rubygems_version: 2.7.9
95
82
  signing_key:
96
- specification_version: 3
83
+ specification_version: 4
97
84
  summary: Rack Middleware which retrieves KML from Rails and produces KMZ for the client.
98
85
  test_files: []
@@ -1,8 +0,0 @@
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