From a664c2dcd3db20cbb62c42ac4e3154b076772480 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 17:11:00 -0300 Subject: [PATCH 01/10] mapa no geografico --- .../controllers/non_geo_controller.js | 72 +++++++++++++++++++ app/models/metadata_non_geo.rb | 3 + app/views/posts/attribute_ro/_non_geo.haml | 6 ++ app/views/posts/attributes/_non_geo.haml | 24 +++++++ 4 files changed, 105 insertions(+) create mode 100644 app/javascript/controllers/non_geo_controller.js create mode 100644 app/models/metadata_non_geo.rb create mode 100644 app/views/posts/attribute_ro/_non_geo.haml create mode 100644 app/views/posts/attributes/_non_geo.haml diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js new file mode 100644 index 00000000..072c1b83 --- /dev/null +++ b/app/javascript/controllers/non_geo_controller.js @@ -0,0 +1,72 @@ +import { Controller } from 'stimulus' + +require("leaflet/dist/leaflet.css") +import L from 'leaflet' +delete L.Icon.Default.prototype._getIconUrl + +L.Icon.Default.mergeOptions({ + iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'), + iconUrl: require('leaflet/dist/images/marker-icon.png'), + shadowUrl: require('leaflet/dist/images/marker-shadow.png'), +}) + +export default class extends Controller { + static targets = [ 'lat', 'lng', 'map', 'overlay' ] + + async connect () { + this.marker() + + this.latTarget.addEventListener('change', event => this.marker()) + this.lngTarget.addEventListener('change', event => this.marker()) + window.addEventListener('resize', event => this.map.invalidateSize()) + + const res = await fetch(this.element.dataset.map); + this.overlayTarget.innerHTML = await res.text(); + + this.map.on('click', event => { + this.latTarget.value = event.latlng.lat + this.lngTarget.value = event.latlng.lng + + this.latTarget.dispatchEvent(new Event('change')) + }) + } + + marker () { + if (this._marker) this.map.removeLayer(this._marker) + + this._marker = L.marker(this.coords).addTo(this.map) + + return this._marker + } + + get lat () { + const lat = parseFloat(this.latTarget.value) + + return isNaN(lat) ? 0 : lat + } + + get lng () { + const lng = parseFloat(this.lngTarget.value) + + return isNaN(lng) ? 0 : lng + } + + get coords () { + return [this.lat, this.lng] + } + + get map () { + if (!this._map) { + this._map = L.map(this.mapTarget).setView(this.coords, 13); + + const bounds = [[0,0], [this.mapTarget.clientHeight, this.mapTarget.clientWidth]]; + + L.svgOverlay(this.overlayTarget.querySelector('svg'), bounds).addTo(this._map); + + this._map.fitBounds(bounds); + this._map.setMaxBounds(bounds); + } + + return this._map + } +} diff --git a/app/models/metadata_non_geo.rb b/app/models/metadata_non_geo.rb new file mode 100644 index 00000000..6aec8461 --- /dev/null +++ b/app/models/metadata_non_geo.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +class MetadataNonGeo < MetadataGeo; end diff --git a/app/views/posts/attribute_ro/_non_geo.haml b/app/views/posts/attribute_ro/_non_geo.haml new file mode 100644 index 00000000..75f8d2ef --- /dev/null +++ b/app/views/posts/attribute_ro/_non_geo.haml @@ -0,0 +1,6 @@ +- lat = metadata.value['lat'] +- lng = metadata.value['lng'] +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td + = "#{lat},#{lng}" diff --git a/app/views/posts/attributes/_non_geo.haml b/app/views/posts/attributes/_non_geo.haml new file mode 100644 index 00000000..ad454d96 --- /dev/null +++ b/app/views/posts/attributes/_non_geo.haml @@ -0,0 +1,24 @@ +.row{ data: { controller: 'non-geo', map: "#{site.url}/public/map.svg" } } + .d-none{ hidden: true, data: { target: 'non-geo.overlay' }} + .col + .form-group + = label_tag "#{base}_#{attribute}_lat", + post_label_t(attribute, :lat, post: post) + = text_field(*field_name_for(base, attribute, :lat), + value: metadata.value['lat'], + **field_options(attribute, metadata), + data: { target: 'non-geo.lat' }) + = render 'posts/attribute_feedback', + post: post, attribute: [attribute, :lat], metadata: metadata + .col + .form-group + = label_tag "#{base}_#{attribute}_lng", + post_label_t(attribute, :lng, post: post) + = text_field(*field_name_for(base, attribute, :lng), + value: metadata.value['lng'], + **field_options(attribute, metadata), + data: { target: 'non-geo.lng' }) + = render 'posts/attribute_feedback', + post: post, attribute: [attribute, :lng], metadata: metadata + .col-12.mb-3 + %div{ data: { target: 'non-geo.map' }, style: 'height: 250px' } From c77fb503668c11580f2f920bffa4df9afa5e970f Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 17:38:29 -0300 Subject: [PATCH 02/10] obtener el overlay antes que nada --- app/javascript/controllers/non_geo_controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index 072c1b83..f8b86643 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -14,15 +14,15 @@ export default class extends Controller { static targets = [ 'lat', 'lng', 'map', 'overlay' ] async connect () { + const res = await fetch(this.element.dataset.map); + this.overlayTarget.innerHTML = await res.text(); + this.marker() this.latTarget.addEventListener('change', event => this.marker()) this.lngTarget.addEventListener('change', event => this.marker()) window.addEventListener('resize', event => this.map.invalidateSize()) - const res = await fetch(this.element.dataset.map); - this.overlayTarget.innerHTML = await res.text(); - this.map.on('click', event => { this.latTarget.value = event.latlng.lat this.lngTarget.value = event.latlng.lng From 417559399ac7a727e6375ed4ceed1a11d2f5b923 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 17:52:40 -0300 Subject: [PATCH 03/10] traer archivos subidos localmente --- app/views/posts/attributes/_non_geo.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/posts/attributes/_non_geo.haml b/app/views/posts/attributes/_non_geo.haml index ad454d96..84b1cb00 100644 --- a/app/views/posts/attributes/_non_geo.haml +++ b/app/views/posts/attributes/_non_geo.haml @@ -1,4 +1,4 @@ -.row{ data: { controller: 'non-geo', map: "#{site.url}/public/map.svg" } } +.row{ data: { controller: 'non-geo', map: url_for(site.static_files.blobs.find_by_filename('map.svg').attachments.first) } } .d-none{ hidden: true, data: { target: 'non-geo.overlay' }} .col .form-group From cf5341eec4bba6b42c45bc01d921300b28ad30f3 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 18:20:19 -0300 Subject: [PATCH 04/10] =?UTF-8?q?usar=20el=20tama=C3=B1o=20del=20svg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/non_geo_controller.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index f8b86643..1a7775f2 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -55,13 +55,25 @@ export default class extends Controller { return [this.lat, this.lng] } + get svgOverlay () { + return this.overlayTarget.querySelector('svg'); + } + + get bounds () { + return [ + [0, 0], + [ + this.svgOverlay.viewBox.baseVal.height, + this.svgOverlay.viewBox.baseVal.width, + ] + ]; + } + get map () { if (!this._map) { this._map = L.map(this.mapTarget).setView(this.coords, 13); - const bounds = [[0,0], [this.mapTarget.clientHeight, this.mapTarget.clientWidth]]; - - L.svgOverlay(this.overlayTarget.querySelector('svg'), bounds).addTo(this._map); + L.svgOverlay(this.svgOverlay, this.bounds).addTo(this._map); this._map.fitBounds(bounds); this._map.setMaxBounds(bounds); From c68508f89af6d566ad4063869f7d84615672e2c2 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 18:21:32 -0300 Subject: [PATCH 05/10] usar el sistema de coordenadas simplificado --- app/javascript/controllers/non_geo_controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index 1a7775f2..1da5511a 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -71,7 +71,10 @@ export default class extends Controller { get map () { if (!this._map) { - this._map = L.map(this.mapTarget).setView(this.coords, 13); + this._map = L.map(this.mapTarget, { + crs: L.CRS.Simple, + zoomSnap: 0.1 + }).setView(this.coords, 13); L.svgOverlay(this.svgOverlay, this.bounds).addTo(this._map); From c5c96c8f3cee253e7e327714bd0785d37f509313 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 1 Feb 2022 18:28:27 -0300 Subject: [PATCH 06/10] ajustar al contenido --- app/javascript/controllers/non_geo_controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index 1da5511a..419e3c6a 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -72,11 +72,14 @@ export default class extends Controller { get map () { if (!this._map) { this._map = L.map(this.mapTarget, { + minZoom: -5, crs: L.CRS.Simple, zoomSnap: 0.1 }).setView(this.coords, 13); - L.svgOverlay(this.svgOverlay, this.bounds).addTo(this._map); + const bounds = this.bounds; + + L.svgOverlay(this.svgOverlay, bounds).addTo(this._map); this._map.fitBounds(bounds); this._map.setMaxBounds(bounds); From 05fba76ab81a03e4b4cad0b2c152181c048a4f5c Mon Sep 17 00:00:00 2001 From: f Date: Thu, 10 Feb 2022 19:00:25 -0300 Subject: [PATCH 07/10] usar mosaicos en lugar de svg --- .../controllers/non_geo_controller.js | 22 +++++++------------ app/views/posts/attributes/_non_geo.haml | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index 419e3c6a..965c561e 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -55,10 +55,6 @@ export default class extends Controller { return [this.lat, this.lng] } - get svgOverlay () { - return this.overlayTarget.querySelector('svg'); - } - get bounds () { return [ [0, 0], @@ -72,17 +68,15 @@ export default class extends Controller { get map () { if (!this._map) { this._map = L.map(this.mapTarget, { - minZoom: -5, - crs: L.CRS.Simple, - zoomSnap: 0.1 - }).setView(this.coords, 13); + minZoom: 0, + maxZoom: 5 + }).setView(this.coords, 0); - const bounds = this.bounds; - - L.svgOverlay(this.svgOverlay, bounds).addTo(this._map); - - this._map.fitBounds(bounds); - this._map.setMaxBounds(bounds); + this._layer = L.tileLayer(`${this.element.dataset.site}public/map/{z}/{y}/{x}.png`, { + minNativeZoom: 0, + maxNativeZoom: 5, + noWrap: true + }).addTo(this._map); } return this._map diff --git a/app/views/posts/attributes/_non_geo.haml b/app/views/posts/attributes/_non_geo.haml index 84b1cb00..fd4e85ea 100644 --- a/app/views/posts/attributes/_non_geo.haml +++ b/app/views/posts/attributes/_non_geo.haml @@ -1,4 +1,4 @@ -.row{ data: { controller: 'non-geo', map: url_for(site.static_files.blobs.find_by_filename('map.svg').attachments.first) } } +.row{ data: { controller: 'non-geo', site: site.url } } .d-none{ hidden: true, data: { target: 'non-geo.overlay' }} .col .form-group From 53ce970bb0892f74faa0acb7878c7c34646289f4 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 11 Feb 2022 13:57:53 -0300 Subject: [PATCH 08/10] no intentar descargar el mapa --- app/javascript/controllers/non_geo_controller.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/javascript/controllers/non_geo_controller.js b/app/javascript/controllers/non_geo_controller.js index 965c561e..1c618fcb 100644 --- a/app/javascript/controllers/non_geo_controller.js +++ b/app/javascript/controllers/non_geo_controller.js @@ -14,9 +14,6 @@ export default class extends Controller { static targets = [ 'lat', 'lng', 'map', 'overlay' ] async connect () { - const res = await fetch(this.element.dataset.map); - this.overlayTarget.innerHTML = await res.text(); - this.marker() this.latTarget.addEventListener('change', event => this.marker()) From 437d5ff230f69f4b6b498cb02f041357098fbf03 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 8 Mar 2022 21:54:25 -0300 Subject: [PATCH 09/10] etiquetas --- app/views/posts/attributes/_geo.haml | 4 ++++ app/views/posts/attributes/_non_geo.haml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/views/posts/attributes/_geo.haml b/app/views/posts/attributes/_geo.haml index d048565e..4ed7a395 100644 --- a/app/views/posts/attributes/_geo.haml +++ b/app/views/posts/attributes/_geo.haml @@ -1,4 +1,8 @@ .row{ data: { controller: 'geo' } } + .col-12 + %p= post_label_t(attribute, post: post) + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata .col .form-group = label_tag "#{base}_#{attribute}_lat", diff --git a/app/views/posts/attributes/_non_geo.haml b/app/views/posts/attributes/_non_geo.haml index fd4e85ea..a5a7ea12 100644 --- a/app/views/posts/attributes/_non_geo.haml +++ b/app/views/posts/attributes/_non_geo.haml @@ -1,5 +1,9 @@ .row{ data: { controller: 'non-geo', site: site.url } } .d-none{ hidden: true, data: { target: 'non-geo.overlay' }} + .col-12 + %p= post_label_t(attribute, post: post) + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata .col .form-group = label_tag "#{base}_#{attribute}_lat", From 6801d5655bf36d9e84025ff37f5f8f52f63752c0 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 8 Mar 2022 21:56:41 -0300 Subject: [PATCH 10/10] mejorar estilo --- app/views/posts/attributes/_geo.haml | 4 ++-- app/views/posts/attributes/_non_geo.haml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/posts/attributes/_geo.haml b/app/views/posts/attributes/_geo.haml index 4ed7a395..dee4707e 100644 --- a/app/views/posts/attributes/_geo.haml +++ b/app/views/posts/attributes/_geo.haml @@ -1,6 +1,6 @@ .row{ data: { controller: 'geo' } } - .col-12 - %p= post_label_t(attribute, post: post) + .col-12.mb-3 + %p.mb-0= post_label_t(attribute, post: post) = render 'posts/attribute_feedback', post: post, attribute: attribute, metadata: metadata .col diff --git a/app/views/posts/attributes/_non_geo.haml b/app/views/posts/attributes/_non_geo.haml index a5a7ea12..3f6a75a6 100644 --- a/app/views/posts/attributes/_non_geo.haml +++ b/app/views/posts/attributes/_non_geo.haml @@ -1,6 +1,7 @@ .row{ data: { controller: 'non-geo', site: site.url } } .d-none{ hidden: true, data: { target: 'non-geo.overlay' }} - .col-12 + .col-12.mb-3 + %p.mb-0= post_label_t(attribute, post: post) %p= post_label_t(attribute, post: post) = render 'posts/attribute_feedback', post: post, attribute: attribute, metadata: metadata