|
|
@@ -0,0 +1,586 @@
|
|
|
+
|
|
|
+const variants_uris = {
|
|
|
+ "preprod.opentalent.fr": "https://api.preprod.opentalent.fr",
|
|
|
+ "local.sub.opentalent.fr": "https://local.api.opentalent.fr",
|
|
|
+ "typo3": "http://docker.nginx.opentalent.fr"
|
|
|
+};
|
|
|
+
|
|
|
+const base_uri = variants_uris[$(location).attr('hostname')];
|
|
|
+let apiGetUrl = base_uri + '/api/public/federation_structures?_format=json&page=1&itemsPerPage=99999';
|
|
|
+
|
|
|
+
|
|
|
+// Converts numeric degrees to radians
|
|
|
+function toRad(Value)
|
|
|
+{
|
|
|
+ return Value * Math.PI / 180;
|
|
|
+}
|
|
|
+
|
|
|
+//This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
|
|
|
+function sphericDistance(lat1, lon1, lat2, lon2)
|
|
|
+{
|
|
|
+ let R = 6371; // km
|
|
|
+ let dLat = toRad(lat2-lat1);
|
|
|
+ let dLon = toRad(lon2-lon1);
|
|
|
+ lat1 = toRad(lat1);
|
|
|
+ lat2 = toRad(lat2);
|
|
|
+
|
|
|
+ let a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
|
|
+ Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
|
|
|
+ let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
|
+ return R * c;
|
|
|
+}
|
|
|
+
|
|
|
+// Specific JS used for the Structures layout
|
|
|
+// > Needs to be loaded after the main.js script
|
|
|
+$(document).ready(function() {
|
|
|
+
|
|
|
+ const queryParameters = new URLSearchParams(window.location.search);
|
|
|
+ let organizationId = queryParameters.get('organization-id');
|
|
|
+
|
|
|
+ if (!organizationId) {
|
|
|
+ throw 'Missing organization-id parameter';
|
|
|
+ }
|
|
|
+
|
|
|
+ // Init
|
|
|
+ let document = $('html, body');
|
|
|
+ let structureFrame = $('.ot-structures-frame').first();
|
|
|
+
|
|
|
+ // let organizationId = structureFrame.data('org-id');
|
|
|
+
|
|
|
+ let resultsPageDiv = structureFrame.find('.structures-page').first();
|
|
|
+ let pleaseWaitSpan = structureFrame.find('.please-wait').first();
|
|
|
+ let noResultSpan = structureFrame.find('.no-result').first();
|
|
|
+ let cardDivModel = structureFrame.find('.structure-card-model').first();
|
|
|
+ let paginationBar = structureFrame.find('.pagination-bar').first();
|
|
|
+ let paginationList = structureFrame.find('.pagination-list').first();
|
|
|
+ let gotoFirstPage = structureFrame.find('.goto-first-page').first();
|
|
|
+ let gotoLastPage = structureFrame.find('.goto-last-page').first();
|
|
|
+
|
|
|
+ let form = $("#structure-search-form");
|
|
|
+ let whatInput = form.find("input[name='search-query']").first();
|
|
|
+ let cityInput = form.find("input[name='search-city']").first();
|
|
|
+ let latInput = form.find("input[name='lat']").first();
|
|
|
+ let longInput = form.find("input[name='long']").first();
|
|
|
+ let categorySelect = form.find("select[name='search-category']").first();
|
|
|
+ let provinceSelect = form.find("select[name='search-province']").first();
|
|
|
+ let federationSelect = form.find("select[name='search-federation']").first();
|
|
|
+ let radiusSelect = form.find("select[name='search-radius']").first();
|
|
|
+ let resetButton = form.find("button.reset-search").first();
|
|
|
+ let submitButton = form.find("button.submit-search").first();
|
|
|
+
|
|
|
+ // Translations
|
|
|
+ let tr = {};
|
|
|
+ $('#labels').find('span').each(function (i, elt) {
|
|
|
+ tr[$(elt).attr('id')] = $(elt).text();
|
|
|
+ });
|
|
|
+
|
|
|
+ let structures_categories = {
|
|
|
+ '1MC': tr['1MC'],
|
|
|
+ '2TH': tr['2TH'],
|
|
|
+ '3DA': tr['3DA'],
|
|
|
+ '5FA': tr['5FA'],
|
|
|
+ 'OTAR':tr['OTAR'],
|
|
|
+ 'OTCI':tr['OTCI'],
|
|
|
+ '6AR': tr['6AR'],
|
|
|
+ '8CI': tr['8CI'],
|
|
|
+ 'OTAU':tr['OTAU'],
|
|
|
+ }
|
|
|
+
|
|
|
+ // #### Instanciate and populate leaflet map
|
|
|
+ let mapDiv = $('#structure-map').first();
|
|
|
+ let mapId = $(mapDiv).attr("id");
|
|
|
+
|
|
|
+ // Instanciate the map object @see https://leafletjs.com/reference-1.6.0.html#map-factory
|
|
|
+ const mapOptions = {scrollWheelZoom: false, zoomSnap: 0.25};
|
|
|
+ map = L.map(mapId, mapOptions);
|
|
|
+ map.setView([46.71, 2.14], 6);
|
|
|
+
|
|
|
+ // Add the tile layer
|
|
|
+ L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
|
|
+ attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
+ }).addTo(map);
|
|
|
+
|
|
|
+ var listenMapMoves = false;
|
|
|
+
|
|
|
+ var defaultsBounds = [51.03, -5.78, 41.2, 9.70];
|
|
|
+
|
|
|
+ // Set the view
|
|
|
+ let resetMapBounds = function () {
|
|
|
+ area = null;
|
|
|
+ bounds = L.latLngBounds(
|
|
|
+ L.latLng(defaultsBounds[0], defaultsBounds[1]),
|
|
|
+ L.latLng(defaultsBounds[2], defaultsBounds[3])
|
|
|
+ );
|
|
|
+ map.fitBounds(bounds);
|
|
|
+ }
|
|
|
+ resetMapBounds();
|
|
|
+
|
|
|
+ var clusters = null;
|
|
|
+
|
|
|
+
|
|
|
+ // #### Filters
|
|
|
+
|
|
|
+ // The current query
|
|
|
+ var query = {};
|
|
|
+ var area = null;
|
|
|
+
|
|
|
+ // Update the current query with form data
|
|
|
+ function updateQuery() {
|
|
|
+ query['what'] = whatInput.val();
|
|
|
+ query['lat'] = latInput.val();
|
|
|
+ query['long'] = longInput.val();
|
|
|
+ query['category'] = categorySelect.val();
|
|
|
+ query['province'] = provinceSelect.val();
|
|
|
+ query['federation'] = federationSelect.val();
|
|
|
+ query['radius'] = radiusSelect.val();
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateArea(long1, lat1, long2, lat2) {
|
|
|
+ area = [long1, lat1, long2, lat2];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Does the given structure match the current query
|
|
|
+ function matchCurrentQuery(structure) {
|
|
|
+
|
|
|
+ // Filter by name
|
|
|
+ if (query['what'] && !structure.name.toLowerCase().includes(query['what'].toLowerCase())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // filter by geographical position
|
|
|
+ if (query['lat'] && query['long']) {
|
|
|
+ if (!structure.latitude || !structure.longitude) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ let radius = Number(query['radius']) ?? 0;
|
|
|
+
|
|
|
+ // radius is increased by 10km to approximate the city radius
|
|
|
+ radius += 10;
|
|
|
+
|
|
|
+ if (sphericDistance(query['lat'], query['long'], structure.latitude, structure.longitude) > radius) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // filter by category
|
|
|
+ if (query['category'] && !structure.categories.includes(query['category'])) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (query['province']) {
|
|
|
+ let province = query['province'];
|
|
|
+
|
|
|
+ // A leading '_' may have been added to prevent the '0' from being stripped by fluid
|
|
|
+ province = province.replace('_', '');
|
|
|
+
|
|
|
+ if (!structure.postalCode.startsWith(province)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (query['federation'] && !structure.parents.includes(Number(query['federation']))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // filter by map bounds
|
|
|
+ if (area !== null) {
|
|
|
+ if (structure.longitude < area[0] ||
|
|
|
+ structure.latitude < area[1] ||
|
|
|
+ structure.longitude > area[2] ||
|
|
|
+ structure.latitude > area[3]
|
|
|
+ ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ function populateFederationsSelect() {
|
|
|
+ federationSelect.children('option:not(:first)').remove();
|
|
|
+ let has_options = false;
|
|
|
+ structures.forEach(function (structure) {
|
|
|
+ if (structure.n1Id === organizationId && structure.principalType.endsWith('FEDERATION')) {
|
|
|
+ let id = structure['@id'].split('/').pop()
|
|
|
+ let option = '<option value="' + id + '">' + structure.name + '</option>';
|
|
|
+ federationSelect.append(option);
|
|
|
+ has_options = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (has_options) {
|
|
|
+ federationSelect.prop("disabled", false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // #### Display results
|
|
|
+ const itemsPerPage = 8;
|
|
|
+ let currentPage = 1;
|
|
|
+
|
|
|
+ updateQuery();
|
|
|
+
|
|
|
+ // on page link clicked event
|
|
|
+ function pageLinkClicked(e) {
|
|
|
+ e.preventDefault();
|
|
|
+ let page = $(this).data('page');
|
|
|
+ if (page > 0) {
|
|
|
+ currentPage = page;
|
|
|
+ }
|
|
|
+ refresh();
|
|
|
+ $('body,html').animate({scrollTop: 0},500);
|
|
|
+ }
|
|
|
+ gotoFirstPage.on('click', pageLinkClicked);
|
|
|
+ gotoLastPage.on('click', pageLinkClicked);
|
|
|
+
|
|
|
+ function refresh(listOnly=false) {
|
|
|
+
|
|
|
+ // Reinitialize current results
|
|
|
+ pleaseWaitSpan.show();
|
|
|
+ listenMapMoves = false;
|
|
|
+
|
|
|
+ resultsPageDiv.find('.structure-card').remove();
|
|
|
+ paginationList.find('.goto-page-li').remove();
|
|
|
+ paginationList.hide();
|
|
|
+ if (!listOnly && clusters !== null) {
|
|
|
+ map.removeLayer(clusters);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ** Update results
|
|
|
+ let results = [];
|
|
|
+ structures.forEach(function(structure) {
|
|
|
+ if (matchCurrentQuery(structure)) {
|
|
|
+ results.push(structure)
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // ** Show the results for the current page
|
|
|
+ let index = 0;
|
|
|
+
|
|
|
+ results.forEach(function(structure) {
|
|
|
+ if (((currentPage - 1) * itemsPerPage) <= index && index < (currentPage * itemsPerPage)) {
|
|
|
+ let cardDiv = $(cardDivModel).clone();
|
|
|
+
|
|
|
+ cardDiv.data('id', structure.id);
|
|
|
+
|
|
|
+ let categoryTagModel = cardDiv.find('.structure-category-model').first();
|
|
|
+ structure.categories.forEach(function (cat) {
|
|
|
+ let tag = categoryTagModel.clone();
|
|
|
+ tag.text(structures_categories[cat]);
|
|
|
+ tag.removeClass('structure-category-model')
|
|
|
+ tag.addClass('structure-category')
|
|
|
+ tag.show();
|
|
|
+ categoryTagModel.parent().append(tag);
|
|
|
+ });
|
|
|
+
|
|
|
+ cardDiv.find('.structure-poster').first().children('img').first().attr('src', structure.logoUri);
|
|
|
+ cardDiv.find('.structure-name').first().text(structure.name);
|
|
|
+ cardDiv.find('.structure-details-address').first().text(
|
|
|
+ [structure.streetAddress, structure.postalCode, structure.addressCity].join(" ")
|
|
|
+ );
|
|
|
+ cardDiv.find('.structure-details-federation').first().text(structure.n1Name);
|
|
|
+
|
|
|
+ cardDiv.show();
|
|
|
+ cardDiv.removeClass('structure-card-model');
|
|
|
+ cardDiv.addClass('structure-card');
|
|
|
+ cardDiv.appendTo(resultsPageDiv);
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ });
|
|
|
+
|
|
|
+ // ** Update results on map
|
|
|
+ if (!listOnly) {
|
|
|
+ clusters = L.markerClusterGroup();
|
|
|
+
|
|
|
+ results.forEach(function (item) {
|
|
|
+ if (item.longitude && item.latitude) {
|
|
|
+ let marker = L.marker([item.latitude, item.longitude]);
|
|
|
+ marker.bindPopup(`<b>${item.name}</b><br/>${item.postalCode} ${item.addressCity}<br/><a href="${item.website}" target="_blank">${item.website}</a>`);
|
|
|
+ clusters.addLayer(marker);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ map.addLayer(clusters);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ** Update pagination
|
|
|
+ let resultsCount = results.length;
|
|
|
+ let pagesCount = Math.floor(resultsCount / itemsPerPage) + 1;
|
|
|
+ gotoLastPage.data("page", pagesCount);
|
|
|
+
|
|
|
+ let pageLiModel = paginationList.find('.goto-page-li-model').first();
|
|
|
+
|
|
|
+ let page_min = currentPage > 5 ? currentPage - 5 : 1;
|
|
|
+ let page_max = currentPage < (pagesCount - 5) ? currentPage + 5 : pagesCount;
|
|
|
+
|
|
|
+ for (let i = page_min; i <= page_max; i++) {
|
|
|
+ let pageLi = pageLiModel.clone();
|
|
|
+
|
|
|
+ let pageLink = pageLi.children('a').first();
|
|
|
+
|
|
|
+ pageLink.text("" + i);
|
|
|
+ pageLink.attr("data-page", i);
|
|
|
+ pageLink.on('click', pageLinkClicked)
|
|
|
+
|
|
|
+ if (i === currentPage) {
|
|
|
+ pageLi.addClass('current');
|
|
|
+ }
|
|
|
+ pageLi.removeClass('goto-page-li-model')
|
|
|
+ pageLi.addClass('goto-page-li')
|
|
|
+
|
|
|
+ pageLi.show();
|
|
|
+
|
|
|
+ pageLi.appendTo(paginationList);
|
|
|
+ }
|
|
|
+ paginationBar.show()
|
|
|
+ paginationList.show()
|
|
|
+
|
|
|
+ // Finalize
|
|
|
+ pleaseWaitSpan.hide();
|
|
|
+ listenMapMoves = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ function fitMapToResults() {
|
|
|
+ bounds = clusters.getBounds();
|
|
|
+ if (bounds.isValid()) {
|
|
|
+ map.fitBounds(bounds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // #### Load structures data and refresh
|
|
|
+ var structures = [];
|
|
|
+ $.ajax({
|
|
|
+ type: 'GET',
|
|
|
+ url: apiGetUrl,
|
|
|
+ dataType: "json",
|
|
|
+ contentType: "application/json; charset=utf-8"
|
|
|
+ })
|
|
|
+ .done(function(res) {
|
|
|
+ structures = res["hydra:member"];
|
|
|
+ populateFederationsSelect();
|
|
|
+ refresh();
|
|
|
+ })
|
|
|
+ .fail(function() {
|
|
|
+ structureFrame.find(".error-message").show()
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // #### Events
|
|
|
+
|
|
|
+ // Update query
|
|
|
+ form.on('submit', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+ updateQuery();
|
|
|
+ area = null;
|
|
|
+ currentPage = 1;
|
|
|
+ refresh();
|
|
|
+ if (Object.values(query).some((k) => k)) {
|
|
|
+ // if it's not an empty query, fit to results
|
|
|
+ fitMapToResults();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ submitButton.on('click', function() {
|
|
|
+ form.submit();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.filters select', form).on('change', function() {
|
|
|
+ form.submit();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Reset search fields
|
|
|
+ resetButton.on('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ let form = $(this).closest('form');
|
|
|
+ form.find('input').each(function () {
|
|
|
+ $(this).val('');
|
|
|
+ });
|
|
|
+ form.find('select').each(function () {
|
|
|
+ $(this).val('');
|
|
|
+ });
|
|
|
+ resetMapBounds();
|
|
|
+ form.submit();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Map goto commands
|
|
|
+ $('img[data-map-fit]').on('click', function (e) {
|
|
|
+ let goto = $(this).data('map-fit');
|
|
|
+ let corners = goto.split(";");
|
|
|
+ let p1 = corners[0].split(",");
|
|
|
+ let p2 = corners[1].split(",");
|
|
|
+ let bounds = L.latLngBounds(L.latLng(p1[0], p1[1]), L.latLng(p2[0], p2[1]));
|
|
|
+ map.fitBounds(bounds);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Toggle structures list and map view
|
|
|
+ let filtersRow = form.find('.filters').first();
|
|
|
+ let buttonsRow = form.find('.search-buttons').first();
|
|
|
+
|
|
|
+ $('.activate-map-view').on('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ if (structureFrame.hasClass('map-view')) {
|
|
|
+ // already in map view
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ structureFrame.removeClass('list-view');
|
|
|
+ structureFrame.addClass('map-view');
|
|
|
+
|
|
|
+ // move reset and submit buttons
|
|
|
+ submitButton.appendTo(buttonsRow);
|
|
|
+ resetButton.prependTo(buttonsRow);
|
|
|
+ buttonsRow.show();
|
|
|
+ })
|
|
|
+ $('.activate-list-view').on('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ if (structureFrame.hasClass('list-view')) {
|
|
|
+ // already in list view
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ structureFrame.removeClass('map-view');
|
|
|
+ structureFrame.addClass('list-view');
|
|
|
+
|
|
|
+ // move reset and submit buttons
|
|
|
+ submitButton.appendTo(filtersRow);
|
|
|
+ resetButton.prependTo(filtersRow);
|
|
|
+ buttonsRow.hide();
|
|
|
+
|
|
|
+ resetButton.prependTo()
|
|
|
+
|
|
|
+
|
|
|
+ resetMapBounds();
|
|
|
+ })
|
|
|
+
|
|
|
+ // Filter results on map moves
|
|
|
+ map.on('zoomend moveend', function(e) {
|
|
|
+ if (listenMapMoves) {
|
|
|
+ let bounds = map.getBounds();
|
|
|
+ updateArea(bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth())
|
|
|
+ refresh(true);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // ### Location filter
|
|
|
+ let addressApiUrl = "https://api-adresse.data.gouv.fr/search/?type=municipality&autocomplete=1&limit=5&q=";
|
|
|
+
|
|
|
+ let resultDropdownDiv = form.find('.city-search-dropdown').first();
|
|
|
+ let inputName = resultDropdownDiv.siblings("input[name='search-city']").first();
|
|
|
+ let inputLat = resultDropdownDiv.siblings("input[name='lat']").first();
|
|
|
+ let inputLong = resultDropdownDiv.siblings("input[name='long']").first();
|
|
|
+ let resultDiv = resultDropdownDiv.find('.city-search-results').first();
|
|
|
+ let loadingDiv = resultDropdownDiv.find('.city-search-loading').first();
|
|
|
+ let noResultDiv = resultDropdownDiv.find('.city-search-no-result').first();
|
|
|
+ let geolocButton = form.find("button[name='search-localize']").first();
|
|
|
+
|
|
|
+ function setNewLocation(name, long, lat) {
|
|
|
+ inputName.val(name);
|
|
|
+ inputLong.val(long);
|
|
|
+ inputLat.val(lat);
|
|
|
+ inputName.css("cursor", "pointer");
|
|
|
+ resultDropdownDiv.hide();
|
|
|
+ form.submit();
|
|
|
+ }
|
|
|
+
|
|
|
+ function hideCityResults() {
|
|
|
+ resultDropdownDiv.hide();
|
|
|
+ // if no city was selected, clear the input
|
|
|
+ if (!inputLat.val()) {
|
|
|
+ inputName.val('');
|
|
|
+ resultDiv.empty();
|
|
|
+ }
|
|
|
+ inputName.css("cursor", "inherit");
|
|
|
+ }
|
|
|
+
|
|
|
+ document.click(function() {
|
|
|
+ hideCityResults();
|
|
|
+ });
|
|
|
+
|
|
|
+ $(document).keyup(function(e) {
|
|
|
+ if(e.key === "Escape") {
|
|
|
+ hideCityResults();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ inputName.click(function(e) {
|
|
|
+ if (resultDiv.children('.city-search-item').length > 0) {
|
|
|
+ resultDropdownDiv.show();
|
|
|
+ }
|
|
|
+ e.stopPropagation();
|
|
|
+ });
|
|
|
+
|
|
|
+ resultDiv.on('click', '.city-search-item', function (e) {
|
|
|
+ setNewLocation($(this).text(), $(this).data("x"), $(this).data("y"))
|
|
|
+ e.stopPropagation();
|
|
|
+ });
|
|
|
+
|
|
|
+ inputName.on('click', function(e) {
|
|
|
+ if ($(this).is(":focus")) {
|
|
|
+ $(this).val('');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function populateCitySearchResults() {
|
|
|
+ let query = inputName.val();
|
|
|
+ let url = addressApiUrl + encodeURI(query);
|
|
|
+
|
|
|
+ if (!query) {
|
|
|
+ resultDropdownDiv.hide();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ inputLat.val('');
|
|
|
+ inputLong.val('');
|
|
|
+ loadingDiv.show();
|
|
|
+ resultDiv.empty();
|
|
|
+ resultDropdownDiv.show();
|
|
|
+ noResultDiv.hide();
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ type: 'GET',
|
|
|
+ url: url,
|
|
|
+ dataType: "json",
|
|
|
+ contentType: "application/json; charset=utf-8"
|
|
|
+ })
|
|
|
+ .done(function(res) {
|
|
|
+ let features = res.features;
|
|
|
+ if (!features.length > 0) {
|
|
|
+ noResultDiv.show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ features.forEach(function (f) {
|
|
|
+ let x = f.geometry.coordinates[0];
|
|
|
+ let y = f.geometry.coordinates[1];
|
|
|
+ let name = f.properties.name;
|
|
|
+ let postcode = f.properties.postcode;
|
|
|
+ let span = '<div class="city-search-item" data-x="' + x + '" data-y="' + y + '">' + name + ' (' + postcode + ')</div>';
|
|
|
+ resultDiv.append(span);
|
|
|
+ });
|
|
|
+ loadingDiv.hide();
|
|
|
+ })
|
|
|
+ .fail(function(e) {
|
|
|
+ console.error(e);
|
|
|
+ loadingDiv.hide();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var runningPopulate = null;
|
|
|
+
|
|
|
+ inputName.on('input', function(e) {
|
|
|
+ if (runningPopulate !== null) {
|
|
|
+ window.clearTimeout(runningPopulate)
|
|
|
+ }
|
|
|
+ runningPopulate = window.setTimeout(populateCitySearchResults, 300);
|
|
|
+ });
|
|
|
+
|
|
|
+ geolocButton.on('click', function(e) {
|
|
|
+ if (navigator.geolocation) {
|
|
|
+ navigator.geolocation.getCurrentPosition(
|
|
|
+ function (geoloc) {
|
|
|
+ setNewLocation(tr['around-me'], geoloc.coords.longitude, geoloc.coords.latitude)
|
|
|
+ e.stopPropagation();
|
|
|
+ },
|
|
|
+ function () {
|
|
|
+ alert(tr['geoloc-unavailable']);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ e.stopPropagation();
|
|
|
+ } else {
|
|
|
+ alert(tr['geoloc-unsupported']);
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|