@antv/l7-map 2.5.25 → 2.5.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/es/earthmap.d.ts +67 -0
  2. package/es/earthmap.js +454 -0
  3. package/es/earthmap.js.map +1 -0
  4. package/es/handler/IHandler.d.ts +2 -1
  5. package/es/handler/blockable_map_event.d.ts +2 -1
  6. package/es/handler/blockable_map_event.js.map +1 -1
  7. package/es/handler/box_zoom.d.ts +2 -1
  8. package/es/handler/box_zoom.js.map +1 -1
  9. package/es/handler/click_zoom.d.ts +2 -1
  10. package/es/handler/click_zoom.js.map +1 -1
  11. package/es/handler/events/map_mouse_event.d.ts +3 -2
  12. package/es/handler/events/map_mouse_event.js.map +1 -1
  13. package/es/handler/events/map_touch_event.d.ts +3 -2
  14. package/es/handler/events/map_touch_event.js.map +1 -1
  15. package/es/handler/events/map_wheel_event.d.ts +4 -3
  16. package/es/handler/events/map_wheel_event.js.map +1 -1
  17. package/es/handler/handler_inertia.d.ts +2 -1
  18. package/es/handler/handler_inertia.js.map +1 -1
  19. package/es/handler/handler_manager.d.ts +2 -1
  20. package/es/handler/handler_manager.js.map +1 -1
  21. package/es/handler/keyboard.d.ts +2 -1
  22. package/es/handler/keyboard.js.map +1 -1
  23. package/es/handler/map_event.d.ts +2 -1
  24. package/es/handler/map_event.js.map +1 -1
  25. package/es/handler/scroll_zoom.d.ts +2 -1
  26. package/es/handler/scroll_zoom.js.map +1 -1
  27. package/es/handler/tap/tap_zoom.d.ts +2 -1
  28. package/es/handler/tap/tap_zoom.js.map +1 -1
  29. package/es/hash.d.ts +2 -1
  30. package/es/hash.js.map +1 -1
  31. package/es/index.d.ts +1 -0
  32. package/es/index.js +1 -0
  33. package/es/index.js.map +1 -1
  34. package/lib/earthmap.js +465 -0
  35. package/lib/earthmap.js.map +1 -0
  36. package/lib/handler/blockable_map_event.js.map +1 -1
  37. package/lib/handler/box_zoom.js.map +1 -1
  38. package/lib/handler/click_zoom.js.map +1 -1
  39. package/lib/handler/events/map_mouse_event.js.map +1 -1
  40. package/lib/handler/events/map_touch_event.js.map +1 -1
  41. package/lib/handler/events/map_wheel_event.js.map +1 -1
  42. package/lib/handler/handler_inertia.js.map +1 -1
  43. package/lib/handler/handler_manager.js.map +1 -1
  44. package/lib/handler/keyboard.js.map +1 -1
  45. package/lib/handler/map_event.js.map +1 -1
  46. package/lib/handler/scroll_zoom.js.map +1 -1
  47. package/lib/handler/tap/tap_zoom.js.map +1 -1
  48. package/lib/hash.js.map +1 -1
  49. package/lib/index.js +13 -0
  50. package/lib/index.js.map +1 -1
  51. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handler/scroll_zoom.ts"],"names":["LngLat","bezier","ease","interpolate","now","DOM","wheelZoomDelta","defaultZoomRate","wheelZoomRate","maxScalePerFrame","ScrollZoomHandler","map","handler","frameId","isActive","tr","transform","delta","zoomRate","type","Math","abs","scale","exp","fromScale","targetZoom","zoomScale","min","maxZoom","max","minZoom","scaleZoom","startZoom","zoom","easing","smoothOutEasing","finished","t","lastWheelEventTime","k","active","finishTimeout","setTimeout","zooming","triggerRenderFrame","noInertia","needsRenderFrame","zoomDelta","around","aroundPoint","originalEvent","lastWheelEvent","el","getCanvasContainer","enabled","undefined","options","isEnabled","aroundCenter","e","value","deltaMode","window","WheelEvent","DOM_DELTA_LINE","deltaY","nowTime","timeDelta","lastValue","timeout","onTimeout","clearTimeout","shiftKey","start","preventDefault","onScrollFrame","initialEvent","isZooming","pos","mousePos","convert","getCenter","unproject","locationPoint","duration","prevEase","preEase","speed","x","sqrt","y"],"mappings":";;;AACA,OAAOA,MAAP,MAAmB,gBAAnB;AAGA,SAASC,MAAT,EAAiBC,IAAjB,EAAuBC,WAAvB,EAAoCC,GAApC,QAA+C,SAA/C;AACA,OAAOC,GAAP,MAAgB,cAAhB;AAIA,IAAMC,cAAc,GAAG,cAAvB;AAIA,IAAMC,eAAe,GAAG,I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AAG,EADI;AAEdgF,QAAAA,QAAQ,EAARA,QAFc;AAGdlD,QAAAA,MAAM,EAANA;AAHc,OAAhB;AAMA,aAAOA,MAAP;AACD;;;;;;AAGH,eAAexB,iBAAf","sourcesContent":["// @ts-ignore\nimport LngLat from '../geo/lng_lat';\nimport Point from '../geo/point';\nimport { Map } from '../map';\nimport { bezier, ease, interpolate, now } from '../util';\nimport DOM from '../utils/dom';\nimport HandlerManager from './handler_manager';\n\n// deltaY value for mouse scroll wheel identification\nconst wheelZoomDelta = 4.000244140625;\n\n// These magic numbers control the rate of zoom. Trackpad events fire at a greater\n// frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick\nconst defaultZoomRate = 1 / 100;\nconst wheelZoomRate = 1 / 450;\n\n// upper bound on how much we scale the map in any single render frame; this\n// is used to limit zoom rate in the case of very fast scrolling\nconst maxScalePerFrame = 2;\n\n/**\n * The `ScrollZoomHandler` allows the user to zoom the map by scrolling.\n */\nclass ScrollZoomHandler {\n private map: Map;\n private el: HTMLElement;\n private enabled: boolean;\n private active: boolean;\n private zooming: boolean;\n private aroundCenter: boolean;\n private around: LngLat;\n private aroundPoint: Point;\n private type: 'wheel' | 'trackpad' | null;\n private lastValue: number;\n private timeout: number | null; // used for delayed-handling of a single wheel movement\n private finishTimeout: number; // used to delay final '{move,zoom}end' events\n\n private lastWheelEvent: any;\n private lastWheelEventTime: number;\n\n private startZoom: number;\n private targetZoom: number;\n private delta: number;\n private easing: (time: number) => number;\n private prevEase: {\n start: number;\n duration: number;\n easing: (_: number) => number;\n };\n\n private frameId: boolean | null;\n private handler: HandlerManager;\n\n private defaultZoomRate: number;\n private wheelZoomRate: number;\n\n /**\n * @private\n */\n constructor(map: Map, handler: HandlerManager) {\n this.map = map;\n this.el = map.getCanvasContainer();\n this.handler = handler;\n\n this.delta = 0;\n this.defaultZoomRate = defaultZoomRate;\n this.wheelZoomRate = wheelZoomRate;\n }\n\n /**\n * Set the zoom rate of a trackpad\n * @param {number} [zoomRate=1/100] The rate used to scale trackpad movement to a zoom value.\n * @example\n * // Speed up trackpad zoom\n * map.scrollZoom.setZoomRate(1/25);\n */\n public setZoomRate(zoomRate: number) {\n this.defaultZoomRate = zoomRate;\n }\n\n /**\n * Set the zoom rate of a mouse wheel\n * @param {number} [wheelZoomRate=1/450] The rate used to scale mouse wheel movement to a zoom value.\n * @example\n * // Slow down zoom of mouse wheel\n * map.scrollZoom.setWheelZoomRate(1/600);\n */\n public setWheelZoomRate(zoomRate: number) {\n this.wheelZoomRate = zoomRate;\n }\n\n /**\n * Returns a Boolean indicating whether the \"scroll to zoom\" interaction is enabled.\n *\n * @returns {boolean} `true` if the \"scroll to zoom\" interaction is enabled.\n */\n public isEnabled() {\n return !!this.enabled;\n }\n\n /*\n * Active state is turned on and off with every scroll wheel event and is set back to false before the map\n * render is called, so _active is not a good candidate for determining if a scroll zoom animation is in\n * progress.\n */\n public isActive() {\n return !!this.active || this.finishTimeout !== undefined;\n }\n\n public isZooming() {\n return !!this.zooming;\n }\n\n /**\n * Enables the \"scroll to zoom\" interaction.\n *\n * @param {Object} [options] Options object.\n * @param {string} [options.around] If \"center\" is passed, map will zoom around center of map\n *\n * @example\n * map.scrollZoom.enable();\n * @example\n * map.scrollZoom.enable({ around: 'center' })\n */\n public enable(options?: any) {\n if (this.isEnabled()) {\n return;\n }\n this.enabled = true;\n this.aroundCenter = options && options.around === 'center';\n }\n\n /**\n * Disables the \"scroll to zoom\" interaction.\n *\n * @example\n * map.scrollZoom.disable();\n */\n public disable() {\n if (!this.isEnabled()) {\n return;\n }\n this.enabled = false;\n }\n\n public wheel(e: WheelEvent) {\n if (!this.isEnabled()) {\n return;\n }\n // Remove `any` cast when https://github.com/facebook/flow/issues/4879 is fixed.\n let value =\n e.deltaMode === window.WheelEvent.DOM_DELTA_LINE\n ? e.deltaY * 40\n : e.deltaY;\n const nowTime = now();\n const timeDelta = nowTime - (this.lastWheelEventTime || 0);\n\n this.lastWheelEventTime = nowTime;\n\n if (value !== 0 && value % wheelZoomDelta === 0) {\n // This one is definitely a mouse wheel event.\n this.type = 'wheel';\n } else if (value !== 0 && Math.abs(value) < 4) {\n // This one is definitely a trackpad event because it is so small.\n this.type = 'trackpad';\n } else if (timeDelta > 400) {\n // This is likely a new scroll action.\n this.type = null;\n this.lastValue = value;\n\n // Start a timeout in case this was a singular event, and dely it by up to 40ms.\n // @ts-ignore\n this.timeout = setTimeout(this.onTimeout, 40, e);\n } else if (!this.type) {\n // This is a repeating event, but we don't know the type of event just yet.\n // If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.\n this.type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';\n\n // Make sure our delayed event isn't fired again, because we accumulate\n // the previous event (which was less than 40ms ago) into this event.\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n value += this.lastValue;\n }\n }\n\n // Slow down zoom if shift key is held for more precise zooming\n if (e.shiftKey && value) {\n value = value / 4;\n }\n // Only fire the callback if we actually know what type of scrolling device the user uses.\n if (this.type) {\n this.lastWheelEvent = e;\n this.delta -= value;\n if (!this.active) {\n this.start(e);\n }\n }\n\n e.preventDefault();\n }\n\n public renderFrame() {\n return this.onScrollFrame();\n }\n\n public reset() {\n this.active = false;\n }\n\n private onScrollFrame = () => {\n if (!this.frameId) {\n return;\n }\n this.frameId = null;\n\n if (!this.isActive()) {\n return;\n }\n const tr = this.map.transform;\n\n // if we've had scroll events since the last render frame, consume the\n // accumulated delta, and update the target zoom level accordingly\n if (this.delta !== 0) {\n // For trackpad events and single mouse wheel ticks, use the default zoom rate\n const zoomRate =\n this.type === 'wheel' && Math.abs(this.delta) > wheelZoomDelta\n ? this.wheelZoomRate\n : this.defaultZoomRate;\n // Scale by sigmoid of scroll wheel delta.\n let scale =\n maxScalePerFrame / (1 + Math.exp(-Math.abs(this.delta * zoomRate)));\n\n if (this.delta < 0 && scale !== 0) {\n scale = 1 / scale;\n }\n\n const fromScale =\n typeof this.targetZoom === 'number'\n ? tr.zoomScale(this.targetZoom)\n : tr.scale;\n this.targetZoom = Math.min(\n tr.maxZoom,\n Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)),\n );\n\n // if this is a mouse wheel, refresh the starting zoom and easing\n // function we're using to smooth out the zooming between wheel\n // events\n if (this.type === 'wheel') {\n this.startZoom = tr.zoom;\n this.easing = this.smoothOutEasing(200);\n }\n\n this.delta = 0;\n }\n\n const targetZoom =\n typeof this.targetZoom === 'number' ? this.targetZoom : tr.zoom;\n const startZoom = this.startZoom;\n const easing = this.easing;\n\n let finished = false;\n let zoom;\n if (this.type === 'wheel' && startZoom && easing) {\n const t = Math.min((now() - this.lastWheelEventTime) / 200, 1);\n const k = easing(t);\n zoom = interpolate(startZoom, targetZoom, k);\n if (t < 1) {\n if (!this.frameId) {\n this.frameId = true;\n }\n } else {\n finished = true;\n }\n } else {\n zoom = targetZoom;\n finished = true;\n }\n\n this.active = true;\n\n if (finished) {\n this.active = false;\n // @ts-ignore\n this.finishTimeout = setTimeout(() => {\n this.zooming = false;\n this.handler.triggerRenderFrame();\n delete this.targetZoom;\n delete this.finishTimeout;\n }, 200);\n }\n\n return {\n noInertia: true,\n needsRenderFrame: !finished,\n zoomDelta: zoom - tr.zoom,\n around: this.aroundPoint,\n originalEvent: this.lastWheelEvent,\n };\n };\n\n private onTimeout(initialEvent: any) {\n this.type = 'wheel';\n this.delta -= this.lastValue;\n if (!this.active) {\n this.start(initialEvent);\n }\n }\n\n private start(e: any) {\n if (!this.delta) {\n return;\n }\n\n if (this.frameId) {\n this.frameId = null;\n }\n\n this.active = true;\n if (!this.isZooming()) {\n this.zooming = true;\n }\n\n if (this.finishTimeout) {\n clearTimeout(this.finishTimeout);\n delete this.finishTimeout;\n }\n\n const pos = DOM.mousePos(this.el, e);\n\n this.around = LngLat.convert(\n this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos),\n );\n this.aroundPoint = this.map.transform.locationPoint(this.around);\n if (!this.frameId) {\n this.frameId = true;\n this.handler.triggerRenderFrame();\n }\n }\n\n private smoothOutEasing(duration: number) {\n let easing = ease;\n\n if (this.prevEase) {\n const preEase = this.prevEase;\n const t = (now() - preEase.start) / preEase.duration;\n const speed = preEase.easing(t + 0.01) - preEase.easing(t);\n\n // Quick hack to make new bezier that is continuous with last\n const x = (0.27 / Math.sqrt(speed * speed + 0.0001)) * 0.01;\n const y = Math.sqrt(0.27 * 0.27 - x * x);\n\n easing = bezier(x, y, 0.25, 1);\n }\n\n this.prevEase = {\n start: now(),\n duration,\n easing,\n };\n\n return easing;\n }\n}\n\nexport default ScrollZoomHandler;\n"],"file":"scroll_zoom.js"}
1
+ {"version":3,"sources":["../../src/handler/scroll_zoom.ts"],"names":["LngLat","bezier","ease","interpolate","now","DOM","wheelZoomDelta","defaultZoomRate","wheelZoomRate","maxScalePerFrame","ScrollZoomHandler","map","handler","frameId","isActive","tr","transform","delta","zoomRate","type","Math","abs","scale","exp","fromScale","targetZoom","zoomScale","min","maxZoom","max","minZoom","scaleZoom","startZoom","zoom","easing","smoothOutEasing","finished","t","lastWheelEventTime","k","active","finishTimeout","setTimeout","zooming","triggerRenderFrame","noInertia","needsRenderFrame","zoomDelta","around","aroundPoint","originalEvent","lastWheelEvent","el","getCanvasContainer","enabled","undefined","options","isEnabled","aroundCenter","e","value","deltaMode","window","WheelEvent","DOM_DELTA_LINE","deltaY","nowTime","timeDelta","lastValue","timeout","onTimeout","clearTimeout","shiftKey","start","preventDefault","onScrollFrame","initialEvent","isZooming","pos","mousePos","convert","getCenter","unproject","locationPoint","duration","prevEase","preEase","speed","x","sqrt","y"],"mappings":";;;AAEA,OAAOA,MAAP,MAAmB,gBAAnB;AAGA,SAASC,MAAT,EAAiBC,IAAjB,EAAuBC,WAAvB,EAAoCC,GAApC,QAA+C,SAA/C;AACA,OAAOC,GAAP,MAAgB,cAAhB;AAIA,IAAMC,cAAc,GAAG,cAAvB;AAIA,IAAMC,eAAe,GAAG,IAAI,GAA5B;AACA,IAAMC,aAAa,GAAG,IAAI,G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c;AAGdlD,QAAAA,MAAM,EAANA;AAHc,OAAhB;AAMA,aAAOA,MAAP;AACD;;;;;;AAGH,eAAexB,iBAAf","sourcesContent":["// @ts-ignore\nimport { EarthMap } from '../earthmap';\nimport LngLat from '../geo/lng_lat';\nimport Point from '../geo/point';\nimport { Map } from '../map';\nimport { bezier, ease, interpolate, now } from '../util';\nimport DOM from '../utils/dom';\nimport HandlerManager from './handler_manager';\n\n// deltaY value for mouse scroll wheel identification\nconst wheelZoomDelta = 4.000244140625;\n\n// These magic numbers control the rate of zoom. Trackpad events fire at a greater\n// frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick\nconst defaultZoomRate = 1 / 100;\nconst wheelZoomRate = 1 / 450;\n\n// upper bound on how much we scale the map in any single render frame; this\n// is used to limit zoom rate in the case of very fast scrolling\nconst maxScalePerFrame = 2;\n\n/**\n * The `ScrollZoomHandler` allows the user to zoom the map by scrolling.\n */\nclass ScrollZoomHandler {\n private map: Map | EarthMap;\n private el: HTMLElement;\n private enabled: boolean;\n private active: boolean;\n private zooming: boolean;\n private aroundCenter: boolean;\n private around: LngLat;\n private aroundPoint: Point;\n private type: 'wheel' | 'trackpad' | null;\n private lastValue: number;\n private timeout: number | null; // used for delayed-handling of a single wheel movement\n private finishTimeout: number; // used to delay final '{move,zoom}end' events\n\n private lastWheelEvent: any;\n private lastWheelEventTime: number;\n\n private startZoom: number;\n private targetZoom: number;\n private delta: number;\n private easing: (time: number) => number;\n private prevEase: {\n start: number;\n duration: number;\n easing: (_: number) => number;\n };\n\n private frameId: boolean | null;\n private handler: HandlerManager;\n\n private defaultZoomRate: number;\n private wheelZoomRate: number;\n\n /**\n * @private\n */\n constructor(map: Map | EarthMap, handler: HandlerManager) {\n this.map = map;\n this.el = map.getCanvasContainer();\n this.handler = handler;\n\n this.delta = 0;\n this.defaultZoomRate = defaultZoomRate;\n this.wheelZoomRate = wheelZoomRate;\n }\n\n /**\n * Set the zoom rate of a trackpad\n * @param {number} [zoomRate=1/100] The rate used to scale trackpad movement to a zoom value.\n * @example\n * // Speed up trackpad zoom\n * map.scrollZoom.setZoomRate(1/25);\n */\n public setZoomRate(zoomRate: number) {\n this.defaultZoomRate = zoomRate;\n }\n\n /**\n * Set the zoom rate of a mouse wheel\n * @param {number} [wheelZoomRate=1/450] The rate used to scale mouse wheel movement to a zoom value.\n * @example\n * // Slow down zoom of mouse wheel\n * map.scrollZoom.setWheelZoomRate(1/600);\n */\n public setWheelZoomRate(zoomRate: number) {\n this.wheelZoomRate = zoomRate;\n }\n\n /**\n * Returns a Boolean indicating whether the \"scroll to zoom\" interaction is enabled.\n *\n * @returns {boolean} `true` if the \"scroll to zoom\" interaction is enabled.\n */\n public isEnabled() {\n return !!this.enabled;\n }\n\n /*\n * Active state is turned on and off with every scroll wheel event and is set back to false before the map\n * render is called, so _active is not a good candidate for determining if a scroll zoom animation is in\n * progress.\n */\n public isActive() {\n return !!this.active || this.finishTimeout !== undefined;\n }\n\n public isZooming() {\n return !!this.zooming;\n }\n\n /**\n * Enables the \"scroll to zoom\" interaction.\n *\n * @param {Object} [options] Options object.\n * @param {string} [options.around] If \"center\" is passed, map will zoom around center of map\n *\n * @example\n * map.scrollZoom.enable();\n * @example\n * map.scrollZoom.enable({ around: 'center' })\n */\n public enable(options?: any) {\n if (this.isEnabled()) {\n return;\n }\n this.enabled = true;\n this.aroundCenter = options && options.around === 'center';\n }\n\n /**\n * Disables the \"scroll to zoom\" interaction.\n *\n * @example\n * map.scrollZoom.disable();\n */\n public disable() {\n if (!this.isEnabled()) {\n return;\n }\n this.enabled = false;\n }\n\n public wheel(e: WheelEvent) {\n if (!this.isEnabled()) {\n return;\n }\n // Remove `any` cast when https://github.com/facebook/flow/issues/4879 is fixed.\n let value =\n e.deltaMode === window.WheelEvent.DOM_DELTA_LINE\n ? e.deltaY * 40\n : e.deltaY;\n const nowTime = now();\n const timeDelta = nowTime - (this.lastWheelEventTime || 0);\n\n this.lastWheelEventTime = nowTime;\n\n if (value !== 0 && value % wheelZoomDelta === 0) {\n // This one is definitely a mouse wheel event.\n this.type = 'wheel';\n } else if (value !== 0 && Math.abs(value) < 4) {\n // This one is definitely a trackpad event because it is so small.\n this.type = 'trackpad';\n } else if (timeDelta > 400) {\n // This is likely a new scroll action.\n this.type = null;\n this.lastValue = value;\n\n // Start a timeout in case this was a singular event, and dely it by up to 40ms.\n // @ts-ignore\n this.timeout = setTimeout(this.onTimeout, 40, e);\n } else if (!this.type) {\n // This is a repeating event, but we don't know the type of event just yet.\n // If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.\n this.type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';\n\n // Make sure our delayed event isn't fired again, because we accumulate\n // the previous event (which was less than 40ms ago) into this event.\n if (this.timeout) {\n clearTimeout(this.timeout);\n this.timeout = null;\n value += this.lastValue;\n }\n }\n\n // Slow down zoom if shift key is held for more precise zooming\n if (e.shiftKey && value) {\n value = value / 4;\n }\n // Only fire the callback if we actually know what type of scrolling device the user uses.\n if (this.type) {\n this.lastWheelEvent = e;\n this.delta -= value;\n if (!this.active) {\n this.start(e);\n }\n }\n\n e.preventDefault();\n }\n\n public renderFrame() {\n return this.onScrollFrame();\n }\n\n public reset() {\n this.active = false;\n }\n\n private onScrollFrame = () => {\n if (!this.frameId) {\n return;\n }\n this.frameId = null;\n\n if (!this.isActive()) {\n return;\n }\n const tr = this.map.transform;\n\n // if we've had scroll events since the last render frame, consume the\n // accumulated delta, and update the target zoom level accordingly\n if (this.delta !== 0) {\n // For trackpad events and single mouse wheel ticks, use the default zoom rate\n const zoomRate =\n this.type === 'wheel' && Math.abs(this.delta) > wheelZoomDelta\n ? this.wheelZoomRate\n : this.defaultZoomRate;\n // Scale by sigmoid of scroll wheel delta.\n let scale =\n maxScalePerFrame / (1 + Math.exp(-Math.abs(this.delta * zoomRate)));\n\n if (this.delta < 0 && scale !== 0) {\n scale = 1 / scale;\n }\n\n const fromScale =\n typeof this.targetZoom === 'number'\n ? tr.zoomScale(this.targetZoom)\n : tr.scale;\n this.targetZoom = Math.min(\n tr.maxZoom,\n Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)),\n );\n\n // if this is a mouse wheel, refresh the starting zoom and easing\n // function we're using to smooth out the zooming between wheel\n // events\n if (this.type === 'wheel') {\n this.startZoom = tr.zoom;\n this.easing = this.smoothOutEasing(200);\n }\n\n this.delta = 0;\n }\n\n const targetZoom =\n typeof this.targetZoom === 'number' ? this.targetZoom : tr.zoom;\n const startZoom = this.startZoom;\n const easing = this.easing;\n\n let finished = false;\n let zoom;\n if (this.type === 'wheel' && startZoom && easing) {\n const t = Math.min((now() - this.lastWheelEventTime) / 200, 1);\n const k = easing(t);\n zoom = interpolate(startZoom, targetZoom, k);\n if (t < 1) {\n if (!this.frameId) {\n this.frameId = true;\n }\n } else {\n finished = true;\n }\n } else {\n zoom = targetZoom;\n finished = true;\n }\n\n this.active = true;\n\n if (finished) {\n this.active = false;\n // @ts-ignore\n this.finishTimeout = setTimeout(() => {\n this.zooming = false;\n this.handler.triggerRenderFrame();\n // @ts-ignore\n delete this.targetZoom;\n // @ts-ignore\n delete this.finishTimeout;\n }, 200);\n }\n\n return {\n noInertia: true,\n needsRenderFrame: !finished,\n zoomDelta: zoom - tr.zoom,\n around: this.aroundPoint,\n originalEvent: this.lastWheelEvent,\n };\n };\n\n private onTimeout(initialEvent: any) {\n this.type = 'wheel';\n this.delta -= this.lastValue;\n if (!this.active) {\n this.start(initialEvent);\n }\n }\n\n private start(e: any) {\n if (!this.delta) {\n return;\n }\n\n if (this.frameId) {\n this.frameId = null;\n }\n\n this.active = true;\n if (!this.isZooming()) {\n this.zooming = true;\n }\n\n if (this.finishTimeout) {\n clearTimeout(this.finishTimeout);\n // @ts-ignore\n delete this.finishTimeout;\n }\n\n const pos = DOM.mousePos(this.el, e);\n\n this.around = LngLat.convert(\n this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos),\n );\n this.aroundPoint = this.map.transform.locationPoint(this.around);\n if (!this.frameId) {\n this.frameId = true;\n this.handler.triggerRenderFrame();\n }\n }\n\n private smoothOutEasing(duration: number) {\n let easing = ease;\n\n if (this.prevEase) {\n const preEase = this.prevEase;\n const t = (now() - preEase.start) / preEase.duration;\n const speed = preEase.easing(t + 0.01) - preEase.easing(t);\n\n // Quick hack to make new bezier that is continuous with last\n const x = (0.27 / Math.sqrt(speed * speed + 0.0001)) * 0.01;\n const y = Math.sqrt(0.27 * 0.27 - x * x);\n\n easing = bezier(x, y, 0.25, 1);\n }\n\n this.prevEase = {\n start: now(),\n duration,\n easing,\n };\n\n return easing;\n }\n}\n\nexport default ScrollZoomHandler;\n"],"file":"scroll_zoom.js"}
@@ -1,3 +1,4 @@
1
+ import { EarthMap } from '../../earthmap';
1
2
  import Point from '../../geo/point';
2
3
  import { Map } from '../../map';
3
4
  import TapRecognizer from './tap_recognizer';
@@ -11,7 +12,7 @@ export default class TapZoomHandler {
11
12
  touchstart(e: TouchEvent, points: Point[], mapTouches: Touch[]): void;
12
13
  touchmove(e: TouchEvent, points: Point[], mapTouches: Touch[]): void;
13
14
  touchend(e: TouchEvent, points: Point[], mapTouches: Touch[]): {
14
- cameraAnimation: (map: Map) => Map;
15
+ cameraAnimation: (map: Map | EarthMap) => Map | EarthMap;
15
16
  } | undefined;
16
17
  touchcancel(): void;
17
18
  enable(): void;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/handler/tap/tap_zoom.ts"],"names":["TapRecognizer","TapZoomHandler","zoomIn","numTouches","numTaps","zoomOut","reset","active","e","points","mapTouches","touchstart","touchmove","zoomInPoint","touchend","zoomOutPoint","preventDefault","setTimeout","cameraAnimation","map","easeTo","duration","zoom","getZoom","around","unproject","originalEvent","enabled"],"mappings":";;;AAGA,OAAOA,aAAP,MAA0B,kBAA1B;;IAEqBC,c;AAMnB,4BAAc;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,MAAL,GAAc,IAAIF,aAAJ,CAAkB;AAC9BG,MAAAA,UAAU,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,CAArB,CAAV;AACA,eAAO;AACLY,UAAAA,eAAe,EAAE,yBAACC,GAAD;AAAA,mBACfA,GAAG,CAACC,MAAJ,CACE;AACEC,cAAAA,QAAQ,EAAE,GADZ;AAEEC,cAAAA,IAAI,EAAEH,GAAG,CAACI,OAAJ,KAAgB,CAFxB;AAGEC,cAAAA,MAAM,EAAEL,GAAG,CAACM,SAAJ,CAAcZ,WAAd;AAHV,aADF,EAME;AAAEa,cAAAA,aAAa,EAAElB;AAAjB,aANF,CADe;AAAA;AADZ,SAAP;AAWD,OAfD,MAeO,IAAIO,YAAJ,EAAkB;AACvB,aAAKR,MAAL,GAAc,IAAd;AACAC,QAAAA,CAAC,CAACQ,cAAF;AACAC,QAAAA,UAAU,CAAC;AAAA,iBAAM,KAAI,CAACX,KAAL,EAAN;AAAA,SAAD,EAAqB,CAArB,CAAV;AACA,eAAO;AACLY,UAAAA,eAAe,EAAE,yBAACC,GAAD;AAAA,mBACfA,GAAG,CAACC,MAAJ,CACE;AACEC,cAAAA,QAAQ,EAAE,GADZ;AAEEC,cAAAA,IAAI,EAAEH,GAAG,CAACI,OAAJ,KAAgB,CAFxB;AAGEC,cAAAA,MAAM,EAAEL,GAAG,CAACM,SAAJ,CAAcV,YAAd;AAHV,aADF,EAME;AAAEW,cAAAA,aAAa,EAAElB;AAAjB,aANF,CADe;AAAA;AADZ,SAAP;AAWD;AACF;;;WAED,uBAAqB;AACnB,WAAKF,KAAL;AACD;;;WAED,kBAAgB;AACd,WAAKqB,OAAL,GAAe,IAAf;AACD;;;WAED,mBAAiB;AACf,WAAKA,OAAL,GAAe,KAAf;AACA,WAAKrB,KAAL;AACD;;;WAED,qBAAmB;AACjB,aAAO,KAAKqB,OAAZ;AACD;;;WAED,oBAAkB;AAChB,aAAO,KAAKpB,MAAZ;AACD;;;;;;SA5FkBN,c","sourcesContent":["// @ts-ignore\nimport Point from '../../geo/point';\nimport { Map } from '../../map';\nimport TapRecognizer from './tap_recognizer';\n\nexport default class TapZoomHandler {\n public enabled: boolean;\n public active: boolean;\n public zoomIn: TapRecognizer;\n public zoomOut: TapRecognizer;\n\n constructor() {\n this.zoomIn = new TapRecognizer({\n numTouches: 1,\n numTaps: 2,\n });\n\n this.zoomOut = new TapRecognizer({\n numTouches: 2,\n numTaps: 1,\n });\n\n this.reset();\n }\n\n public reset() {\n this.active = false;\n this.zoomIn.reset();\n this.zoomOut.reset();\n }\n\n public touchstart(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n this.zoomIn.touchstart(e, points, mapTouches);\n this.zoomOut.touchstart(e, points, mapTouches);\n }\n\n public touchmove(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n this.zoomIn.touchmove(e, points, mapTouches);\n this.zoomOut.touchmove(e, points, mapTouches);\n }\n\n public touchend(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n const zoomInPoint = this.zoomIn.touchend(e, points, mapTouches);\n const zoomOutPoint = this.zoomOut.touchend(e, points, mapTouches);\n\n if (zoomInPoint) {\n this.active = true;\n e.preventDefault();\n setTimeout(() => this.reset(), 0);\n return {\n cameraAnimation: (map: Map) =>\n map.easeTo(\n {\n duration: 300,\n zoom: map.getZoom() + 1,\n around: map.unproject(zoomInPoint),\n },\n { originalEvent: e },\n ),\n };\n } else if (zoomOutPoint) {\n this.active = true;\n e.preventDefault();\n setTimeout(() => this.reset(), 0);\n return {\n cameraAnimation: (map: Map) =>\n map.easeTo(\n {\n duration: 300,\n zoom: map.getZoom() - 1,\n around: map.unproject(zoomOutPoint),\n },\n { originalEvent: e },\n ),\n };\n }\n }\n\n public touchcancel() {\n this.reset();\n }\n\n public enable() {\n this.enabled = true;\n }\n\n public disable() {\n this.enabled = false;\n this.reset();\n }\n\n public isEnabled() {\n return this.enabled;\n }\n\n public isActive() {\n return this.active;\n }\n}\n"],"file":"tap_zoom.js"}
1
+ {"version":3,"sources":["../../../src/handler/tap/tap_zoom.ts"],"names":["TapRecognizer","TapZoomHandler","zoomIn","numTouches","numTaps","zoomOut","reset","active","e","points","mapTouches","touchstart","touchmove","zoomInPoint","touchend","zoomOutPoint","preventDefault","setTimeout","cameraAnimation","map","easeTo","duration","zoom","getZoom","around","unproject","originalEvent","enabled"],"mappings":";;;AAIA,OAAOA,aAAP,MAA0B,kBAA1B;;IAEqBC,c;AAMnB,4BAAc;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,MAAL,GAAc,IAAIF,aAAJ,CAAkB;AAC9BG,MAAAA,UAAU,EAAE,CADkB;AAE9BC,MAAAA,OAAO,EAAE;AAFqB,KAAlB,CAAd;AAKA,SAAKC,OAAL,GAAe,IAAIL,aAAJ,CAAkB;AAC/BG,MAAAA,UAAU,EAAE,CADmB;AAE/BC,MAAAA,OAAO,EAAE;AAFsB,KAAlB,CAAf;AAKA,SAAKE,KAAL;AACD;;;;WAED,iBAAe;AACb,WAAKC,MAAL,GAAc,KAAd;AACA,WAAKL,MAAL,CAAYI,KAAZ;AACA,WAAKD,OAAL,CAAaC,KAAb;AACD;;;WAED,oBAAkBE,CAAlB,EAAiCC,MAAjC,EAAkDC,UAAlD,EAAuE;AACrE,WAAKR,MAAL,CAAYS,UAAZ,CAAuBH,CAAvB,EAA0BC,MAA1B,EAAkCC,UAAlC;AACA,WAAKL,OAAL,CAAaM,UAAb,CAAwBH,CAAxB,EAA2BC,MAA3B,EAAmCC,UAAnC;AACD;;;WAED,mBAAiBF,CAAjB,EAAgCC,MAAhC,EAAiDC,UAAjD,EAAsE;AACpE,WAAKR,MAAL,CAAYU,SAAZ,CAAsBJ,CAAtB,EAAyBC,MAAzB,EAAiCC,UAAjC;AACA,WAAKL,OAAL,CAAaO,SAAb,CAAuBJ,CAAvB,EAA0BC,MAA1B,EAAkCC,UAAlC;AACD;;;WAED,kBAAgBF,CAAhB,EAA+BC,MAA/B,EAAgDC,UAAhD,EAAqE;AAAA;;AACnE,UAAMG,WAAW,GAAG,KAAKX,MAAL,CAAYY,QAAZ,CAAqBN,CAArB,EAAwBC,MAAxB,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GAAe,IAAf;AACD;;;WAED,mBAAiB;AACf,WAAKA,OAAL,GAAe,KAAf;AACA,WAAKrB,KAAL;AACD;;;WAED,qBAAmB;AACjB,aAAO,KAAKqB,OAAZ;AACD;;;WAED,oBAAkB;AAChB,aAAO,KAAKpB,MAAZ;AACD;;;;;;SA5FkBN,c","sourcesContent":["// @ts-ignore\nimport { EarthMap } from '../../earthmap';\nimport Point from '../../geo/point';\nimport { Map } from '../../map';\nimport TapRecognizer from './tap_recognizer';\n\nexport default class TapZoomHandler {\n public enabled: boolean;\n public active: boolean;\n public zoomIn: TapRecognizer;\n public zoomOut: TapRecognizer;\n\n constructor() {\n this.zoomIn = new TapRecognizer({\n numTouches: 1,\n numTaps: 2,\n });\n\n this.zoomOut = new TapRecognizer({\n numTouches: 2,\n numTaps: 1,\n });\n\n this.reset();\n }\n\n public reset() {\n this.active = false;\n this.zoomIn.reset();\n this.zoomOut.reset();\n }\n\n public touchstart(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n this.zoomIn.touchstart(e, points, mapTouches);\n this.zoomOut.touchstart(e, points, mapTouches);\n }\n\n public touchmove(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n this.zoomIn.touchmove(e, points, mapTouches);\n this.zoomOut.touchmove(e, points, mapTouches);\n }\n\n public touchend(e: TouchEvent, points: Point[], mapTouches: Touch[]) {\n const zoomInPoint = this.zoomIn.touchend(e, points, mapTouches);\n const zoomOutPoint = this.zoomOut.touchend(e, points, mapTouches);\n\n if (zoomInPoint) {\n this.active = true;\n e.preventDefault();\n setTimeout(() => this.reset(), 0);\n return {\n cameraAnimation: (map: Map | EarthMap) =>\n map.easeTo(\n {\n duration: 300,\n zoom: map.getZoom() + 1,\n around: map.unproject(zoomInPoint),\n },\n { originalEvent: e },\n ),\n };\n } else if (zoomOutPoint) {\n this.active = true;\n e.preventDefault();\n setTimeout(() => this.reset(), 0);\n return {\n cameraAnimation: (map: Map | EarthMap) =>\n map.easeTo(\n {\n duration: 300,\n zoom: map.getZoom() - 1,\n around: map.unproject(zoomOutPoint),\n },\n { originalEvent: e },\n ),\n };\n }\n }\n\n public touchcancel() {\n this.reset();\n }\n\n public enable() {\n this.enabled = true;\n }\n\n public disable() {\n this.enabled = false;\n this.reset();\n }\n\n public isEnabled() {\n return this.enabled;\n }\n\n public isActive() {\n return this.active;\n }\n}\n"],"file":"tap_zoom.js"}
package/es/hash.d.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import { EarthMap } from './earthmap';
1
2
  import { Map } from './map';
2
3
  declare class Hash {
3
4
  private map;
4
5
  private updateHash;
5
6
  private hashName?;
6
7
  constructor(hashName?: string);
7
- addTo(map: Map): this;
8
+ addTo(map: Map | EarthMap): this;
8
9
  remove(): this;
9
10
  onHashChange: () => boolean;
10
11
  private getCurrentHash;
package/es/hash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hash.ts"],"names":["throttle","Hash","hashName","loc","getCurrentHash","length","some","v","isNaN","bearing","map","dragRotate","isEnabled","touchZoomRotate","getBearing","jumpTo","center","zoom","pitch","hash","window","location","replace","keyval","split","part","forEach","getHashString","history","replaceState","state","SecurityError","encodeURIComponent","updateHash","updateHashUnthrottled","addEventListener","onHashChange","on","removeEventListener","off","mapFeedback","getCenter","Math","round","getZoom","precision","ceil","LN2","log","LN10","m","pow","lng","lat","getPitch","found","parts","slice","key","filter","a","push","join"],"mappings":";;;AAEA,OAAOA,QAAP,MAAqB,iBAArB;;IASMC,I;AAKJ,gBAAYC,QAAZ,EAA+B;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,0CAqBT,YAAM;AAC1B,UAAMC,GAAG,GAAG,KAAI,CAACC,cAAL,EAAZ;;AACA,UAAID,GAAG,CAACE,MAAJ,IAAc,CAAd,IAAmB,CAACF,GAAG,CAACG,IAAJ,CAAS,UAACC,CAAD;AAAA,eAAeC,KAAK,CAAC,CAACD,CAAF,CAApB;AAAA,OAAT,CAAxB,EAA4D;AAC1D,YAAME,OAAO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AAI,CAACD,KAAL,CAAW,GAAX,EAAgB,CAAhB,CAAZ;;AACA,cAAIkC,GAAG,KAAKxD,QAAZ,EAAsB;AACpBqD,YAAAA,KAAK,GAAG,IAAR;AACA,6BAAUG,GAAV,cAAiBvC,IAAjB;AACD;;AACD,iBAAOM,IAAP;AACD,SAVW,EAWXkC,MAXW,CAWJ,UAACC,CAAD;AAAA,iBAAOA,CAAP;AAAA,SAXI,CAAd;;AAYA,YAAI,CAACL,KAAL,EAAY;AACVC,UAAAA,KAAK,CAACK,IAAN,WAAc3D,QAAd,cAA0BiB,IAA1B;AACD;;AACD,0BAAWqC,KAAK,CAACM,IAAN,CAAW,GAAX,CAAX;AACD;;AAED,wBAAW3C,IAAX;AACD;;;;;;AAcH,eAAelB,IAAf","sourcesContent":["// @ts-ignore\n// tslint:disable-next-line:no-submodule-imports\nimport throttle from 'lodash/throttle';\nimport { Map } from './map';\n\n/*\n * Adds the map's position to its page's location hash.\n * Passed as an option to the map object.\n *\n * @returns {Hash} `this`\n */\nclass Hash {\n private map: Map;\n private updateHash: () => number | void;\n private hashName?: string;\n\n constructor(hashName?: string) {\n this.hashName = hashName && encodeURIComponent(hashName);\n\n // Mobile Safari doesn't allow updating the hash more than 100 times per 30 seconds.\n this.updateHash = throttle(this.updateHashUnthrottled, (30 * 1000) / 100);\n }\n public addTo(map: Map) {\n this.map = map;\n window.addEventListener('hashchange', this.onHashChange, false);\n this.map.on('moveend', this.updateHash);\n return this;\n }\n public remove() {\n window.removeEventListener('hashchange', this.onHashChange, false);\n this.map.off('moveend', this.updateHash);\n // clearTimeout(this.updateHash());\n\n delete this.map;\n return this;\n }\n\n public onHashChange = () => {\n const loc = this.getCurrentHash();\n if (loc.length >= 3 && !loc.some((v: string) => isNaN(+v))) {\n const bearing =\n this.map.dragRotate.isEnabled() && this.map.touchZoomRotate.isEnabled()\n ? +(loc[3] || 0)\n : this.map.getBearing();\n this.map.jumpTo({\n center: [+loc[2], +loc[1]],\n zoom: +loc[0],\n bearing,\n pitch: +(loc[4] || 0),\n });\n return true;\n }\n return false;\n };\n\n private getCurrentHash = () => {\n // Get the current hash from location, stripped from its number sign\n const hash = window.location.hash.replace('#', '');\n if (this.hashName) {\n // Split the parameter-styled hash into parts and find the value we need\n let keyval;\n hash\n .split('&')\n .map((part) => part.split('='))\n .forEach((part) => {\n if (part[0] === this.hashName) {\n keyval = part;\n }\n });\n return (keyval ? keyval[1] || '' : '').split('/');\n }\n return hash.split('/');\n };\n\n private getHashString(mapFeedback?: boolean) {\n const center = this.map.getCenter();\n const zoom = Math.round(this.map.getZoom() * 100) / 100;\n // derived from equation: 512px * 2^z / 360 / 10^d < 0.5px\n const precision = Math.ceil(\n (zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10,\n );\n const m = Math.pow(10, precision);\n const lng = Math.round(center.lng * m) / m;\n const lat = Math.round(center.lat * m) / m;\n const bearing = this.map.getBearing();\n const pitch = this.map.getPitch();\n let hash = '';\n if (mapFeedback) {\n // new map feedback site has some constraints that don't allow\n // us to use the same hash format as we do for the Map hash option.\n hash += `/${lng}/${lat}/${zoom}`;\n } else {\n hash += `${zoom}/${lat}/${lng}`;\n }\n\n if (bearing || pitch) {\n hash += `/${Math.round(bearing * 10) / 10}`;\n }\n if (pitch) {\n hash += `/${Math.round(pitch)}`;\n }\n\n if (this.hashName) {\n const hashName = this.hashName;\n let found = false;\n const parts = window.location.hash\n .slice(1)\n .split('&')\n .map((part) => {\n const key = part.split('=')[0];\n if (key === hashName) {\n found = true;\n return `${key}=${hash}`;\n }\n return part;\n })\n .filter((a) => a);\n if (!found) {\n parts.push(`${hashName}=${hash}`);\n }\n return `#${parts.join('&')}`;\n }\n\n return `#${hash}`;\n }\n\n private updateHashUnthrottled = () => {\n const hash = this.getHashString();\n try {\n window.history.replaceState(window.history.state, '', hash);\n } catch (SecurityError) {\n // IE11 does not allow this if the page is within an iframe created\n // with iframe.contentWindow.document.write(...).\n // https://github.com/mapbox/mapbox-gl-js/issues/7410\n }\n };\n}\n\nexport default Hash;\n"],"file":"hash.js"}
1
+ {"version":3,"sources":["../src/hash.ts"],"names":["throttle","Hash","hashName","loc","getCurrentHash","length","some","v","isNaN","bearing","map","dragRotate","isEnabled","touchZoomRotate","getBearing","jumpTo","center","zoom","pitch","hash","window","location","replace","keyval","split","part","forEach","getHashString","history","replaceState","state","SecurityError","encodeURIComponent","updateHash","updateHashUnthrottled","addEventListener","onHashChange","on","removeEventListener","off","mapFeedback","getCenter","Math","round","getZoom","precision","ceil","LN2","log","LN10","m","pow","lng","lat","getPitch","found","parts","slice","key","filter","a","push","join"],"mappings":";;;AAEA,OAAOA,QAAP,MAAqB,iBAArB;;IAUMC,I;AAKJ,gBAAYC,QAAZ,EAA+B;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,0CAuBT,YAAM;AAC1B,UAAMC,GAAG,GAAG,KAAI,CAACC,cAAL,EAAZ;;AACA,UAAID,GAAG,CAACE,MAAJ,IAAc,CAAd,IAAmB,CAACF,GAAG,CAACG,IAAJ,CAAS,UAACC,CAAD;AAAA,eAAeC,KAAK,CAAC,CAACD,CAAF,CAApB;AAAA,OAAT,CAAxB,EAA4D;AAC1D,YAAME,OAAO,GACX,KAAI,CAACC,GAAL,CAASC,UAAT,CAAoBC,SAApB,MAAmC,KAAI,CAACF,GAAL,CAASG,eAAT,CAAyBD,SAAzB,EAAnC,GACI,EAAET,GAAG,CAAC,CAAD,CAAH,IAAU,CAAZ,CADJ,GAEI,KAAI,CAACO,GAAL,CAASI,UAAT,EAHN;;AAIA,QAAA,KAAI,CAACJ,GAAL,CAASK,MAAT,CAAgB;AACdC,UAAAA,MAAM,EAAE,CAAC,CAACb,GAAG,CAAC,CAAD,CAAL,EAAU,CAACA,GAAG,CAAC,CAAD,CAAd,CADM;AAEdc,UAAAA,IAAI,EAAE,CAACd,GAAG,CAAC,CAAD,CAFI;AAGdM,UAAAA,OAAO,EAAPA,OAHc;AAIdS,UAAAA,KAAK,EAAE,EAAE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sourcesContent":["// @ts-ignore\n// tslint:disable-next-line:no-submodule-imports\nimport throttle from 'lodash/throttle';\nimport { EarthMap } from './earthmap';\nimport { Map } from './map';\n\n/*\n * Adds the map's position to its page's location hash.\n * Passed as an option to the map object.\n *\n * @returns {Hash} `this`\n */\nclass Hash {\n private map: Map | EarthMap;\n private updateHash: () => number | void;\n private hashName?: string;\n\n constructor(hashName?: string) {\n this.hashName = hashName && encodeURIComponent(hashName);\n\n // Mobile Safari doesn't allow updating the hash more than 100 times per 30 seconds.\n this.updateHash = throttle(this.updateHashUnthrottled, (30 * 1000) / 100);\n }\n public addTo(map: Map | EarthMap) {\n this.map = map;\n window.addEventListener('hashchange', this.onHashChange, false);\n // @ts-ignore\n this.map.on('moveend', this.updateHash);\n return this;\n }\n public remove() {\n window.removeEventListener('hashchange', this.onHashChange, false);\n // @ts-ignore\n this.map.off('moveend', this.updateHash);\n // clearTimeout(this.updateHash());\n // @ts-ignore\n delete this.map;\n return this;\n }\n\n public onHashChange = () => {\n const loc = this.getCurrentHash();\n if (loc.length >= 3 && !loc.some((v: string) => isNaN(+v))) {\n const bearing =\n this.map.dragRotate.isEnabled() && this.map.touchZoomRotate.isEnabled()\n ? +(loc[3] || 0)\n : this.map.getBearing();\n this.map.jumpTo({\n center: [+loc[2], +loc[1]],\n zoom: +loc[0],\n bearing,\n pitch: +(loc[4] || 0),\n });\n return true;\n }\n return false;\n };\n\n private getCurrentHash = () => {\n // Get the current hash from location, stripped from its number sign\n const hash = window.location.hash.replace('#', '');\n if (this.hashName) {\n // Split the parameter-styled hash into parts and find the value we need\n let keyval;\n hash\n .split('&')\n .map((part) => part.split('='))\n .forEach((part) => {\n if (part[0] === this.hashName) {\n keyval = part;\n }\n });\n return (keyval ? keyval[1] || '' : '').split('/');\n }\n return hash.split('/');\n };\n\n private getHashString(mapFeedback?: boolean) {\n const center = this.map.getCenter();\n const zoom = Math.round(this.map.getZoom() * 100) / 100;\n // derived from equation: 512px * 2^z / 360 / 10^d < 0.5px\n const precision = Math.ceil(\n (zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10,\n );\n const m = Math.pow(10, precision);\n const lng = Math.round(center.lng * m) / m;\n const lat = Math.round(center.lat * m) / m;\n const bearing = this.map.getBearing();\n const pitch = this.map.getPitch();\n let hash = '';\n if (mapFeedback) {\n // new map feedback site has some constraints that don't allow\n // us to use the same hash format as we do for the Map hash option.\n hash += `/${lng}/${lat}/${zoom}`;\n } else {\n hash += `${zoom}/${lat}/${lng}`;\n }\n\n if (bearing || pitch) {\n hash += `/${Math.round(bearing * 10) / 10}`;\n }\n if (pitch) {\n hash += `/${Math.round(pitch)}`;\n }\n\n if (this.hashName) {\n const hashName = this.hashName;\n let found = false;\n const parts = window.location.hash\n .slice(1)\n .split('&')\n .map((part) => {\n const key = part.split('=')[0];\n if (key === hashName) {\n found = true;\n return `${key}=${hash}`;\n }\n return part;\n })\n .filter((a) => a);\n if (!found) {\n parts.push(`${hashName}=${hash}`);\n }\n return `#${parts.join('&')}`;\n }\n\n return `#${hash}`;\n }\n\n private updateHashUnthrottled = () => {\n const hash = this.getHashString();\n try {\n window.history.replaceState(window.history.state, '', hash);\n } catch (SecurityError) {\n // IE11 does not allow this if the page is within an iframe created\n // with iframe.contentWindow.document.write(...).\n // https://github.com/mapbox/mapbox-gl-js/issues/7410\n }\n };\n}\n\nexport default Hash;\n"],"file":"hash.js"}
package/es/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './map';
2
+ export * from './earthmap';
package/es/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './map';
2
+ export * from './earthmap';
2
3
  //# sourceMappingURL=index.js.map
package/es/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAd","sourcesContent":["export * from './map';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAd;AACA,cAAc,YAAd","sourcesContent":["export * from './map';\nexport * from './earthmap';\n"],"file":"index.js"}