UNPKG

urbi-exhibitions

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