Skip to content

Commit

Permalink
updated marker icons with new webp files
Browse files Browse the repository at this point in the history
  • Loading branch information
p3t3r67x0 committed Feb 7, 2024
1 parent 6aefa79 commit e85e852
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import markerDefault from 'url:../static/marker-icon-default.webp'
import markerSelected from 'url:../static/marker-icon-active.webp'



fetch(kitas, {
method: 'GET'
}).then((response) => response.json()).then((data) => {
Expand All @@ -32,26 +31,12 @@ fetch(districts, {


const layerStyle = {
transparent: {
color: 'transparent',
fillColor: 'transparent',
fillOpacity: 0.7,
opacity: 0.6,
weight: 1
},
standard: {
color: '#fff',
fillColor: '#11aa44',
fillOpacity: 0.4,
opacity: 0.6,
weight: 3
},
click: {
color: '#fff',
fillColor: '#002db4',
fillOpacity: 0.4,
opacity: 0.8,
weight: 4
}
}

Expand All @@ -71,6 +56,7 @@ L.tileLayer.wms('https://sgx.geodatenzentrum.de/wms_basemapde?SERVICE=WMS&Reques

let geocoder = L.Control.Geocoder.nominatim()
let previousSelectedMarker = null
let slugUrlActive = null


if (typeof URLSearchParams !== 'undefined' && location.search) {
Expand Down Expand Up @@ -108,7 +94,15 @@ function addDistrictsLayer(data) {
}


function capitalizeEachWord(str) {
return str.replace(/-/g, ' ').replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
})
}


function renderFeatureDetails(feature) {
const slug = feature.properties.slug
const district = feature.properties.district
const address = feature.properties.address
const postal_code = feature.properties.postal_code
Expand All @@ -129,6 +123,12 @@ function renderFeatureDetails(feature) {
const lunch_offer = feature.properties.lunch_offer
const comments = feature.properties.comments

const title = `${capitalizeEachWord(slug)} - Schulen in Flensburg`

document.querySelector('title').innerHTML = title
document.querySelector('meta[property="og:title"]').setAttribute('content', title)
document.querySelector('meta[property="og:url"]').setAttribute('content', `${window.location.href}${slug}`)

let detailOutput = ''

if (facility !== '') {
Expand Down Expand Up @@ -203,15 +203,15 @@ const defaultIcon = L.icon({
iconUrl: markerDefault,
iconSize: [25, 35],
iconAnchor: [12, 35],
tooltipAnchor: [0, -35]
tooltipAnchor: [1, -36]
})


const selectedIcon = L.icon({
iconUrl: markerSelected,
iconSize: [25, 35],
iconAnchor: [12, 35],
tooltipAnchor: [0, -35]
tooltipAnchor: [1, -36]
})


Expand All @@ -223,6 +223,18 @@ function marker(data) {

const geojsonGroup = L.geoJSON(data, {
onEachFeature(feature, layer) {
const slug = String(feature.properties.slug)
const path = decodeURIComponent(window.location.pathname)

if (slug === path.slice(1)) {
document.querySelector('#about').classList.add('hidden')
layer.setIcon(selectedIcon)
previousSelectedMarker = layer
renderFeatureDetails(feature)
map.setView(layer._latlng, 18)
slugUrlActive = true
}

layer.on('click', function (e) {
document.getElementById('filter').scrollTo({
top: 0,
Expand All @@ -234,11 +246,11 @@ function marker(data) {
if (currentZoom < 15) {
map.setView(e.latlng, 15)
}
else {
map.setView(e.latlng, currentZoom)
}

document.querySelector('#about').classList.add('hidden')
map.setView(e.latlng, 18)
renderFeatureDetails(e.target.feature)
history.pushState({ page: slug }, slug, slug)
})
},
pointToLayer(feature, latlng) {
Expand All @@ -263,4 +275,8 @@ function marker(data) {

markers.addLayer(geojsonGroup)
map.addLayer(markers)
}
}

window.addEventListener('popstate', (event) => {
console.debug(`location: ${document.location}, state: ${JSON.stringify(event.state)}`)
})
Binary file modified static/marker-icon-active.webp
Binary file not shown.
Binary file modified static/marker-icon-default.webp
Binary file not shown.

0 comments on commit e85e852

Please sign in to comment.