CodeforLeipzig/stadtratmonitor

View on GitHub
app/assets/javascripts/geo.js

Summary

Maintainability
F
6 days
Test Coverage
function geojsonDaten() {
  return {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Mitte",
          "raum": "Stadtbüro",
          "ort": "Burgplatz 1, 04109 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2350"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3727021,
            51.3370619
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Nordost",
          "raum": "KulturGut Schloss Schönefeld",
          "ort": "Zeumerstraße 1, 04347 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2284"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.407042064270335,
            51.35905225
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Ost",
          "raum": "BSZ 7 - Außenstelle",
          "ort": "Neustädter Straße 1, 04315 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2295"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.399940740484912,
            51.344629850000004
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Südost",
          "raum": "Franz-Mehring-Schule",
          "ort": "Gletschersteinstraße 9, 04299 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2324"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.425064636414,
            51.3165416
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Süd",
          "raum": "Immanuel-Kant-Gymnasium, Zi. 408",
          "ort": "Scharnhorststraße 15, 04275 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2369"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3724315691414,
            51.3199336
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Südwest",
          "raum": "Schule am Grünen Gleis",
          "ort": "Baumannstraße 13, 04229 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2309"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.323566707065215,
            51.3176798
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat West",
          "raum": "Freizeittreff \"Völkerfreundschaft\", Großer Saal",
          "ort": "Stuttgarter Allee 9, 04209 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2282"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.2915533009981,
            51.3156583
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Alt-West",
          "raum": "Rathaus Leutzsch, Beratungsraum 1. Etage",
          "ort": "Georg-Schwarz-Straße 140, 04179 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2271"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3138069902423,
            51.34783805
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Nordwest",
          "raum": "Stadtteilzentrum \"ANKER\"",
          "ort": "Renftstraße 1, 04159 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2250"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3430596,
            51.3675295
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Stadtbezirksbeirat Nord",
          "raum": "Kulturhof Gohlis, Kultursaal",
          "ort": "Eisenacher Straße 72, 04155 Leipzig",
          "typ": "Stadtbezirksbeirat",
          "id": "2272"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3592316,
            51.3623363
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Böhlitz-Ehrenberg",
          "raum": "Große Eiche, Salon Böhlitz",
          "ort": "Leipziger Straße 81, 04178 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2261"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.2907928,
            51.3595433
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Burghausen",
          "raum": "ehem. Gemeindeamt Burghausen, Sitzungszimmer",
          "ort": "Miltitzer Straße 1, 04178 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2259"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.2649439543724,
            51.35492225
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Engelsdorf",
          "raum": "Versammlungsraum des Ortschaftsrates Engelsdorf",
          "ort": "Engelsdorfer Str. 345, 04319 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2336"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.4901256,
            51.3390546
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Hartmannsdorf-Knautnaundorf",
          "raum": "ehem. Gemeindeamt Knautnaundorf",
          "ort": "Schkorlopper Straße 34, 04249 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2283"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.26865655,
            51.25494705
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Holzhausen",
          "raum": "Schule Holzhausen, Aula",
          "ort": "Stötteritzer Landstraße 21, 04288 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2262"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.4658203,
            51.3049215
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Liebertwolkwitz",
          "raum": "Rathaus Liebertwolkwitz, Zi. 2",
          "ort": "Liebertwolkwitzer Markt 1, 04288 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2330"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.4642926352189,
            51.28270915
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Lindenthal",
          "raum": "Rathaus Lindenthal, Ratssaal",
          "ort": "Erich-Thiele-Str. 2, 04159 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2316"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.327974438667297,
            51.392381000768204
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Lützschena-Stahmeln",
          "raum": "Leipziger Hotel",
          "ort": "Hallesche Straße 190, 04159 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2368"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.2710945,
            51.3853193
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Miltitz",
          "raum": "Heimatverein Miltitz",
          "ort": "An der alten Post 1, 04205 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2365"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.25400846230211,
            51.32507435
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Mölkau",
          "raum": "ehem. Gemeindeamt Mölkau, Ratssaal",
          "ort": "Engelsdorfer Straße 90, 04316 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2255"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.441776,
            51.3310749
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Plaußig ",
          "raum": "Freiwillige Feuerwehr Plaußig - Schulungsraum",
          "ort": "Plaußiger Dorfstraße 23, 04349 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2377"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.4557221,
            51.3922605
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Rückmarsdorf ",
          "raum": "Ortsteilzentrum Rückmarsdorf",
          "ort": "Ehrenberger Straße 5a, 04178 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2276"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.2784925298815,
            51.34322465
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Seehausen",
          "raum": "Hort der Grundschule Seehausen",
          "ort": "Seehausener Allee 15, 04356 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2312"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.411255135155008,
            51.40299085
          ]
        }
      },
      {
        "type": "Feature",
        "properties": {
          "name": "Ortschaftsrat Wiederitzsch",
          "raum": "Rathaus Wiederitzsch, Rathaussaal",
          "ort": "Delitzscher Landstraße 55, 04158 Leipzig",
          "typ": "Ortschaftsrat",
          "id": "2304"
        },
        "geometry": {
          "type": "Point",
          "coordinates": [
            12.3737383807901,
            51.3935912
          ]
        }
      }
    ]
  }
}

var locked = null
var popUp;

var hoverToMarkerOffset = function (currentZoomLevel) {
  return 0.39 / Math.pow(2, currentZoomLevel - 6);
};

var registerListeners = function (map, geojsonLayer) {

  geojsonLayer.on('mouseover', function (event) {
    var coords = event.layer.feature.geometry.coordinates;
    if (map && (coords != locked)) {
      hidePopUp(map);
      showPopUp(map, event);
      locked = coords;
    }
  });

  geojsonLayer.on('click', function (event) {
    if (popUp && map) {
      var coords = event.layer.feature.geometry.coordinates;
      if (locked == coords) {
        locked = null;
      } else {
        showPopUp(map, event);
        locked = coords;
      }
    }
  });
}

function showPopUp(map, event) {
  var coords = event.layer.feature.geometry.coordinates;
  var popUpCoords = [coords[1] + hoverToMarkerOffset(map.getZoom()), coords[0]];
  var properties = event.layer.feature.properties
  popUp = L.popup()
    .setLatLng(popUpCoords)
    .setContent(createPopUpContent(properties))
    .openOn(map);
}

function hidePopUp(map) {
  map.closePopup(popUp);
  popUp = null;
}

function createPopUpContent(properties) {
  var content = "<b>" + properties.name + "</b>";
  content += "<br />";
  content += "<span style=\"text-decoration: underline;\">Adresse:</span> "
  content += properties.ort
  content += "<br />"
  content += "<span style=\"text-decoration: underline;\">Raum:</span> "
  content += properties.raum
  content += "<ul>"
  content += "<li><a href=\"https://ratsinformation.leipzig.de/allris_leipzig_public/gr020?GRLFDNR=" + properties.id + "\">Mitglieder</a></li>"
  content += "<li><a href=\"https://ratsinformation.leipzig.de/allris_leipzig_public/si018?GRLFDNR=" + properties.id + "\">Sitzungen</a></li>"
  content += "</ul>"
  return content
}