Skip to content

Commit

Permalink
Add enable_time_slider toogle to Map model. Improving visual feedback…
Browse files Browse the repository at this point in the history
…, embedding numbers per year, switch for showing all places... (refs #301)
  • Loading branch information
ut committed Jun 13, 2024
1 parent a4af1ec commit 2388f4a
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 191 deletions.
136 changes: 7 additions & 129 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -338,122 +338,24 @@ jQuery(function ($) {
userZoomLevel(map);
userMapBounds(map);

var custom_base_layer;
var custom_basemap_url;
var custom_basemap_attribution;
var custom_background_color;
var Esri_WorldImagery_layer = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri <span class="show-for-large">&mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community</a>',
minZoom: 0,
maxZoom: 18

});
var Openstreetmap_layer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 21,
attribution: 'OpenStreetMap + its contributors, CC-BY-SA'
});
var wmsLayerHamburg1925s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1925-1930'
});
var wmsLayerHamburg1930s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1930-1940'
});
var wmsLayerHamburg1980s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1980-1990'
});
var custom_background_color;



if ( $('#selection').data('map-background-color') ) {
custom_background_color = $('#selection').data('map-background-color');
$('#map').css('background', custom_background_color);
}
if ( $('#selection').data('map-basemap-url') ) {
custom_basemap_url = $('#selection').data('map-basemap-url');

if ( $('#selection').data('map-basemap-attribution') ) {
custom_basemap_attribution = $('#selection').data('map-basemap-attribution');
}
custom_base_layer = L.tileLayer(custom_basemap_url, {
attribution: custom_basemap_attribution,
minZoom: 0,
maxZoom: 21
});
var basemaps = {
Custom: custom_base_layer,
Satellite: Esri_WorldImagery_layer,
Openstreetmap: Openstreetmap_layer,
}
if ( $('#selection').data('map-enable-historical-maps') === true ) {
console.log("HISTORICAL MAPS enabled");
basemaps["Historical HH 1925-1930"] = wmsLayerHamburg1925s;
basemaps["Historical HH 1930-1940"] = wmsLayerHamburg1930s;
basemaps["Historical HH 1980-1990"] = wmsLayerHamburg1980s;
}

// TODO: reset baselayer if custom was set or changed server-side

if ( localStorage.baselayer == 'Openstreetmap') {
$('#map').addClass('darken-icons');
$('#map').addClass('darken-icons2');
$('#timeline-wrapper').addClass('dark');
Openstreetmap_layer.addTo(map);
} else if ( localStorage.baselayer == 'Satellite') {
Esri_WorldImagery_layer.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1925-1930') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1925s.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1930-1940') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1930s.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1980-1990') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1980s.addTo(map);
} else {
custom_base_layer.addTo(map);
}

if ( $('#selection').data('map-marker-display-mode') === 'zigzag cluster, w/gradient' ) {
$('#map').addClass('gradient-icons')
}


} else {
console.log("No custom base layer defined");
if ( localStorage.baselayer == 'Openstreetmap') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
Openstreetmap_layer.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1925-1930') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1925s.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1930-1940') {
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1930s.addTo(map);
} else {
Esri_WorldImagery_layer.addTo(map);
}
<% if ( Rails.env != 'test' && Rails.application.credentials.token ) %>
let access_token = "<%= Rails.application.credentials.token[:mapbox] %>"
L.tileLayer("https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}@2x.jpg90?access_token="+access_token, {
attribution: "&copy; <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> Contributors",
minZoom: 19,
maxZoom: 21}).addTo(map);
<% end %>
var basemaps = {
"Satellite": Esri_WorldImagery_layer,
"Openstreetmap": Openstreetmap_layer,
};
if ( $('#selection').data('map-enable-historical-maps') === true ) {
console.log("HISTORICAL MAPS enabled");
basemaps["Historical HH 1925-1930"] = wmsLayerHamburg1925s;
basemaps["Historical HH 1930-1940"] = wmsLayerHamburg1930s;
basemaps["Historical HH 1980-1990"] = wmsLayerHamburg1980s;
}
}
}
BaseMapLayerChange(map,overlays,'setup');

console.log("Check Overlay settings")
if ( localStorage.overlayPlaces == 'true' ) {
Expand All @@ -474,32 +376,8 @@ jQuery(function ($) {
}
map.on('baselayerchange', function(e){
console.log("Baselayer change to " + e.name);
if ( e.name == 'Openstreetmap') {
$('#map').addClass('darken-icons')
$('#map').addClass('darken-icons2')
$('#timeline-wrapper').addClass('dark');
} else if ( localStorage.baselayer == 'Historical HH 1925-1930') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1925s.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1930-1940') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1930s.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1980-1980') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons')
$('#timeline-wrapper').addClass('dark');
wmsLayerHamburg1980s.addTo(map);
} else {
$('#map').removeClass('darken-icons');
$('#map').removeClass('darken-icons2');
$('#map').removeClass('darken-label');
$('#timeline-wrapper').removeClass('dark');
}
localStorage.baselayer = e.name;
BaseMapLayerChange(map,overlays,'update');
})
map.on('overlayadd', function(e){
console.log("Overlay added");
Expand Down Expand Up @@ -538,7 +416,7 @@ jQuery(function ($) {
}
}
});
L.control.layers(basemaps,overlays,{position: 'topright'}).addTo(map);


if ( $('#selection').data('layer-id') ) {
// localStorage.setItem('Layer',$('#selection').data('layer-id'));
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/graphics/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ var LargeMarkerIcon = {
}
}),
iconSVG: function(params) {
console.log("PARAMS",params);
// console.log("PARAMS",params);
var svg = `<svg height="${params.marker_size}" width="${params.marker_size}" xmlns="http://www.w3.org/2000/svg">${params.defs_with_gradient}<circle class="cls-1" cx="${params.marker_size/2}" cy="${params.marker_size/2}" r="${params.marker_size/2}" fill="${params.color}" fill-opacity="${params.opacity}" stroke="${params.stroke}" stroke-width="${params.stroke_width}" stroke-opacity="${params.stroke_opacity}" shape-rendering="geometricPrecision"></circle></svg>`;
return encodeURI("data:image/svg+xml," + svg).replace(new RegExp('#', 'g'),'%23');
},
create: function(params) {
var defaultParams = {marker_size: 30, color: "black", opacity: 0.7, stroke: "transparent", stroke_width: 0, stroke_opacity: 0, defs_with_gradient: ""};
params = Object.assign({}, defaultParams, params);
console.log("PARAMS",params);
// console.log("PARAMS",params);
return new this.CustomLargeIcon({iconUrl: this.iconSVG(params)});
}

Expand Down
141 changes: 141 additions & 0 deletions app/assets/javascripts/helpers/basemap_layer_change.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@



function BaseMapLayerChange(map,overlays,action) {
var custom_base_layer;
var custom_basemap_url;
var custom_basemap_attribution;
var Esri_WorldImagery_layer = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri <span class="show-for-large">&mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community</a>',
minZoom: 0,
maxZoom: 18
});
var Openstreetmap_layer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 21,
attribution: 'OpenStreetMap + its contributors, CC-BY-SA'
});
var wmsLayerHamburg1925s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1925-1930',
attribution: 'Landesbetriebs Geoinformation und Vermessung (LGV) Hamburg, Datenlizenz Deutschland Namensnennung 2.0'
});
var wmsLayerHamburg1930s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1930-1940',
attribution: 'Landesbetriebs Geoinformation und Vermessung (LGV) Hamburg, Datenlizenz Deutschland Namensnennung 2.0'
});
var wmsLayerHamburg1980s = L.tileLayer.wms('https://geodienste.hamburg.de/HH_WMS_Historische_Karte_1_5000?', {
layers: 'jahrgang_1980-1990',
transparent: true,
attribution: 'Landesbetriebs Geoinformation und Vermessung (LGV) Hamburg, Datenlizenz Deutschland Namensnennung 2.0'
});
if ( $('#selection').data('map-basemap-url') ) {
console.log("Custom base layer defined");
custom_basemap_url = $('#selection').data('map-basemap-url');
if ( $('#selection').data('map-basemap-attribution') ) {
custom_basemap_attribution = $('#selection').data('map-basemap-attribution');
}
custom_base_layer = L.tileLayer(custom_basemap_url, {
attribution: custom_basemap_attribution,
minZoom: 0,
maxZoom: 21
});
}

if ( action === 'setup') {
if ( $('#selection').data('map-basemap-url') ) {
var basemaps = {
Custom: custom_base_layer,
Satellite: Esri_WorldImagery_layer,
Openstreetmap: Openstreetmap_layer,
}
} else {
console.log("No custom base layer defined");
<% if Rails.env != "test" && Rails.application.credentials.token %>
let access_token = "<%= Rails.application.credentials.token[:mapbox] %>"
L.tileLayer("https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}@2x.jpg90?access_token="+access_token, {
attribution: "&copy; <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> Contributors",
minZoom: 19,
maxZoom: 21}).addTo(map);
<% end %>
var basemaps = {
"Satellite": Esri_WorldImagery_layer,
"Openstreetmap": Openstreetmap_layer,
};

}
if ( $('#selection').data('map-enable-historical-maps') === true ) {
console.log("HISTORICAL MAPS enabled");
basemaps["Historical HH 1925-1930"] = wmsLayerHamburg1925s;
basemaps["Historical HH 1930-1940"] = wmsLayerHamburg1930s;
basemaps["Historical HH 1980-1990"] = wmsLayerHamburg1980s;
}
}


if ( localStorage.baselayer == 'Openstreetmap') {
Openstreetmap_layer.addTo(map);
} else if ( localStorage.baselayer == 'Satellite') {
Esri_WorldImagery_layer.addTo(map);
} else if ( localStorage.baselayer == 'Historical HH 1925-1930') {
wmsLayerHamburg1925s.addTo(map);
MapboundsToHamburg(map);
} else if ( localStorage.baselayer == 'Historical HH 1930-1940') {
wmsLayerHamburg1930s.addTo(map);
MapboundsToHamburg(map);
} else if ( localStorage.baselayer == 'Historical HH 1980-1990') {
wmsLayerHamburg1980s.addTo(map);
MapboundsToHamburg(map);
} else {
console.log("custom_base_layer",custom_base_layer)
map.removeLayer(Openstreetmap_layer);
map.removeLayer(Esri_WorldImagery_layer);
map.removeLayer(wmsLayerHamburg1925s);
map.removeLayer(wmsLayerHamburg1930s);
map.removeLayer(wmsLayerHamburg1980s);
custom_base_layer.addTo(map);
if (custom_base_layer) {
custom_base_layer.addTo(map);
}
}



// delete any class of $('#timeline-wrapper')
$('#timeline-wrapper').removeClass();

if ( localStorage.baselayer == 'Openstreetmap') {
$('#map').addClass('darken-icons');
$('#map').addClass('darken-icons2');
$('#timeline-wrapper').addClass('light');
} else if ( localStorage.baselayer == 'Historical HH 1925-1930') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons');
$('#timeline-wrapper').addClass('dark');
} else if ( localStorage.baselayer == 'Historical HH 1930-1940') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons');
$('#timeline-wrapper').addClass('dark');
} else if ( localStorage.baselayer == 'Historical HH 1980-1990') {
// $('#map').addClass('darken-icons darken-label')
$('#map').addClass('darken-icons');
$('#timeline-wrapper').addClass('dark');
} else {
$('#map').removeClass('darken-icons');
$('#map').removeClass('darken-icons2');
$('#map').removeClass('darken-label');
}

L.control.layers(basemaps,overlays,{position: 'topright'}).addTo(map);
}

function MapboundsToHamburg(map){
var minx = 9.721052;
var miny = 53.423000;
var maxx = 10.270569;
var maxy = 53.697028;

var centerLat = (miny + maxy) / 2.0002;
//* very quirky padding hack *//
var centerLng = (minx + maxx) / 2.015;

map.flyTo([centerLat, centerLng], 12);
}
Loading

0 comments on commit 2388f4a

Please sign in to comment.