All Downloads are FREE. Search and download functionalities are using the official Maven repository.

assets.js.main-template.js Maven / Gradle / Ivy

global.d3 = require('d3');
var YAML = require('js-yaml');
var Flatpickr = require('flatpickr');
require('flatpickr/dist/l10n');

var L = require('leaflet');
require('leaflet-contextmenu');
require('leaflet-loading');
require('leaflet.heightgraph');
var moment = require('moment');
require('./lib/leaflet_numbered_markers.js');

global.jQuery = require('jquery');
global.$ = global.jQuery;
require('./lib/jquery-ui-custom-1.12.0.min.js');
require('./lib/jquery.history.js');
require('./lib/jquery.autocomplete.js');

var ghenv = require("./config/options.js").options;
console.log(ghenv.environment);

var GHInput = require('./graphhopper/GHInput.js');
var GHRequest = require('./graphhopper/GHRequest.js');
var host = ghenv.routing.host;
if (!host) {
    if (location.port === '') {
        host = location.protocol + '//' + location.hostname;
    } else {
        host = location.protocol + '//' + location.hostname + ":" + location.port;
    }
}

var AutoComplete = require('./autocomplete.js');
if (ghenv.environment === 'development') {
    var autocomplete = AutoComplete.prototype.createStub();
} else {
    var autocomplete = new AutoComplete(ghenv.geocoding.host, ghenv.geocoding.api_key);
}

var mapLayer = require('./map.js');
var nominatim = require('./nominatim.js');
var routeManipulation = require('./routeManipulation.js');
var gpxExport = require('./gpxexport.js');
var messages = require('./messages.js');
var translate = require('./translate.js');

var format = require('./tools/format.js');
var urlTools = require('./tools/url.js');
var tileLayers = require('./config/tileLayers.js');
if(ghenv.with_tiles)
   tileLayers.enableVectorTiles();

var debug = false;
var ghRequest = new GHRequest(host, ghenv.routing.api_key);
var bounds = {};
var metaVersionInfo;

// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
if (global.window) {
    window.log = function () {
        log.history = log.history || [];   // store logs to an array for reference
        log.history.push(arguments);
        if (this.console && debug) {
            console.log(Array.prototype.slice.call(arguments));
        }
    };
}

$(document).ready(function (e) {
    // fixing cross domain support e.g in Opera
    jQuery.support.cors = true;

    gpxExport.addGpxExport(ghRequest);

    $("#flex-input-link").click(function() {
        $("#regular-input").toggle();
        $("#flex-input").toggle();
        // avoid default action, so use a different search button
        $("#searchButton").toggle();
        mapLayer.adjustMapSize();
    });
    $("#flex-example").click(function() {
         $("#flex-input-text").val("speed_factor:\n  road_class:\n    motorway: 0.8\npriority:\n  road_environment:\n    tunnel: 0.0\n  road_class:\n    residential: 0.7\n  max_weight:\n    \">3\": 0.0");
         return false;
    });

    var sendCustomData = function() {
       mapLayer.clearElevation();
       mapLayer.clearLayers();
       flagAll();

       var infoDiv = $("#info");
       infoDiv.empty();
       infoDiv.show();
       var routeResultsDiv = $("
"); infoDiv.append(routeResultsDiv); routeResultsDiv.html(' Search Route ...'); var inputText = $("#flex-input-text").val(); if(inputText.length < 5) { routeResultsDiv.html("Routing configuration too short"); return; } var points = []; for(var idx = 0; idx < ghRequest.route.size(); idx++) { var point = ghRequest.route.getIndex(idx); if (point.isResolved()) { points.push([point.lng, point.lat]); } else { routeResultsDiv.html("Unresolved points"); return; } } var jsonModel; try { jsonModel = inputText.indexOf("{") == 0? JSON.parse(inputText) : YAML.safeLoad(inputText); } catch(ex) { routeResultsDiv.html("Cannot parse " + inputText + " " + ex); return; } jsonModel.points = points; jsonModel.points_encoded = false; jsonModel.elevation = ghRequest.api_params.elevation; jsonModel.profile = ghRequest.api_params.profile; var request = JSON.stringify(jsonModel); $.ajax({ url: "/route-custom", type: "POST", contentType: 'application/json; charset=utf-8', dataType: "json", data: request, success: createRouteCallback(ghRequest, routeResultsDiv, "", true), error: function(err) { routeResultsDiv.html("Error response: cannot process input"); var json = JSON.parse(err.responseText); createRouteCallback(ghRequest, routeResultsDiv, "", true)(json); } }); }; $("#flex-input-text").keydown(function (e) { // CTRL+Enter if (e.ctrlKey && e.keyCode == 13) sendCustomData(); }); $("#flex-search-button").click(sendCustomData); if (isProduction()) $('#hosting').show(); var History = window.History; if (History.enabled) { History.Adapter.bind(window, 'statechange', function () { // No need for workaround? // Chrome and Safari always emit a popstate event on page load, but Firefox doesn’t // https://github.com/defunkt/jquery-pjax/issues/143#issuecomment-6194330 var state = History.getState(); console.log(state); initFromParams(state.data, true); }); } $('#locationform').submit(function (e) { // no page reload e.preventDefault(); mySubmit(); }); var urlParams = urlTools.parseUrlWithHisto(); if(urlParams.flex) $("#flex-input-link").click(); var customURL = urlParams.load_custom; if(customURL && ghenv.environment === 'development') $.ajax(customURL). done(function(data) { $("#flex-input-text").val(data); $("#flex-input-link").click(); }). fail(function(err) { console.log("Cannot load custom URL " + customURL); }); $.when(ghRequest.fetchTranslationMap(urlParams.locale), ghRequest.getInfo()) .then(function (arg1, arg2) { // init translation retrieved from first call (fetchTranslationMap) var translations = arg1[0]; autocomplete.setLocale(translations.locale); ghRequest.setLocale(translations.locale); translate.init(translations); // init bounding box from getInfo result var json = arg2[0]; var tmp = json.bbox; bounds.initialized = true; bounds.minLon = tmp[0]; bounds.minLat = tmp[1]; bounds.maxLon = tmp[2]; bounds.maxLat = tmp[3]; nominatim.setBounds(bounds); var profilesDiv = $("#profiles"); function createButton(profile, hide) { var vehicle = profile.vehicle; var profileName = profile.name; var button = $("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy