     visible_layers[0].setOpacity 1 - state.layer_b_opacity
     visible_layers[1].setOpacity state.layer_b_opacity
     current_state.visible_layers = visible_layers
+    if current_state.year != year
+        current_state.year = year
+        year_changed = true
+    else
+        year_changed = false
 
     update_years state
 

    $("#year_b").html orto_years[state.layer_a_idx + 1]
    $("#year_a").css {opacity: 1 - state.layer_b_opacity}
    $("#year_b").css {opacity: state.layer_b_opacity}

    # Set visibility flags on all layers and hide the non-visible layers.
    for al in orto_layers

        opacity: 1.0
        fillOpacity: 0.4
    year = parseInt feat.properties.valmvuosi
    if current_state.year and year > current_state.year
        ret.opacity = 0
        ret.fillOpacity = 0
    if not year or year == 9999
        color = '#eee'
    else
        start_year = 1890
        end_year = new Date().getFullYear()
        if year < start_year
            year = start_year
        n = Math.floor (year - start_year) * colors.length / (end_year - start_year)
        n = colors.length - n - 1
        color = colors[n]
    ret.color = color
    return ret

building_layer = null

window.show_buildings = false

map.on 'moveend', ->
    if map.getZoom() < 16 or not window.show_buildings
        if building_layer
            map.removeLayer building_layer
            building_layer = null
        return
    str = map.getBounds().toBBoxString() + ',EPSG:4326'
    get_wfs 'hel:rakennukset',
        maxFeatures: 500
        bbox: str
        propertyName: 'valmvuosi,osoite,wkb_geometry_s2'
        , (data) ->
            if building_layer
                map.removeLayer building_layer
            building_layer = L.geoJson data,
                style: building_styler
                onEachFeature: (feat, layer) ->
                    year = feat.properties.valmvuosi
                    address = feat.properties.osoite
                    layer.bindPopup "<b>Valm.vuosi #{year}</b><br/>#{address}"
            building_layer.addTo map
