From 94a4f0a2735f5297d6e10b36dfad421f42803588 Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 16 Feb 2020 01:07:20 +0100 Subject: [PATCH] standard.js rulez --- static/js/addmap.js | 116 ++++++++++++++++++++----------------------- static/js/viewmap.js | 101 ++++++++++++++++++------------------- 2 files changed, 105 insertions(+), 112 deletions(-) diff --git a/static/js/addmap.js b/static/js/addmap.js index 8631db9..b7cb446 100644 --- a/static/js/addmap.js +++ b/static/js/addmap.js @@ -1,69 +1,61 @@ -function viewMap() { - var map = L.map('mapid').setView([43.797, 11.2400], 11); - // Set up the OSM layer - L.tileLayer( -'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' - ).addTo(map); +/* globals $, jQuery, L */ +function viewMap () { + var map = L.map('mapid').setView([43.797, 11.2400], 11) + // Set up the OSM layer + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map) - $.getJSON('/api/rapporti/get', function(data) { - for(var i in data.rapporti) { - var p = data.rapporti[i] - L.circle([p.lat, p.lng], { - color: p.colore, - fillColor:p.colore, - fillOpacity: 0.2, - opacity: 0.7, - radius: p.radius, - }).addTo(map) - } + $.getJSON('/api/rapporti/get', function (data) { + for (var i in data.rapporti) { + var p = data.rapporti[i] + L.circle([p.lat, p.lng], { + color: p.colore, + fillColor: p.colore, + fillOpacity: 0.2, + opacity: 0.7, + radius: p.radius + }).addTo(map) + } + }) + + function addPointToDb (dati) { + $.post('/api/rapporti/add', dati + , function (p) { + L.circle([p.lat, p.lng], { + color: p.colore, + fillColor: p.colore, + fillOpacity: 0.5, + radius: p.radius + }).addTo(map) + }) + } + + function onFormSubmit () { + addPointToDb({ + lat: $('#pointform input[name=lat]').val(), + lng: $('#pointform input[name=lng]').val(), + stabilita: $('#pointform select[name=stabilita]').val(), + comprensibile: $('#pointform select[name=comprensibile]').val() }) + $('#pointform').addClass('hidden') + return false + } - function addPointToDb(dati) { - $.post('/api/rapporti/add', dati - , function(p) { - console.log(p) - L.circle([p.lat, p.lng], { - color: p.colore, - fillColor:p.colore, - fillOpacity: 0.5, - radius: p.radius, - }).addTo(map) - }) + function onMapClick (e) { + var stabilita = 3 + if (map.getZoom() > 15) { + stabilita = 19 - map.getZoom() } + $('#pointform input[name=lat]').val(e.latlng.lat) + $('#pointform input[name=lng]').val(e.latlng.lng) + $('#pointform select[name=stabilita]').val(stabilita) + $('#pointform').removeClass('hidden') + // TODO: aggiungi punto temporaneo, ma poi va rimosso + } - function onFormSubmit() { - addPointToDb({ - lat: $('#pointform input[name=lat]').val(), - lng: $('#pointform input[name=lng]').val(), - stabilita: $('#pointform select[name=stabilita]').val(), - comprensibile: $('#pointform select[name=comprensibile]').val(), - }) - $('#pointform').addClass('hidden') - return false; - } - - function onMapClick(e) { - console.log('click', e) - console.log(e.latlng) - var stabilita = 3 - console.log(map.getZoom()) - if(map.getZoom() > 15) { - stabilita = 19 - map.getZoom() - } - console.log('st', stabilita) - $('#pointform input[name=lat]').val(e.latlng.lat) - $('#pointform input[name=lng]').val(e.latlng.lng) - $('#pointform select[name=stabilita]').val(stabilita) - $('#pointform').removeClass('hidden') - // TODO: aggiungi punto temporaneo, ma poi va rimosso - - } - - map.on('click', onMapClick) - $('#addPoint').on('click', onFormSubmit) + map.on('click', onMapClick) + $('#addPoint').on('click', onFormSubmit) } -jQuery(function($) { - $('#mapid').css('height', $(window).height() - 200) - viewMap() +jQuery(function ($) { + $('#mapid').css('height', $(window).height() - 200) + viewMap() }) - diff --git a/static/js/viewmap.js b/static/js/viewmap.js index 64816a0..c3c838a 100644 --- a/static/js/viewmap.js +++ b/static/js/viewmap.js @@ -1,55 +1,56 @@ -RapportoMarker = L.Circle.extend({ options: { originalData: 0 } }); +/* globals $, jQuery, L */ +var RapportoMarker = L.Circle.extend({ options: { originalData: 0 } }) -function viewMap() { - var map = L.map('mapid').setView([43.797, 11.2400], 11); - // Set up the OSM layer - L.tileLayer( -'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' - ).addTo(map); - $.getJSON('/api/rapporti/get', function(data) { - for(var i in data.rapporti) { - var p = data.rapporti[i] - var marker = new RapportoMarker([p.lat, p.lng], { - color: p.colore, - fillColor:p.colore, - fillOpacity: 0.3, - radius: p.radius, - originalData: p, - }) - marker.addTo(map).bindPopup(p.explaination) - marker.off('click') - marker.on('click', onMarkerClicked) - } - }) - function onMarkerClicked(evt) { - console.log('T', this) - var data = evt.target.options.originalData - var rid = data.rid - $('#dialog').html('
') - $('#dialog .explaination').text(data.explaination) - $('#dialog .actions').html('') - $('#dialog').attr('title', rid) - $('#dialog').data('rid', rid) - $('#dialog').data('marker', this) - $('#dialog').dialog({ - modal: true, - beforeClose: function(event, ui) { - $('#dialog').dialog('destroy') - $('#dialog')[0].outerHTML = '
' - } - }) +function viewMap () { + var map = L.map('mapid').setView([43.797, 11.2400], 11) + // Set up the OSM layer + L.tileLayer( + 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' + ).addTo(map) + $.getJSON('/api/rapporti/get', function (data) { + for (var i in data.rapporti) { + var p = data.rapporti[i] + var marker = new RapportoMarker([p.lat, p.lng], { + color: p.colore, + fillColor: p.colore, + fillOpacity: 0.3, + radius: p.radius, + originalData: p + }) + marker.addTo(map).bindPopup(p.explaination) + marker.off('click') + marker.on('click', onMarkerClicked) } - - $('body').on('click', '.btn-elimina', function onCancella(evt) { - var rid = $('#dialog').data('rid') - console.log('cancelliamo?', rid) - $.post('/api/rapporti/delete', {rid: rid}, function() { - map.removeLayer($('#dialog').data('marker')) - $('#dialog').dialog('close') - }) + }) + function onMarkerClicked (evt) { + console.log('T', this) + var data = evt.target.options.originalData + var rid = data.rid + $('#dialog').html('
') + $('#dialog .explaination').text(data.explaination) + $('#dialog .actions').html('') + $('#dialog').attr('title', rid) + $('#dialog').data('rid', rid) + $('#dialog').data('marker', this) + $('#dialog').dialog({ + modal: true, + beforeClose: function (event, ui) { + $('#dialog').dialog('destroy') + $('#dialog')[0].outerHTML = '
' + } }) + } + + $('body').on('click', '.btn-elimina', function onCancella (evt) { + var rid = $('#dialog').data('rid') + console.log('cancelliamo?', rid) + $.post('/api/rapporti/delete', { rid: rid }, function () { + map.removeLayer($('#dialog').data('marker')) + $('#dialog').dialog('close') + }) + }) } -jQuery(function($) { - $('#mapid').css('height', $(window).height() - 200) - viewMap() +jQuery(function ($) { + $('#mapid').css('height', $(window).height() - 200) + viewMap() })