standard.js rulez

This commit is contained in:
boyska 2020-02-16 01:07:20 +01:00
parent a248cb92f8
commit 94a4f0a273
2 changed files with 105 additions and 112 deletions

View file

@ -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()
})

View file

@ -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('<div class="explaination"></div><div class="actions"></div>')
$('#dialog .explaination').text(data.explaination)
$('#dialog .actions').html('<button class="btn-elimina">Elimina</button>')
$('#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 = '<div id="dialog"></div>'
}
})
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('<div class="explaination"></div><div class="actions"></div>')
$('#dialog .explaination').text(data.explaination)
$('#dialog .actions').html('<button class="btn-elimina">Elimina</button>')
$('#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 = '<div id="dialog"></div>'
}
})
}
$('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()
})