UNPKG

urbi-exhibitions

Version:
418 lines (417 loc) 11.1 kB
var z = Object.defineProperty; var w = (i, t, e) => t in i ? z(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e; var l = (i, t, e) => w(i, typeof t != "symbol" ? t + "" : t, e); import { c as H, a as G, g as j, p as J, r as K } from "../routeCaching-BdIWvpHb.js"; function Y(i) { const t = i.models[0]; return { modelId: t.name, isDark: !!i.isDark, coordinates: i.coords, linkedIds: i.buildingIds, scale: i.scale, rotateX: i.rotateX * 180, rotateY: i.rotateY * 180, rotateZ: i.rotateZ * 180, offsetX: i.moveX / 100, offsetY: i.moveY / 100, offsetZ: i.moveZ / 100, modelUrl: t.path }; } function L(i) { return { rotateX: i.rotateX * 180, rotateY: i.rotateY * 180, rotateZ: i.rotateZ * 180, offsetX: i.moveX / 100, offsetY: i.moveY / 100, offsetZ: i.moveZ / 100 }; } var c = 63710088e-1, E = { centimeters: c * 100, centimetres: c * 100, degrees: 360 / (2 * Math.PI), feet: c * 3.28084, inches: c * 39.37, kilometers: c / 1e3, kilometres: c / 1e3, meters: c, metres: c, miles: c / 1609.344, millimeters: c * 1e3, millimetres: c * 1e3, nauticalmiles: c / 1852, radians: 1, yards: c * 1.0936 }; function D(i, t, e = {}) { const o = { type: "Feature" }; return (e.id === 0 || e.id) && (o.id = e.id), e.bbox && (o.bbox = e.bbox), o.properties = t || {}, o.geometry = i, o; } function f(i, t, e = {}) { if (!i) throw new Error("coordinates is required"); if (!Array.isArray(i)) throw new Error("coordinates must be an Array"); if (i.length < 2) throw new Error("coordinates must be at least 2 numbers long"); if (!v(i[0]) || !v(i[1])) throw new Error("coordinates must contain numbers"); return D({ type: "Point", coordinates: i }, t, e); } function A(i, t = "kilometers") { const e = E[t]; if (!e) throw new Error(t + " units is invalid"); return i * e; } function P(i, t = "kilometers") { const e = E[t]; if (!e) throw new Error(t + " units is invalid"); return i / e; } function p(i) { return i % (2 * Math.PI) * 180 / Math.PI; } function m(i) { return i % 360 * Math.PI / 180; } function v(i) { return !isNaN(i) && i !== null && !Array.isArray(i); } function M(i) { if (!i) throw new Error("coord is required"); if (!Array.isArray(i)) { if (i.type === "Feature" && i.geometry !== null && i.geometry.type === "Point") return [...i.geometry.coordinates]; if (i.type === "Point") return [...i.coordinates]; } if (Array.isArray(i) && i.length >= 2 && !Array.isArray(i[0]) && !Array.isArray(i[1])) return [...i]; throw new Error("coord must be GeoJSON Point or an Array of numbers"); } function Z(i, t, e = {}) { if (e.final === !0) return R(i, t); const o = M(i), r = M(t), u = m(o[0]), n = m(r[0]), s = m(o[1]), a = m(r[1]), h = Math.sin(n - u) * Math.cos(a), g = Math.cos(s) * Math.sin(a) - Math.sin(s) * Math.cos(a) * Math.cos(n - u); return p(Math.atan2(h, g)); } function R(i, t) { let e = Z(t, i); return e = (e + 180) % 360, e; } var T = Z; function O(i, t, e = {}) { var o = M(i), r = M(t), u = m(r[1] - o[1]), n = m(r[0] - o[0]), s = m(o[1]), a = m(r[1]), h = Math.pow(Math.sin(u / 2), 2) + Math.pow(Math.sin(n / 2), 2) * Math.cos(s) * Math.cos(a); return A( 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)), e.units ); } var I = O; function x(i, t, e, o = {}) { const r = M(i), u = m(r[0]), n = m(r[1]), s = m(e), a = P(t, o.units), h = Math.asin( Math.sin(n) * Math.cos(a) + Math.cos(n) * Math.sin(a) * Math.cos(s) ), g = u + Math.atan2( Math.sin(s) * Math.sin(a) * Math.cos(n), Math.cos(a) - Math.sin(n) * Math.sin(h) ), d = p(g), y = p(h); return f([d, y], o.properties); } function _(i, t) { const e = O(i, t), o = Z(i, t); return x(i, e / 2, o); } var N = _; const S = { zoomInOutTime: 1e3, defaultRotationDuration: 4e3, defaultZoom: 18.5, defaultPitch: 55, step: 150 }, F = 600, B = 5e3, C = 120, X = 60 * 60 * 1e3; class Q { constructor({ zoom: t, maxZoom: e, minZoom: o, center: r, pitch: u, rotation: n, baseDuration: s, maxZoomDuration: a, buildingFlightOption: h }) { l(this, "zoom"); l(this, "maxZoom"); l(this, "minZoom"); l(this, "center"); l(this, "pitch"); l(this, "rotation"); l(this, "baseDuration"); l(this, "maxZoomDuration"); l(this, "zoomAmplitude"); l(this, "buildingFlightOption"); l(this, "flightId"); l(this, "activeFlightMap"); this.zoom = t, this.maxZoom = e, this.minZoom = o, this.center = r, this.pitch = u, this.rotation = n, this.baseDuration = s || F, this.maxZoomDuration = a || B, this.zoomAmplitude = e - o, this.buildingFlightOption = { ...S, ...h || {} }, this.flightId = 0, this.activeFlightMap = {}; } getInitialMapOptions() { return { zoom: this.zoom, maxZoom: this.maxZoom, minZoom: this.minZoom, center: this.center, pitch: this.pitch, rotation: this.rotation }; } getFlightId() { return ++this.flightId; } waitIdle(t) { return new Promise((e) => { t && t.once("idle", e); }); } sleep(t) { return new Promise((e) => { setTimeout(e, t); }); } abortFlights() { for (const t in this.activeFlightMap) this.activeFlightMap[t] = !1; } async runFlight(t, e, o = !1) { this.abortFlights(); const r = this.getFlightId(); this.activeFlightMap[r] = !0; for (let u = 0; u < e.length; u++) { if (!this.activeFlightMap[r]) return; const n = e[u]; o && console.log(n, u); const s = n.duration || 0; if (n.center) { const a = { duration: s }; n.centerEasing && (a.easing = n.centerEasing), t.setCenter(n.center, a); } if (n.styleZoom !== void 0) { const a = { duration: s, useHeightForAnimation: !0 }; n.styleZoomEasing && (a.easing = n.styleZoomEasing), t.setStyleZoom(n.styleZoom, a); } else if (n.zoom !== void 0) { const a = { duration: s, useHeightForAnimation: !0 }; n.zoomEasing && (a.easing = n.zoomEasing), t.setZoom(n.zoom, a); } if (n.pitch !== void 0) { const a = { duration: s }; n.pitchEasing && (a.easing = n.pitchEasing), t.setPitch( (n.incremental ? t.getPitch() : 0) + n.pitch, a ); } if (n.rotation !== void 0) { const a = { duration: n.rotationDuration ?? s }; n.rotationEasing && (a.easing = n.rotationEasing), t.setRotation( (n.incremental ? t.getRotation() : 0) + n.rotation, { ...a, normalize: n.rotationNormalize ?? !0 } ); } typeof n.f == "function" && n.f(), n.waitIdle ? await this.waitIdle(t) : await this.sleep(s); } } getBuildingBaseFlight({ center: t, styleZoom: e, pitch: o, ...r }) { const u = r.rotationDuration ?? this.buildingFlightOption.defaultRotationDuration; return [ { duration: this.buildingFlightOption.zoomInOutTime, center: t, styleZoom: e ?? this.buildingFlightOption.defaultZoom, pitch: o ?? this.buildingFlightOption.defaultPitch }, { duration: u / 2, rotationEasing: "easeInSine", rotation: -this.buildingFlightOption.step, incremental: !0 }, { duration: u / 2, rotationEasing: "easeOutSine", rotation: -this.buildingFlightOption.step, incremental: !0 } ]; } runBuildingFlight(t, e, o) { const r = [ ...this.getBuildingBaseFlight(e), { duration: this.buildingFlightOption.zoomInOutTime, styleZoom: t.getStyleZoom(), pitch: t.getPitch(), rotation: t.getRotation() }, { f: o } ]; return this.runFlight(t, r); } flyToOpts(t, e = {}, o) { const r = [ { duration: 2e3, centerEasing: e.easing ?? "easeInOutQuad", zoomEasing: e.easing ?? "easeInOutQuad", styleZoomEasing: e.easing ?? "easeInOutQuad", rotationNormalize: !0, ...e } ]; return o && r.push({ f: o }), this.runFlight(t, r); } getZoomParams({ from: t = this.zoom, to: e = this.zoom }) { const o = t - e; return { duration: this.maxZoomDuration * Math.abs(o) / this.zoomAmplitude, dir: o > 0 ? "out" : "in", easing: o > 0 ? "easeInQuart" : "easeOutQuart" }; } getZoomPart({ from: t = this.zoom, to: e = this.zoom }) { const { duration: o, easing: r } = this.getZoomParams({ from: t, to: e }); return { duration: o, zoom: e, zoomEasing: r }; } getMoveCenterOnMaxZoomPart(t) { return t ? { duration: 2 * F, center: t, centerEasing: "easeInOutQuad" } : {}; } getMoveCenter(t, { to: e, ...o }) { if (!e) return {}; const r = o.from ?? t.getCenter(); return { duration: I(t.project(r), t.project(e)) / 5, center: e, centerEasing: "easeInOutQuad" }; } getZoomToOpts({ from: t = this.zoom, opts: e }) { if (!e || !e.zoom) return {}; const { duration: o, easing: r } = this.getZoomParams({ from: t, to: e.zoom }); return { duration: o < this.baseDuration ? this.baseDuration : o, zoom: e.zoom, pitch: e.pitch, center: e.center, rotation: e.rotation, centerEasing: r }; } resetMapRestrictions(t) { t.setMaxZoom(this.maxZoom), t.setMinZoom(this.minZoom); } getLineFlight(t, { speed: e = C, distanceLimit: o = 1 / 0, restrictRotationDuration: r = !1, logResult: u = !1, cb: n }) { const s = []; let a = 0, h = 0; for (let g = 0; g < t.length - 1; g++) { const d = I(t[g], t[g + 1]); if (d === 0) continue; h += d, a = T( f(t[g]), f(t[g + 1]) ); const b = d / e * X; if (s.push({ rotation: -a, rotationDuration: r && b > 500 ? 500 : void 0, rotationNormalize: !0, // Дистанция в "км", так как для turfDistance, км - дефолт! traveledDistance: h, duration: b, center: t[g + 1], centerEasing: "linear", waitIdle: g === 0 }), n && s.push({ traveledDistance: h, f: function() { n(this.traveledDistance); } }), h > o) break; } return u && console.log(s), { flight: s, speed: e, distance: h }; } getMidpoint(t, e) { const o = f(t), r = f(e); return N(o, r).geometry.coordinates; } } export { Q as MapFlight, H as clearRoutesCache, L as convertModelParams, Y as convertModelToCS, G as getRouteCache, j as getRouteStringKey, J as prefetchRoutes, K as routesCache };