PageSourceSearch

https://geliospro.com/js/libs/graphhopper.js

js geliospro.com collected 2026-10-07 10:51:56 UTC 16,164 bytes, 337 lines download raw bytes

1(function e(t, n, r) {
2    function s(o, u) {
3        if (!n[o]) {
4            if (!t[o]) {
5                var a = typeof require == "function" && require;
6                if (!u && a) return a(o, !0);
7                if (i) return i(o, !0);
8                var f = new Error("Cannot find module '" + o + "'");
9                throw f.code = "MODULE_NOT_FOUND", f
10            }
11            var l = n[o] = {exports: {}};
12            t[o][0].call(l.exports, function (e) {
13                var n = t[o][1][e];
14                return s(n ? n : e)
15            }, l, l.exports, e, t, n, r)
16        }
17        return n[o].exports
18    }
19
20    var i = typeof require == "function" && require;
21    for (var o = 0; o < r.length; o++) s(r[o]);
22    return s
23})({
24    1: [function (require, module, exports) {
25        function corslite(url, callback, cors) {
26            var sent = false;
27            if (typeof window.XMLHttpRequest === "undefined") {
28                return callback(Error("Browser not supported"))
29            }
30            if (typeof cors === "undefined") {
31                var m = url.match(/^\s*https?:\/\/[^\/]*/);
32                cors = m && m[0] !== location.protocol + "//" + location.domain + (location.port ? ":" + location.port : "")
33            }
34            var x = new window.XMLHttpRequest;
35
36            function isSuccessful(status) {
37                return status >= 200 && status < 300 || status === 304
38            }
39
40            if (cors && !("withCredentials" in x)) {
41                x = new window.XDomainRequest;
42                var original = callback;
43                callback = function () {
44                    if (sent) {
45                        original.apply(this, arguments)
46                    } else {
47                        var that = this, args = arguments;
48                        setTimeout(function () {
49                            original.apply(that, args)
50                        }, 0)
51                    }
52                }
53            }
54
55            function loaded() {
56                if (x.status === undefined || isSuccessful(x.status)) callback.call(x, null, x); else callback.call(x, x, null)
57            }
58
59            if ("onload" in x) {
60                x.onload = loaded
61            } else {
62                x.onreadystatechange = function readystate() {
63                    if (x.readyState === 4) {
64                        loaded()
65                    }
66                }
67            }
68            x.onerror = function error(evt) {
69                callback.call(this, evt || true, null);
70                callback = function () {
71                }
72            };
73            x.onprogress = function () {
74            };
75            x.ontimeout = function (evt) {
76                callback.call(this, evt, null);
77                callback = function () {
78                }
79            };
80            x.onabort = function (evt) {
81                callback.call(this, evt, null);
82                callback = function () {
83                }
84            };
85            x.open("GET", url, true);
86            x.send(null);
87            sent = true;
88            return x
89        }
90
91        if (typeof module !== "undefined") module.exports = corslite
92    }, {}], 2: [function (require, module, exports) {
93        var polyline = {};
94
95        function encode(coordinate, factor) {
96            coordinate = Math.round(coordinate * factor);
97            coordinate <<= 1;
98            if (coordinate < 0) {
99                coordinate = ~coordinate
100            }
101            var output = "";
102            while (coordinate >= 32) {
103                output += String.fromCharCode((32 | coordinate & 31) + 63);
104                coordinate >>= 5
105            }
106            output += String.fromCharCode(coordinate + 63);
107            return output
108        }
109
110        polyline.decode = function (str, precision) {
111            var index = 0, lat = 0, lng = 0, coordinates = [], shift = 0, result = 0, byte = null, latitude_change,
112                longitude_change, factor = Math.pow(10, precision || 5);
113            while (index < str.length) {
114                byte = null;
115                shift = 0;
116                result = 0;
117                do {
118                    byte = str.charCodeAt(index++) - 63;
119                    result |= (byte & 31) << shift;
120                    shift += 5
121                } while (byte >= 32);
122                latitude_change = result & 1 ? ~(result >> 1) : result >> 1;
123                shift = result = 0;
124                do {
125                    byte = str.charCodeAt(index++) - 63;
126                    result |= (byte & 31) << shift;
127                    shift += 5
128                } while (byte >= 32);
129                longitude_change = result & 1 ? ~(result >> 1) : result >> 1;
130                lat += latitude_change;
131                lng += longitude_change;
132                coordinates.push([lat / factor, lng / factor])
133            }
134            return coordinates
135        };
136        polyline.encode = function (coordinates, precision) {
137            if (!coordinates.length) return "";
138            var factor = Math.pow(10, precision || 5),
139                output = encode(coordinates[0][0], factor) + encode(coordinates[0][1], factor);
140            for (var i = 1; i < coordinates.length; i++) {
141                var a = coordinates[i], b = coordinates[i - 1];
142                output += encode(a[0] - b[0], factor);
143                output += encode(a[1] - b[1], factor)
144            }
145            return output
146        };
147        if (typeof module !== undefined) module.exports = polyline
148    }, {}
148], 3: [function (require, module, exports) {
149        (function (global) {
150            (function () {
151                "use strict";
152                var L = typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null;
153                var corslite = require("corslite");
154                var polyline = require("polyline");
155                L.Routing = L.Routing || {};
156                L.Routing.GraphHopper = L.Evented.extend({
157                    options: {serviceUrl: "https://graphhopper.com/api/1/route", timeout: 30 * 1e3, urlParameters: {}},
158                    initialize: function (options) {
159                        L.Util.setOptions(this, options)
160                    },
161                    route: function (waypoints, callback, context, options) {
162                        var timedOut = false, wps = [], url, timer, wp, i;
163                        options = options || {};
164                        url = this.buildRouteUrl(waypoints, options);
165                        timer = setTimeout(function () {
166                            timedOut = true;
167                            callback.call(context || callback, {status: -1, message: "GraphHopper request timed out."})
168                        }, this.options.timeout);
169                        for (i = 0; i < waypoints.length; i++) {
170                            wp = waypoints[i];
171                            wps.push({latLng: wp.latLng, name: wp.name, options: wp.options})
172                        }
173                        corslite(url, L.bind(function (err, resp) {
174                            var data;
175                            clearTimeout(timer);
176                            if (!timedOut) {
177                                var fired = err ? err : resp;
178                                this.fire("response", {
179                                    status: fired.status
180                                });
181                                if (!err) {
182                                    data = JSON.parse(resp.responseText);
183                                    this._routeDone(data, wps, callback, context)
184                                } else {
185                                    var finalResponse;
186                                    var responseText = err && err.responseText;
187                                    try {
188                                        finalResponse = JSON.parse(responseText)
189                                    } catch (e) {
190                                        finalResponse = responseText
191                                    }
192                                    callback.call(context || callback, {
193                                        status: -1,
194                                        message: "HTTP request failed: " + err,
195                                        response: finalResponse
196                                    })
197                                }
198                            }
199                        }, this));
200                        return this
201                    },
202                    _routeDone: function (response, inputWaypoints, callback, context) {
203                        var alts = [], mappedWaypoints, coordinates, i, path, actualWaypoints;
204                        context = context || callback;
205                        if (response.info.errors && response.info.errors.length) {
206                            callback.call(context, {
207                                status: response.info.errors[0].details,
208                                message: response.info.errors[0].message
209                            });
210                            return
211                        }
212                        for (i = 0; i < response.paths.length; i++) {
213                            path = response.paths[i];
214                            coordinates = this._decodePolyline(path.points);
215                            mappedWaypoints = this._mapWaypointIndices(inputWaypoints, path.instructions, coordinates);
216                            alts.push({
217                                name: "",
218                                coordinates: coordinates,
219                                instructions: this._convertInstru
219ctions(path.instructions),
220                                summary: {
221                                    totalDistance: path.distance,
222                                    totalTime: path.time / 1e3,
223                                    totalAscend: path.ascend
224                                },
225                                inputWaypoints: inputWaypoints,
226                                actualWaypoints: mappedWaypoints.waypoints,
227                                waypointIndices: mappedWaypoints.waypointIndices
228                            })
229                        }
230                        var dropRoutingInd = [];
231                        var i;
232                        for (i = 0; i < inputWaypoints.length - 1; i++) {
233                            if (inputWaypoints[i].options.isManual) {
234                                dropRoutingInd.push(i);
235                            }
236                        }
237
238                            for (i = 0; i < dropRoutingInd.length; i++) {
239                                var dropRouting = dropRoutingInd[i],
240                                    deleted = false;
241                                for (var j = 0; j < mappedWaypoints.waypointIndices.length; j++) {
242                                    if (deleted !== false) {
243                                        mappedWaypoints.waypointIndices[j] = mappedWaypoints.waypointIndices[j] - deleted;
244                                    }
245                                    if (j === dropRouting) {
246                                        deleted = coordinates.splice(mappedWaypoints.waypointIndices[j] + 1, mappedWaypoints.waypointIndices[j + 1] - mappedWaypoints.waypointIndices[j] - 1);
247                                        deleted = deleted.length;
248                                        coordinates[mappedWaypoints.waypointIndices[j] + 1] = inputWaypoints[dropRoutingInd[i] + 1].latLng;
249                                    }
250                                }
251                            }
252
253                        callback.call(context, null, alts)
254
255                    },
256                    _decodePolyline: function (geometry) {
257                        var coords = polyline.decode(geometry, 5), latlngs = new Array(coords.length), i;
258                        for (i = 0; i < coords.length; i++) {
259                            latlngs[i] = new L.LatLng(coords[i][0], coords[i][1])
260                        }
261                        return latlngs
262                    },
263                    _toWaypoints: function (inputWaypoints, vias) {
264                        var wps = [], i;
265                        for (i = 0; i < vias.length; i++) {
266                            wps.push({
267                                latLng: L.latLng(vias[i]),
268                                name: inputWaypoints[i].name,
269                                options: inputWaypoints[i].options
270                            })
271                        }
272                        return wps
273                    },
274                    buildRouteUrl: function (waypoints, options) {
275                        var computeInstructions = true, locs = [], i, baseUrl;
276                        for (i = 0; i < waypoints.length; i++) {
277                            locs.push("point=" + waypoints[i].latLng.lat + "," + waypoints[i].latLng.lng)
278                        }
279                        baseUrl = this.options.serviceUrl + "?" + locs.join("&");
280                        return baseUrl + L.Util.getParamString(L.extend({
281                            instructions: computeInstructions,
282                            type: "json",
283                        }, this.options.urlParameters), baseUrl)
284                    },
285                    _convertInstructions: function (instructions) {
286                        var signToType = {
287                            "-3": "SharpLeft",
288                            "-2": "Left",
289                            "-1": "SlightLeft",
290                            0: "Straight",
291                            1: "SlightRight",
292                            2: "Right",
293                            3: "SharpRight",
294                            4: "DestinationReached",
295                            5: "WaypointReached",
296                            6: "Roundabout"
297                        }, result = [], i, instr;
298                        for (i = 0; instructions && i < instructions.length; i++) {
299                            instr = instructions[i];
300                            result.push({
301                                type: signToType[instr.sign],
302                                text: instr.text,
303                                distance: instr.distance,
304                                time: instr.time / 1e3,
305                                index: instr.interval[0],
306                                exit: instr.exit_number
307                            })
308                        }
309                        return result
310                    },
311                    _mapWaypointIndices: function (waypoints, instructions, coordinates) {
312                        var wps = [], wpIndices = [], i, idx;
313                        wpIndices.push(0);
314                        wps.push(new L.Routing.Waypoint(coordinates[0], waypoints[0].name));
315                        for (i = 0; instructions && i < instructions.length; i++) {
316                            if (instructions[i].sign === 5) {
317                                idx = instructions[i].interval[0];
318                                wpIndices.push(idx);
319                                wps.push({latLng: coordinates[idx], name: waypoints[wps.length + 1].name})
320                            }
321                        }
322                        wpIndices.push(coordinates.length - 1);
323                        wps.push({
324                            latLng: coordinates[coordinates.length - 1],
325                            name: waypoints[waypoints.length - 1].name
326                        });
327                        return {waypointIndices: wpIndices, waypoints: wps}
328                    }
329                });
330                L.Routing.graphHopper = function (options) {
331                    return new L.Routing.GraphHopper(options)
332                };
333                module.exports = L.Routing.GraphHopper
334            })()
335        }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
336    }, {corslite: 1, polyline: 2}]
337}, {}, [3]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.