2014-08-15 23:46:04 +04:00
|
|
|
(function($, OC) {
|
2017-08-23 14:51:37 +03:00
|
|
|
$(function() {
|
2017-08-24 13:28:00 +03:00
|
|
|
mapController.initMap();
|
2019-03-28 16:51:24 +03:00
|
|
|
mapController.map.favoritesController = favoritesController;
|
2019-03-27 20:04:04 +03:00
|
|
|
favoritesController.initFavorites(mapController.map);
|
2019-03-27 22:03:14 +03:00
|
|
|
favoritesController.getFavorites();
|
2019-04-03 05:14:10 +03:00
|
|
|
routingController.initRoutingControl(mapController.map);
|
2019-03-26 19:26:29 +03:00
|
|
|
photosController.initLayer(mapController.map);
|
2019-03-26 21:27:58 +03:00
|
|
|
|
|
|
|
// once controllers have been set/initialized, we can restore option values from server
|
2019-03-26 20:59:11 +03:00
|
|
|
optionsController.restoreOptions();
|
2014-08-10 23:33:43 +04:00
|
|
|
|
2017-08-24 19:58:36 +03:00
|
|
|
// Popup
|
|
|
|
$(document).on('click', '#opening-hours-header', function() {
|
|
|
|
$('#opening-hours-table').toggle();
|
|
|
|
$('#opening-hours-table-toggle-expand').toggle();
|
|
|
|
$('#opening-hours-table-toggle-collapse').toggle();
|
|
|
|
});
|
|
|
|
|
2017-08-24 13:28:00 +03:00
|
|
|
// Search
|
|
|
|
$('#search-form').submit(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
submitSearchForm();
|
2017-08-23 14:51:37 +03:00
|
|
|
});
|
2017-08-24 13:28:00 +03:00
|
|
|
$('#search-submit').click(function() {
|
|
|
|
submitSearchForm();
|
2017-08-23 14:51:37 +03:00
|
|
|
});
|
2017-08-23 16:39:28 +03:00
|
|
|
|
2017-08-24 13:28:00 +03:00
|
|
|
function submitSearchForm() {
|
2017-08-23 16:39:28 +03:00
|
|
|
var str = $('#search-term').val();
|
2019-03-26 21:27:58 +03:00
|
|
|
if(str.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 16:39:28 +03:00
|
|
|
|
|
|
|
searchController.search(str).then(function(results) {
|
2019-03-26 21:27:58 +03:00
|
|
|
if (results.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (results.length === 1) {
|
|
|
|
var result = results[0];
|
|
|
|
mapController.displaySearchResult(result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('multiple results');
|
|
|
|
var result = results[0];
|
|
|
|
mapController.displaySearchResult(result);
|
|
|
|
}
|
2017-08-23 16:39:28 +03:00
|
|
|
});
|
2017-08-24 13:28:00 +03:00
|
|
|
}
|
2019-03-27 20:04:04 +03:00
|
|
|
|
2019-03-29 05:54:32 +03:00
|
|
|
document.onkeydown = function (e) {
|
|
|
|
e = e || window.event;
|
|
|
|
if (e.key === 'Escape' && favoritesController.movingFavoriteId !== null) {
|
|
|
|
favoritesController.leaveMoveFavoriteMode();
|
|
|
|
}
|
|
|
|
};
|
2017-08-23 14:51:37 +03:00
|
|
|
});
|
2017-08-23 16:39:28 +03:00
|
|
|
|
2017-08-24 18:57:49 +03:00
|
|
|
var helpers = {
|
|
|
|
beautifyUrl: function(url) {
|
|
|
|
return url.replace(/^(?:\w+:|)\/\/(?:www\.|)(.*[^\/])\/*$/, '$1');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-26 20:09:08 +03:00
|
|
|
var optionsController = {
|
|
|
|
optionValues: {},
|
2019-03-29 21:07:53 +03:00
|
|
|
enabledFavoriteCategories: [],
|
2019-03-26 20:09:08 +03:00
|
|
|
saveOptionValues: function (optionValues) {
|
|
|
|
var req = {
|
|
|
|
options: optionValues
|
|
|
|
};
|
|
|
|
var url = OC.generateUrl('/apps/maps/saveOptionValue');
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
async: true
|
|
|
|
}).done(function (response) {
|
|
|
|
}).fail(function() {
|
|
|
|
OC.Notification.showTemporary(
|
|
|
|
t('maps', 'Failed to save option values')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreOptions: function () {
|
2019-03-29 21:07:53 +03:00
|
|
|
var that = this;
|
2019-03-26 20:09:08 +03:00
|
|
|
var url = OC.generateUrl('/apps/maps/getOptionsValues');
|
|
|
|
var req = {};
|
|
|
|
var optionsValues = {};
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
async: true
|
|
|
|
}).done(function (response) {
|
|
|
|
optionsValues = response.values;
|
2019-03-26 21:27:58 +03:00
|
|
|
// set tilelayer before showing photo layer because it needs a max zoom value
|
2019-03-26 20:59:11 +03:00
|
|
|
if (optionsValues.hasOwnProperty('tileLayer')) {
|
|
|
|
mapController.map.addLayer(mapController.baseLayers[optionsValues.tileLayer]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mapController.map.addLayer(mapController.baseLayers['OpenStreetMap']);
|
|
|
|
}
|
2019-04-01 18:45:23 +03:00
|
|
|
if (!optionsValues.hasOwnProperty('photosLayer') || optionsValues.photosLayer === 'true') {
|
2019-03-26 21:34:58 +03:00
|
|
|
photosController.toggleLayer();
|
2019-03-26 21:27:58 +03:00
|
|
|
}
|
|
|
|
if (optionsValues.hasOwnProperty('locControlEnabled') && optionsValues.locControlEnabled === 'true') {
|
|
|
|
mapController.locControl.start();
|
|
|
|
}
|
2019-04-01 18:45:23 +03:00
|
|
|
if (!optionsValues.hasOwnProperty('favoritesEnabled') || optionsValues.favoritesEnabled === 'true') {
|
2019-03-27 20:04:04 +03:00
|
|
|
favoritesController.toggleFavorites();
|
|
|
|
}
|
2019-04-01 18:45:23 +03:00
|
|
|
if (!optionsValues.hasOwnProperty('favoriteCategoryListShow') || optionsValues.favoriteCategoryListShow === 'true') {
|
2019-03-29 19:27:53 +03:00
|
|
|
favoritesController.toggleCategoryList();
|
|
|
|
}
|
2019-03-29 21:07:53 +03:00
|
|
|
if (optionsValues.hasOwnProperty('enabledFavoriteCategories')
|
|
|
|
&& optionsValues.enabledFavoriteCategories
|
|
|
|
&& optionsValues.enabledFavoriteCategories !== '')
|
|
|
|
{
|
|
|
|
that.enabledFavoriteCategories = optionsValues.enabledFavoriteCategories.split('|');
|
|
|
|
if (favoritesController.favoritesLoaded) {
|
|
|
|
favoritesController.restoreCategoriesState(that.enabledFavoriteCategories);
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 05:14:10 +03:00
|
|
|
if (optionsValues.hasOwnProperty('routingEnabled') && optionsValues.routingEnabled === 'true') {
|
|
|
|
routingController.toggleRouting();
|
|
|
|
}
|
2019-03-29 19:38:24 +03:00
|
|
|
|
|
|
|
// save tile layer when changed
|
|
|
|
// do it after restore, otherwise restoring triggers save
|
|
|
|
mapController.map.on('baselayerchange ', function(e) {
|
|
|
|
optionsController.saveOptionValues({tileLayer: e.name});
|
|
|
|
});
|
2019-03-26 20:09:08 +03:00
|
|
|
}).fail(function() {
|
|
|
|
OC.Notification.showTemporary(
|
|
|
|
t('maps', 'Failed to restore options values')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-04-01 12:23:11 +03:00
|
|
|
};
|
2019-03-26 20:09:08 +03:00
|
|
|
|
2017-08-24 13:28:00 +03:00
|
|
|
var mapController = {
|
|
|
|
searchMarker: {},
|
|
|
|
map: {},
|
2017-09-24 16:59:22 +03:00
|
|
|
locControl: undefined,
|
2019-03-26 20:59:11 +03:00
|
|
|
baseLayers: undefined,
|
2017-08-24 13:28:00 +03:00
|
|
|
displaySearchResult: function(result) {
|
|
|
|
if(this.searchMarker) this.map.removeLayer(this.searchMarker);
|
|
|
|
this.searchMarker = L.marker([result.lat, result.lon]);
|
|
|
|
var name = result.display_name;
|
|
|
|
var popupContent = searchController.parseOsmResult(result);
|
|
|
|
this.searchMarker.bindPopup(popupContent);
|
|
|
|
this.searchMarker.addTo(this.map);
|
|
|
|
this.searchMarker.openPopup();
|
|
|
|
},
|
|
|
|
initMap: function() {
|
|
|
|
var attribution = '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>';
|
|
|
|
|
2019-03-19 02:16:32 +03:00
|
|
|
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
attribution : attribution,
|
2017-08-24 13:28:00 +03:00
|
|
|
noWrap: true,
|
2019-03-19 20:50:20 +03:00
|
|
|
detectRetina: false,
|
|
|
|
maxZoom: 19
|
2019-03-19 02:16:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
var attributionESRI = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
|
|
|
|
var ESRIAerial = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
|
|
|
|
attribution : attributionESRI,
|
|
|
|
noWrap: false,
|
2019-03-19 20:50:20 +03:00
|
|
|
detectRetina: true,
|
|
|
|
maxZoom: 19
|
|
|
|
});
|
|
|
|
var ESRITopo = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
|
|
|
|
attribution : attributionESRI,
|
|
|
|
noWrap: false,
|
|
|
|
detectRetina: false,
|
|
|
|
maxZoom: 19
|
|
|
|
});
|
|
|
|
var attributionOpenTopo = 'Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://viewfinderpanoramass.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)';
|
|
|
|
var openTopo = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
|
|
|
|
attribution : attributionOpenTopo,
|
|
|
|
noWrap: false,
|
|
|
|
detectRetina: false,
|
|
|
|
maxZoom: 17
|
|
|
|
});
|
|
|
|
var attributionDark = '© Map tiles by CartoDB, under CC BY 3.0. Data by OpenStreetMap, under ODbL.';
|
|
|
|
var dark = L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
|
|
|
|
attribution : attributionDark,
|
|
|
|
noWrap: false,
|
|
|
|
detectRetina: false,
|
|
|
|
maxZoom: 18
|
|
|
|
});
|
|
|
|
var attributionWatercolor = '<a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a> | © Map tiles by <a href="https://stamen.com">Stamen Design</a>, under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>, Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, under <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.';
|
|
|
|
var watercolor = L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg', {
|
|
|
|
attribution : attributionWatercolor,
|
|
|
|
noWrap: false,
|
|
|
|
detectRetina: false,
|
|
|
|
maxZoom: 18
|
2017-08-24 13:28:00 +03:00
|
|
|
});
|
|
|
|
this.map = L.map('map', {
|
2019-03-26 19:10:18 +03:00
|
|
|
zoom: 2,
|
2019-03-19 02:16:32 +03:00
|
|
|
zoomControl: true,
|
2019-04-02 03:50:18 +03:00
|
|
|
maxZoom: 19,
|
2019-03-26 19:10:18 +03:00
|
|
|
center: new L.LatLng(0, 0),
|
2019-03-19 20:24:00 +03:00
|
|
|
maxBounds: new L.LatLngBounds(new L.LatLng(-90, 180), new L.LatLng(90, -180)),
|
|
|
|
layers: []
|
2017-08-24 13:28:00 +03:00
|
|
|
});
|
2019-04-02 18:11:45 +03:00
|
|
|
L.control.scale({metric: true, imperial: true, position: 'topleft'})
|
|
|
|
.addTo(this.map);
|
2017-09-24 16:59:22 +03:00
|
|
|
this.locControl = L.control.locate({
|
2019-04-02 18:11:45 +03:00
|
|
|
position: 'topleft',
|
2019-03-26 20:59:11 +03:00
|
|
|
drawCircle: true,
|
|
|
|
drawMarker: true,
|
2017-09-24 16:59:22 +03:00
|
|
|
showPopup: false,
|
2019-03-26 20:59:11 +03:00
|
|
|
icon: 'fa fa-map-marker-alt',
|
2017-09-24 16:59:22 +03:00
|
|
|
iconLoading: 'fa fa-spinner fa-spin',
|
|
|
|
strings: {
|
2019-03-26 20:59:11 +03:00
|
|
|
title: t('maps', 'Get current location')
|
2017-09-24 16:59:22 +03:00
|
|
|
}
|
|
|
|
}).addTo(this.map);
|
2019-03-26 20:59:11 +03:00
|
|
|
$('.leaflet-control-locate a').click( function(e) {
|
|
|
|
optionsController.saveOptionValues({locControlEnabled: mapController.locControl._active});
|
|
|
|
});
|
2019-03-19 02:16:32 +03:00
|
|
|
|
|
|
|
// tile layer selector
|
|
|
|
var baseLayers = {
|
|
|
|
'OpenStreetMap': osm,
|
2019-03-19 20:50:20 +03:00
|
|
|
'ESRI Aerial': ESRIAerial,
|
|
|
|
'ESRI Topo': ESRITopo,
|
|
|
|
'OpenTopoMap': openTopo,
|
|
|
|
'Dark': dark,
|
|
|
|
'Watercolor': watercolor
|
2019-03-19 02:16:32 +03:00
|
|
|
}
|
2019-03-26 20:59:11 +03:00
|
|
|
this.baseLayers = baseLayers;
|
2019-03-19 02:16:32 +03:00
|
|
|
L.control.layers(baseLayers, {}, {position: 'bottomright'}).addTo(this.map);
|
2019-03-19 20:24:00 +03:00
|
|
|
|
|
|
|
// main layers buttons
|
2019-03-27 20:46:17 +03:00
|
|
|
var esriImageUrl = $('#dummylogo').css('content').replace('url("', '').replace('")', '').replace('.png', 'esri.jpg');
|
2019-03-19 20:50:20 +03:00
|
|
|
var esriButton = L.easyButton({
|
2019-03-19 20:24:00 +03:00
|
|
|
position: 'bottomright',
|
|
|
|
states: [{
|
|
|
|
stateName: 'no-importa',
|
2019-03-27 20:46:17 +03:00
|
|
|
icon: '<img src="'+esriImageUrl+'"/>',
|
2019-03-19 20:50:20 +03:00
|
|
|
title: t('maps', 'Aerial map'),
|
2019-03-19 20:24:00 +03:00
|
|
|
onClick: function(btn, map) {
|
2019-03-19 20:50:20 +03:00
|
|
|
for (var tl in baseLayers) {
|
|
|
|
map.removeLayer(baseLayers[tl]);
|
|
|
|
}
|
|
|
|
map.addLayer(ESRIAerial);
|
2019-03-19 20:24:00 +03:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2019-03-19 20:50:20 +03:00
|
|
|
esriButton.addTo(this.map);
|
2019-03-27 20:46:17 +03:00
|
|
|
var osmImageUrl = $('#dummylogo').css('content').replace('url("', '').replace('")', '').replace('.png', 'osm.png');
|
2019-03-19 20:50:20 +03:00
|
|
|
var osmButton = L.easyButton({
|
2019-03-19 20:24:00 +03:00
|
|
|
position: 'bottomright',
|
|
|
|
states: [{
|
|
|
|
stateName: 'no-importa',
|
2019-03-27 20:46:17 +03:00
|
|
|
icon: '<img src="'+osmImageUrl+'"/>',
|
2019-03-19 20:50:20 +03:00
|
|
|
title: t('maps', 'Classic map'),
|
2019-03-19 20:24:00 +03:00
|
|
|
onClick: function(btn, map) {
|
2019-03-19 20:50:20 +03:00
|
|
|
for (var tl in baseLayers) {
|
|
|
|
map.removeLayer(baseLayers[tl]);
|
|
|
|
}
|
|
|
|
map.addLayer(osm);
|
2019-03-19 20:24:00 +03:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2019-03-19 20:50:20 +03:00
|
|
|
osmButton.addTo(this.map);
|
2019-04-03 05:14:10 +03:00
|
|
|
}
|
|
|
|
};
|
2019-04-02 18:11:45 +03:00
|
|
|
|
2019-04-03 05:14:10 +03:00
|
|
|
var routingController = {
|
|
|
|
control: undefined,
|
|
|
|
map: undefined,
|
|
|
|
enabled: false,
|
|
|
|
initRoutingControl: function(map) {
|
|
|
|
this.map = map;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
//var bikeRouter = L.Routing.osrmv1({
|
|
|
|
// serviceUrl: 'http://osrm.mapzen.com/bicycle/viaroute'
|
|
|
|
//});
|
|
|
|
this.control = L.Routing.control({
|
2019-04-02 18:11:45 +03:00
|
|
|
//waypoints: [
|
|
|
|
// L.latLng(57.74, 11.94),
|
|
|
|
// L.latLng(57.6792, 11.949)
|
|
|
|
//],
|
|
|
|
routeWhileDragging: true,
|
|
|
|
geocoder: L.Control.Geocoder.nominatim(),
|
2019-04-03 05:14:10 +03:00
|
|
|
// TODO find a way to check if current NC language is supported by routing control
|
|
|
|
//language: 'fr',
|
|
|
|
//router: bikeRouter
|
|
|
|
})
|
|
|
|
|
|
|
|
$('body').on('click', '.routingMenuButton', function(e) {
|
|
|
|
var wasOpen = $(this).parent().parent().parent().find('>.app-navigation-entry-menu').hasClass('open');
|
|
|
|
$('.app-navigation-entry-menu.open').removeClass('open');
|
|
|
|
if (!wasOpen) {
|
|
|
|
$(this).parent().parent().parent().find('>.app-navigation-entry-menu').addClass('open');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// toggle routing control
|
|
|
|
$('body').on('click', '#toggleRoutingButton, #navigation-routing > a', function(e) {
|
|
|
|
that.toggleRouting();
|
|
|
|
optionsController.saveOptionValues({routingEnabled: that.enabled});
|
|
|
|
});
|
2019-04-03 05:21:23 +03:00
|
|
|
// export
|
|
|
|
$('body').on('click', '.exportCurrentRoute', function(e) {
|
|
|
|
that.exportRoute();
|
|
|
|
});
|
2019-04-03 05:14:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleRouting: function() {
|
|
|
|
if (this.enabled) {
|
|
|
|
this.control.remove();
|
|
|
|
$('#toggleRoutingButton button').addClass('icon-toggle').attr('style', '');
|
|
|
|
this.enabled = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.control.addTo(this.map);
|
|
|
|
var color = OCA.Theming.color.replace('#', '');
|
|
|
|
var imgurl = OC.generateUrl('/svg/core/actions/toggle?color='+color);
|
|
|
|
$('#toggleRoutingButton button').removeClass('icon-toggle').css('background-image', 'url('+imgurl+')');
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
2019-04-03 05:21:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
exportRoute: function() {
|
|
|
|
if (this.control.hasOwnProperty('_routes')
|
|
|
|
&& this.control._routes.length > 0
|
|
|
|
&& this.control._routes[0].hasOwnProperty('coordinates')
|
|
|
|
) {
|
|
|
|
console.log(this.control._routes[0].coordinates);
|
|
|
|
}
|
2017-08-24 13:28:00 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-01 12:23:11 +03:00
|
|
|
var timeFilterController = {
|
2019-04-01 22:33:24 +03:00
|
|
|
min: 0,
|
|
|
|
max: Date.now()/1000,
|
2019-04-02 03:50:18 +03:00
|
|
|
minInitialized: false,
|
|
|
|
maxInitialized: false,
|
|
|
|
valueBegin: null,
|
|
|
|
valueEnd: null,
|
2019-04-01 22:33:24 +03:00
|
|
|
updateFilterTimeBegin: [],
|
|
|
|
updateFilterTimeEnd: [],
|
2019-04-01 23:23:14 +03:00
|
|
|
onUpdateCallbackBlock: false,
|
2019-04-02 03:50:18 +03:00
|
|
|
onChangeCallbackBlock: false,
|
|
|
|
slider : document.getElementById("timeRangeSlider"),
|
2019-04-02 10:57:26 +03:00
|
|
|
sliderConnect: null,
|
2019-04-02 03:50:18 +03:00
|
|
|
connect: function () {
|
|
|
|
noUiSlider.create(this.slider, {
|
|
|
|
start: [20, 80],
|
|
|
|
connect: true,
|
|
|
|
behaviour: 'drag',
|
|
|
|
tooltips: [{
|
|
|
|
to: function (x) {
|
|
|
|
return new Date(x*1000);
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
to: function (x) {
|
|
|
|
return new Date(x*1000);
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
range: {
|
|
|
|
'min': 0,
|
|
|
|
'max': 1
|
2019-04-02 10:57:26 +03:00
|
|
|
}
|
2019-04-02 03:50:18 +03:00
|
|
|
});
|
2019-04-02 10:57:26 +03:00
|
|
|
this.sliderConnect = this.slider.getElementsByClassName("noUi-connect")[0];
|
2019-04-02 03:50:18 +03:00
|
|
|
this.updateSliderRange(this.min, this.max);
|
|
|
|
this.setSlider(this.min, this.max);
|
2019-04-01 22:33:24 +03:00
|
|
|
var that = this;
|
2019-04-02 03:50:18 +03:00
|
|
|
this.slider.noUiSlider.on('update', function(values, handle, unencoded, tap, positions) {
|
2019-04-01 22:33:24 +03:00
|
|
|
if (!that.onUpdateCallbackBlock){
|
|
|
|
that.onUpdateCallbackBlock = true;
|
|
|
|
if (handle === 0) {
|
2019-04-02 03:50:18 +03:00
|
|
|
that.valueBegin = unencoded[0];
|
|
|
|
photosController.updateTimeFilterBegin(that.valueBegin);
|
2019-04-01 22:33:24 +03:00
|
|
|
}
|
2019-04-02 03:50:18 +03:00
|
|
|
else {
|
|
|
|
that.valueEnd = unencoded[1];
|
|
|
|
photosController.updateTimeFilterEnd(that.valueEnd);
|
|
|
|
}
|
|
|
|
favoritesController.updateFilterDisplay();
|
2019-04-02 10:57:26 +03:00
|
|
|
|
2019-04-01 22:33:24 +03:00
|
|
|
that.onUpdateCallbackBlock = false;
|
2019-04-02 10:57:26 +03:00
|
|
|
if (unencoded[0] < that.min || unencoded[1] > that.max || positions[1] - positions[0] < 10) {
|
|
|
|
that.sliderConnect.classList.add("timeRangeSlider-active");
|
|
|
|
} else {
|
|
|
|
that.sliderConnect.classList.remove("timeRangeSlider-active");
|
|
|
|
}
|
2019-04-01 22:33:24 +03:00
|
|
|
}
|
2019-04-02 03:50:18 +03:00
|
|
|
});
|
|
|
|
this.slider.noUiSlider.on('change', function(values, handle, unencoded, tap, positions) {
|
2019-04-02 10:57:26 +03:00
|
|
|
if (!that.onChangeCallbackBlock) {
|
2019-04-01 23:23:14 +03:00
|
|
|
that.onChangeCallbackBlock = true;
|
|
|
|
if (unencoded[0] < that.min) {
|
|
|
|
var delta = that.min-unencoded[0];
|
|
|
|
var r = that.max-that.min;
|
|
|
|
that.updateSliderRange(that.min - 25* delta*delta/r, that.max);
|
|
|
|
}
|
|
|
|
if (unencoded[1] > that.max) {
|
|
|
|
var delta = -that.max+unencoded[1];
|
|
|
|
var r = that.max-that.min;
|
|
|
|
that.updateSliderRange(that.min, that.max + 25*delta*delta/r);
|
|
|
|
}
|
|
|
|
if (positions[1] - positions[0] < 10) {
|
|
|
|
var m = (unencoded[0] + unencoded[1])/2;
|
2019-04-02 10:57:26 +03:00
|
|
|
var d = Math.max((unencoded[1] - unencoded[0])/2,1);
|
2019-04-01 23:23:14 +03:00
|
|
|
that.updateSliderRange(m-2.5*d, m+2.5*d);
|
|
|
|
that.setSlider(unencoded[0], unencoded[1]);
|
|
|
|
}
|
2019-04-02 13:23:06 +03:00
|
|
|
that.sliderConnect.classList.remove("timeRangeSlider-active");
|
2019-04-01 23:23:14 +03:00
|
|
|
that.onChangeCallbackBlock = false;
|
|
|
|
}
|
2019-04-01 22:33:24 +03:00
|
|
|
});
|
2019-04-02 13:16:57 +03:00
|
|
|
this.slider.ondblclick = function() {
|
|
|
|
that.updateSliderRangeFromController();
|
|
|
|
that.setSliderToMaxInterval();
|
|
|
|
};
|
2019-04-01 22:33:24 +03:00
|
|
|
},
|
2019-04-02 03:50:18 +03:00
|
|
|
updateSliderRange: function(min, max) {
|
2019-04-01 12:23:11 +03:00
|
|
|
var range = max - min;
|
2019-04-01 22:33:24 +03:00
|
|
|
this.slider.noUiSlider.updateOptions({
|
|
|
|
range: {
|
|
|
|
'min': min - range/10,
|
|
|
|
'max': max + range/10
|
2019-04-02 10:57:26 +03:00
|
|
|
},
|
2019-04-01 22:33:24 +03:00
|
|
|
});
|
2019-04-01 23:23:14 +03:00
|
|
|
this.min = min;
|
|
|
|
this.max = max;
|
2019-04-01 12:23:11 +03:00
|
|
|
},
|
2019-04-01 23:23:14 +03:00
|
|
|
setSlider: function(min, max) {
|
|
|
|
this.slider.noUiSlider.set([min, max]);
|
2019-04-02 03:50:18 +03:00
|
|
|
},
|
|
|
|
// when a controller's data has changed
|
|
|
|
updateSliderRangeFromController: function() {
|
|
|
|
var mins = [
|
|
|
|
favoritesController.firstDate,
|
|
|
|
photosController.photoMarkersOldest
|
|
|
|
];
|
|
|
|
var maxs = [
|
|
|
|
favoritesController.lastDate,
|
|
|
|
photosController.photoMarkersNewest
|
|
|
|
];
|
|
|
|
var i;
|
|
|
|
for (i=0; i < mins.length; i++) {
|
|
|
|
// if there is a value, we change the timeFilterController min if there is none
|
|
|
|
// or if there is a lower value
|
|
|
|
if (mins[i] !== null && (!this.minInitialized || mins[i] < this.min)) {
|
|
|
|
this.min = mins[i];
|
|
|
|
this.minInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i < maxs.length; i++) {
|
|
|
|
// if there is a value, we change the timeFilterController max if there is none
|
|
|
|
// or if there is a higher value
|
|
|
|
if (maxs[i] !== null && (!this.maxInitialized || maxs[i] > this.max)) {
|
|
|
|
this.max = maxs[i];
|
|
|
|
this.maxInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minInitialized && this.maxInitialized) {
|
2019-04-02 04:53:46 +03:00
|
|
|
// avoid min == max
|
|
|
|
if (this.min === this.max) {
|
|
|
|
this.min = this.min - 10;
|
|
|
|
this.max = this.max + 10;
|
|
|
|
}
|
2019-04-02 03:50:18 +03:00
|
|
|
this.updateSliderRange(this.min, this.max);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// on first data load, controllers want to set the slider values to global common max
|
|
|
|
setSliderToMaxInterval: function() {
|
|
|
|
this.setSlider(this.min, this.max);
|
2019-04-01 23:23:14 +03:00
|
|
|
}
|
2019-04-01 12:23:11 +03:00
|
|
|
};
|
|
|
|
|
2019-04-01 22:33:24 +03:00
|
|
|
|
2019-04-01 12:23:11 +03:00
|
|
|
var photosController = new PhotosController(optionsController, timeFilterController);
|
2019-04-01 21:03:12 +03:00
|
|
|
var favoritesController = new FavoritesController(optionsController, timeFilterController);
|
2017-08-31 00:40:37 +03:00
|
|
|
|
2019-04-02 03:50:18 +03:00
|
|
|
timeFilterController.connect();
|
2019-04-01 12:23:11 +03:00
|
|
|
|
2017-08-23 16:39:28 +03:00
|
|
|
var searchController = {
|
|
|
|
isGeocodeabe: function(str) {
|
|
|
|
var pattern = /^\s*\d+\.?\d*\,\s*\d+\.?\d*\s*$/;
|
|
|
|
return pattern.test(str);
|
|
|
|
},
|
|
|
|
search: function(str) {
|
|
|
|
var searchTerm = str.replace(' ', '%20'); // encode spaces
|
2019-03-26 21:27:58 +03:00
|
|
|
var apiUrl = 'https://nominatim.openstreetmap.org/search/'+searchTerm+'?format=json&addressdetails=1&extratags=1&namedetails=1&limit=8';
|
2017-08-23 16:39:28 +03:00
|
|
|
return $.getJSON(apiUrl, {}, function(response) {
|
|
|
|
return response;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
geocode: function(latlng) {
|
|
|
|
if(!this.isGeocodeabe(latlng)) return;
|
|
|
|
var splits = latlng.split(',');
|
|
|
|
var lat = splits[0].trim();
|
|
|
|
var lon = splits[1].trim();
|
|
|
|
var apiUrl = 'https://nominatim.openstreetmap.org/reverse?format=json&lat=' + lat + '&lon='+ lon + '&addressdetails=1';
|
|
|
|
return $.getJSON(apiUrl, {}, function(response) {
|
|
|
|
return response;
|
|
|
|
});
|
|
|
|
},
|
2017-08-23 18:55:58 +03:00
|
|
|
parseOsmResult: function(result) {
|
|
|
|
var add = result.address;
|
2017-08-23 20:35:07 +03:00
|
|
|
var road, postcode, city, state, name;
|
2017-08-23 16:39:28 +03:00
|
|
|
if(add.road) {
|
2017-08-23 20:35:07 +03:00
|
|
|
road = add.road;
|
|
|
|
if(add.house_number) road += ' ' + add.house_number;
|
2017-08-23 16:39:28 +03:00
|
|
|
}
|
2017-08-23 20:35:07 +03:00
|
|
|
if(add.postcode) postcode = add.postcode;
|
2017-08-23 16:39:28 +03:00
|
|
|
if(add.city || add.town || add.village) {
|
|
|
|
if(add.city) city = add.city;
|
|
|
|
else if(add.town) city = add.town;
|
|
|
|
else if(add.village) city = add.village;
|
|
|
|
if(add.state) {
|
2017-08-23 20:35:07 +03:00
|
|
|
state = add.state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var details = result.namedetails;
|
|
|
|
if(details.name) name = details.name;
|
|
|
|
|
|
|
|
var unformattedHeader;
|
|
|
|
if(name) unformattedHeader = name;
|
|
|
|
else if(road) unformattedHeader = road;
|
|
|
|
else if(city) unformattedHeader = city;
|
|
|
|
|
|
|
|
var unformattedDesc = '';
|
|
|
|
var needSeparator = false;
|
2017-08-24 13:30:14 +03:00
|
|
|
// add road to desc if it is not heading and exists (isn't heading, if 'name' is set)
|
|
|
|
if(name && road) {
|
2017-08-23 20:35:07 +03:00
|
|
|
unformattedDesc = road;
|
|
|
|
needSeparator = true;
|
|
|
|
}
|
|
|
|
if(postcode) {
|
|
|
|
if(needSeparator) {
|
|
|
|
unformattedDesc += ', ';
|
|
|
|
needSeparator = false;
|
|
|
|
}
|
|
|
|
unformattedDesc += postcode;
|
|
|
|
}
|
|
|
|
if(city) {
|
|
|
|
if(needSeparator) {
|
|
|
|
unformattedDesc += ', ';
|
|
|
|
needSeparator = false;
|
|
|
|
} else if(unformattedDesc.length > 0) {
|
|
|
|
unformattedDesc += ' ';
|
2017-08-23 16:39:28 +03:00
|
|
|
}
|
2017-08-23 20:35:07 +03:00
|
|
|
unformattedDesc += city;
|
2017-08-23 16:39:28 +03:00
|
|
|
}
|
2017-08-23 20:35:07 +03:00
|
|
|
if(state && add && add.country_code == 'us') { // assume that state is only important for us addresses
|
|
|
|
if(unformattedDesc.length > 0) {
|
2017-08-24 13:30:14 +03:00
|
|
|
unformattedDesc += ' ';
|
2017-08-23 20:35:07 +03:00
|
|
|
}
|
|
|
|
unformattedDesc += '(' + state + ')';
|
|
|
|
}
|
|
|
|
|
2017-08-23 16:39:28 +03:00
|
|
|
var header = '<h2 class="location-header">' + unformattedHeader + '</h2>';
|
2017-08-24 18:57:49 +03:00
|
|
|
if(result.icon) header = '<div class="inline-wrapper"><img class="location-icon" src="' + result.icon + '" />' + header + '</div>';
|
2017-08-23 20:35:07 +03:00
|
|
|
var desc = '<span class="location-city">' + unformattedDesc + '</span>';
|
|
|
|
|
|
|
|
// Add extras to parsed desc
|
2017-08-23 18:55:58 +03:00
|
|
|
var extras = result.extratags;
|
|
|
|
if(extras.opening_hours) {
|
2017-08-24 19:58:36 +03:00
|
|
|
desc += '<div id="opening-hours-header" class="inline-wrapper"><img class="popup-icon" src="'+OC.filePath('maps', 'img', 'recent.svg')+'" />';
|
2017-08-24 17:01:01 +03:00
|
|
|
var oh = new opening_hours(extras.opening_hours, result);
|
|
|
|
var isCurrentlyOpen = oh.getState();
|
|
|
|
var changeDt = oh.getNextChange();
|
|
|
|
var currentDt = new Date();
|
|
|
|
var dtDiff = changeDt.getTime() - currentDt.getTime();
|
|
|
|
dtDiff = dtDiff / 60000; // get diff in minutes
|
|
|
|
if(oh.getState()) { // is open?
|
2017-08-24 18:57:49 +03:00
|
|
|
desc += '<span class="poi-open">Open</span>';
|
|
|
|
if(dtDiff <= 60) {
|
|
|
|
desc += '<span class="poi-closes">, closes in ' + dtDiff + ' minutes</span>';
|
|
|
|
} else {
|
|
|
|
desc += '<span> until ' + changeDt.toLocaleTimeString() + '</span>';
|
2017-08-24 17:01:01 +03:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-24 18:57:49 +03:00
|
|
|
desc += '<span class="poi-closed">Closed</span>';
|
|
|
|
desc += '<span class="poi-opens">opens at ' + changeDt.toLocaleTimeString() + '</span>';
|
2017-08-23 18:55:58 +03:00
|
|
|
}
|
2017-08-24 19:58:36 +03:00
|
|
|
desc += '<img id="opening-hours-table-toggle-collapse" src="'+OC.filePath('maps', 'img', 'triangle-s.svg')+'" /><img id="opening-hours-table-toggle-expand" src="'+OC.filePath('maps', 'img', 'triangle-e.svg')+'" /></div>';
|
2017-08-24 17:01:01 +03:00
|
|
|
var todayStart = currentDt;
|
|
|
|
todayStart.setHours(0);
|
|
|
|
todayStart.setMinutes(0);
|
|
|
|
todayStart.setSeconds(0);
|
|
|
|
var sevDaysEnd = new Date(todayStart);
|
|
|
|
var sevDaysMs = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
sevDaysEnd.setTime(sevDaysEnd.getTime()+sevDaysMs);
|
|
|
|
var intervals = oh.getOpenIntervals(todayStart, sevDaysEnd);
|
2017-08-24 19:58:36 +03:00
|
|
|
desc += '<table id="opening-hours-table">';
|
2017-08-24 17:01:01 +03:00
|
|
|
// intervals should be 7, if 8, then first entry is interval after 00:00:00 from last day
|
|
|
|
if(intervals.length == 8) {
|
|
|
|
// set end time of last element to end time of first element and remove it
|
|
|
|
intervals[7][1] = intervals[0][1];
|
|
|
|
intervals.splice(0, 1);
|
|
|
|
}
|
|
|
|
for(var i=0; i<intervals.length; i++) {
|
|
|
|
var from = intervals[i][0];
|
|
|
|
var to = intervals[i][1];
|
|
|
|
var day = from.toLocaleDateString([], {weekday:'long'});
|
|
|
|
if(i==0) desc += '<tr class="selected">';
|
|
|
|
else desc += '<tr>';
|
|
|
|
desc += '<td class="opening-hours-day">' + day + '</td>';
|
|
|
|
var startTime = from.toLocaleTimeString();
|
|
|
|
var endTime =to.toLocaleTimeString();
|
|
|
|
desc += '<td class="opening-hours-hours">' + startTime + ' - ' + endTime + '</td>';
|
|
|
|
desc += '</tr>';
|
|
|
|
}
|
|
|
|
desc += '</table>';
|
2017-08-23 18:55:58 +03:00
|
|
|
}
|
2017-08-23 18:59:55 +03:00
|
|
|
if(extras.website) {
|
2017-08-24 18:57:49 +03:00
|
|
|
desc += '<div class="inline-wrapper"><img class="popup-icon" src="'+OC.filePath('maps', 'img', 'link.svg')+'" /><a href="' + extras.website + '" target="_blank">' + helpers.beautifyUrl(extras.website) + '</a></div>';
|
|
|
|
}
|
|
|
|
if(extras.phone) {
|
|
|
|
desc += '<div class="inline-wrapper"><img class="popup-icon" src="'+OC.filePath('maps', 'img', 'link.svg')+'" /><a href="tel:' + extras.phone + '" target="_blank">' + extras.phone + '</a></div>';
|
|
|
|
}
|
|
|
|
if(extras.email) {
|
|
|
|
desc += '<div class="inline-wrapper"><img class="popup-icon" src="'+OC.filePath('maps', 'img', 'mail.svg')+'" /><a href="mailto:' + extras.email + '" target="_blank">' + extras.email + '</a></div>';
|
2017-08-23 18:59:55 +03:00
|
|
|
}
|
2017-08-23 18:55:58 +03:00
|
|
|
|
2017-08-23 16:39:28 +03:00
|
|
|
return header + desc;
|
|
|
|
}
|
|
|
|
};
|
2014-08-31 15:21:13 +04:00
|
|
|
})(jQuery, OC);
|