1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /* 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)
- }
- })
- 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(),
- tiporadio:$('#pointform select[name=tiporadio]').val(),
- comprensibile: $('#pointform select[name=comprensibile]').val()
- })
- $('#pointform').addClass('hidden')
- return false
- }
- 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
- }
- map.on('click', onMapClick)
- $('#addPoint').on('click', onFormSubmit)
- }
- jQuery(function ($) {
- $('#mapid').css('height', $(window).height() - 200)
- viewMap()
- })
|