@guardian/interactive-component-library 0.3.1 → 0.3.2-rc1
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.
- package/dist/components/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/Map.d.ts +8 -0
- package/dist/components/molecules/canvas-map/Map.js +90 -0
- package/dist/components/molecules/canvas-map/context/MapContext.d.ts +19 -0
- package/dist/components/molecules/canvas-map/context/MapContext.js +20 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.d.ts +6 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.js +40 -0
- package/dist/components/molecules/canvas-map/controls/icons/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.js +25 -0
- package/dist/components/molecules/canvas-map/controls/index.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/style.module.css.js +11 -0
- package/dist/components/molecules/canvas-map/index.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/Feature.d.ts +44 -0
- package/dist/components/molecules/canvas-map/lib/Feature.js +113 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +24 -0
- package/dist/components/molecules/canvas-map/lib/Map.d.ts +82 -0
- package/dist/components/molecules/canvas-map/lib/Map.js +267 -0
- package/dist/components/molecules/canvas-map/lib/View.d.ts +222 -0
- package/dist/components/molecules/canvas-map/lib/View.js +208 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.js +35 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.js +9 -0
- package/dist/components/molecules/canvas-map/lib/events/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.d.ts +63 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +122 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.js +41 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.js +19 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.js +22 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.js +46 -0
- package/dist/components/molecules/canvas-map/lib/geometry/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js +95 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +65 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +52 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +118 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +57 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +136 -0
- package/dist/components/molecules/canvas-map/lib/layers/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.d.ts +27 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.js +12 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +90 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +53 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +133 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +79 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +15 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +53 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +7 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.js +15 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +22 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.js +17 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +146 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.js +116 -0
- package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/util/array.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/array.js +15 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.js +24 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.d.ts +47 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.js +61 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.d.ts +26 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.js +35 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.js +27 -0
- package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +36 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.js +12 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.js +28 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +98 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.js +118 -0
- package/dist/components/molecules/canvas-map/lib/util/index.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.js +20 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.js +11 -0
- package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +114 -0
- package/dist/components/molecules/canvas-map/lib/util/size.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/util/size.js +53 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.js +25 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.js +7 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +14 -0
- package/dist/components/molecules/canvas-map/style.module.scss.js +20 -0
- package/dist/components/molecules/column-chart/column-chart-example.d.ts +35 -0
- package/dist/components/molecules/column-chart/column-chart-util.d.ts +1 -0
- package/dist/components/molecules/column-chart/index.d.ts +11 -0
- package/dist/components/molecules/column-chart/index.js +63 -0
- package/dist/components/molecules/column-chart/style.module.css.js +14 -0
- package/dist/components/molecules/control-change/index.d.ts +6 -0
- package/dist/components/molecules/control-change/index.js +29 -0
- package/dist/components/molecules/control-change/style.module.css.js +11 -0
- package/dist/components/molecules/dropdown/index.d.ts +11 -0
- package/dist/components/molecules/dropdown/index.js +191 -0
- package/dist/components/molecules/dropdown/style.module.css.js +50 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +5 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.js +14 -0
- package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +14 -0
- package/dist/components/molecules/index.d.ts +18 -0
- package/dist/components/molecules/modal/index.d.ts +8 -0
- package/dist/components/molecules/modal/index.js +59 -0
- package/dist/components/molecules/modal/style.module.css.js +26 -0
- package/dist/components/molecules/option-picker/index.d.ts +26 -0
- package/dist/components/molecules/option-picker/index.js +94 -0
- package/dist/components/molecules/option-picker/style.module.css.js +35 -0
- package/dist/components/molecules/page-section/index.d.ts +8 -0
- package/dist/components/molecules/page-section/index.js +52 -0
- package/dist/components/molecules/page-section/style.module.scss.js +20 -0
- package/dist/components/molecules/party-profile/index.d.ts +10 -0
- package/dist/components/molecules/party-profile/index.js +29 -0
- package/dist/components/molecules/party-profile/style.module.css.js +26 -0
- package/dist/components/molecules/refresh-indicator/index.d.ts +4 -0
- package/dist/components/molecules/refresh-indicator/index.js +18 -0
- package/dist/components/molecules/refresh-indicator/style.module.scss.js +17 -0
- package/dist/components/molecules/responsive-grid/index.d.ts +10 -0
- package/dist/components/molecules/responsive-grid/index.js +19 -0
- package/dist/components/molecules/responsive-grid/style.module.scss.js +8 -0
- package/dist/components/molecules/result-summary/index.d.ts +8 -0
- package/dist/components/molecules/result-summary/index.js +40 -0
- package/dist/components/molecules/result-summary/style.module.css.js +11 -0
- package/dist/components/molecules/search-input/icons/search.d.ts +1 -0
- package/dist/components/molecules/search-input/icons/search.js +24 -0
- package/dist/components/molecules/search-input/icons/search.module.css.js +11 -0
- package/dist/components/molecules/search-input/index.d.ts +11 -0
- package/dist/components/molecules/search-input/index.js +165 -0
- package/dist/components/molecules/search-input/style.module.css.js +32 -0
- package/dist/components/molecules/slope-chart/index.d.ts +16 -0
- package/dist/components/molecules/slope-chart/index.js +139 -0
- package/dist/components/molecules/slope-chart/style.module.css.js +35 -0
- package/dist/components/molecules/svg-map/context/MapContext.d.ts +1 -0
- package/dist/components/molecules/svg-map/context/MapContext.js +5 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +10 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.js +88 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.js +26 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +1 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +9 -0
- package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +4 -0
- package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +1 -0
- package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +4 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +19 -0
- package/dist/components/molecules/svg-map/index.d.ts +38 -0
- package/dist/components/molecules/svg-map/index.js +121 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.js +14 -0
- package/dist/components/molecules/svg-map/layers/Line.d.ts +7 -0
- package/dist/components/molecules/svg-map/layers/Line.js +48 -0
- package/dist/components/molecules/svg-map/layers/Point.d.ts +10 -0
- package/dist/components/molecules/svg-map/layers/Point.js +59 -0
- package/dist/components/molecules/svg-map/layers/Polygon.d.ts +9 -0
- package/dist/components/molecules/svg-map/layers/Polygon.js +75 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.js +11 -0
- package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +8 -0
- package/dist/components/molecules/svg-map/layers/index.d.ts +5 -0
- package/dist/components/molecules/svg-map/layers/index.js +12 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +3 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +32 -0
- package/dist/components/molecules/svg-map/style.module.css.js +11 -0
- package/dist/components/molecules/table/index.d.ts +7 -0
- package/dist/components/molecules/table/index.js +90 -0
- package/dist/components/molecules/table/style.module.scss.js +29 -0
- package/dist/components/molecules/table/useTable.d.ts +8 -0
- package/dist/components/molecules/table/useTable.js +128 -0
- package/dist/components/molecules/tooltip/index.d.ts +82 -0
- package/dist/components/molecules/tooltip/index.js +117 -0
- package/dist/components/molecules/tooltip/style.module.css.js +8 -0
- package/dist/components/molecules/topline-result/index.d.ts +3 -0
- package/dist/components/molecules/topline-result/index.js +61 -0
- package/dist/components/molecules/topline-result/style.module.scss.js +38 -0
- package/dist/components/organisms/coalitions-tracker/index.d.ts +16 -0
- package/dist/components/organisms/coalitions-tracker/index.js +151 -0
- package/dist/components/organisms/coalitions-tracker/style.module.scss.js +32 -0
- package/dist/components/organisms/index.d.ts +2 -0
- package/dist/components/organisms/ticker/gradient/index.d.ts +1 -0
- package/dist/components/organisms/ticker/gradient/index.js +35 -0
- package/dist/components/organisms/ticker/gradient/style.module.scss.js +14 -0
- package/dist/components/organisms/ticker/index.d.ts +5 -0
- package/dist/components/organisms/ticker/index.js +102 -0
- package/dist/components/organisms/ticker/style.module.scss.js +32 -0
- package/dist/components/particles/ad-slot/index.d.ts +40 -0
- package/dist/components/particles/ad-slot/index.js +34 -0
- package/dist/components/particles/ad-slot/style.module.css.js +11 -0
- package/dist/components/particles/arrow-button/index.d.ts +6 -0
- package/dist/components/particles/arrow-button/index.js +32 -0
- package/dist/components/particles/arrow-button/style.module.css.js +11 -0
- package/dist/components/particles/aspect-ratio-box/index.d.ts +4 -0
- package/dist/components/particles/aspect-ratio-box/index.js +15 -0
- package/dist/components/particles/aspect-ratio-box/style.module.css.js +6 -0
- package/dist/components/particles/button/index.d.ts +6 -0
- package/dist/components/particles/button/index.js +10 -0
- package/dist/components/particles/button/style.module.css.js +11 -0
- package/dist/components/particles/change-bar/index.d.ts +8 -0
- package/dist/components/particles/change-bar/index.js +27 -0
- package/dist/components/particles/change-bar/style.module.scss.js +14 -0
- package/dist/components/particles/chevron/index.d.ts +6 -0
- package/dist/components/particles/chevron/index.js +78 -0
- package/dist/components/particles/chevron/style.module.css.js +20 -0
- package/dist/components/particles/circle-icon/index.d.ts +6 -0
- package/dist/components/particles/circle-icon/index.js +32 -0
- package/dist/components/particles/circle-icon/style.module.css.js +14 -0
- package/dist/components/particles/close-button/index.d.ts +5 -0
- package/dist/components/particles/close-button/index.js +35 -0
- package/dist/components/particles/close-button/style.module.css.js +17 -0
- package/dist/components/particles/container/index.d.ts +5 -0
- package/dist/components/particles/container/index.js +13 -0
- package/dist/components/particles/container/style.module.scss.js +11 -0
- package/dist/components/particles/gradient-icon/index.d.ts +1 -0
- package/dist/components/particles/gradient-icon/index.js +46 -0
- package/dist/components/particles/gradient-icon/style.module.css.js +14 -0
- package/dist/components/particles/index.d.ts +18 -0
- package/dist/components/particles/info-button/index.d.ts +3 -0
- package/dist/components/particles/info-button/index.js +19 -0
- package/dist/components/particles/info-button/style.module.css.js +11 -0
- package/dist/components/particles/legend-item/index.d.ts +6 -0
- package/dist/components/particles/legend-item/index.js +26 -0
- package/dist/components/particles/legend-item/style.module.css.js +17 -0
- package/dist/components/particles/relative-time-sentence/index.d.ts +4 -0
- package/dist/components/particles/relative-time-sentence/index.js +14 -0
- package/dist/components/particles/relative-time-sentence/style.module.css.js +8 -0
- package/dist/components/particles/square-cut-corner-icon/index.d.ts +6 -0
- package/dist/components/particles/square-cut-corner-icon/index.js +56 -0
- package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +17 -0
- package/dist/components/particles/square-icon/index.d.ts +5 -0
- package/dist/components/particles/square-icon/index.js +28 -0
- package/dist/components/particles/square-icon/style.module.scss.js +11 -0
- package/dist/components/particles/stacked-bar/index.d.ts +23 -0
- package/dist/components/particles/stacked-bar/index.js +140 -0
- package/dist/components/particles/stacked-bar/style.module.css.js +17 -0
- package/dist/components/particles/stacked-grid/index.d.ts +6 -0
- package/dist/components/particles/stacked-grid/index.js +35 -0
- package/dist/components/particles/stacked-grid/style.module.css.js +20 -0
- package/dist/components/particles/waffle/index.d.ts +14 -0
- package/dist/components/particles/waffle/index.js +76 -0
- package/dist/components/particles/waffle/style.module.css.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +147 -0
- package/dist/shared/colors/index.d.ts +2 -0
- package/dist/shared/helpers/createStore.d.ts +1 -0
- package/dist/shared/helpers/geometry.d.ts +3 -0
- package/dist/shared/helpers/geometry.js +16 -0
- package/dist/shared/helpers/geometry.test.d.ts +1 -0
- package/dist/shared/helpers/labelsUtil.d.ts +54 -0
- package/dist/shared/helpers/labelsUtil.js +58 -0
- package/dist/shared/helpers/labelsUtils.test.d.ts +1 -0
- package/dist/shared/helpers/shouldUpdate.d.ts +7 -0
- package/dist/shared/hooks/index.d.ts +3 -0
- package/dist/shared/hooks/useContainerSize.d.ts +1 -0
- package/dist/shared/hooks/useContainerSize.js +24 -0
- package/dist/shared/hooks/useTouchOrHover.d.ts +7 -0
- package/dist/shared/hooks/useTouchOrHover.js +103 -0
- package/dist/shared/hooks/useWindowSize.d.ts +4 -0
- package/dist/shared/hooks/useWindowSize.js +27 -0
- package/dist/style.css +74 -74
- package/dist/styles/helpers/mergeStyles.d.ts +1 -0
- package/dist/styles/helpers/mergeStyles.js +22 -0
- package/dist/styles/helpers/mergeStyles.test.d.ts +1 -0
- package/dist/styles/theme.config.d.ts +124 -0
- package/package.json +19 -10
- package/dist/interactive-component-library.js +0 -8370
- package/dist/interactive-component-library.js.map +0 -1
- package/dist/interactive-component-library.umd.cjs +0 -8365
- package/dist/interactive-component-library.umd.cjs.map +0 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { View } from "./View.js";
|
|
2
|
+
import { sizeForElement } from "./util/size.js";
|
|
3
|
+
import { arrayEquals } from "./util/array.js";
|
|
4
|
+
import { containsCoordinate } from "./util/extent.js";
|
|
5
|
+
import { MapRenderer } from "./renderers/MapRenderer.js";
|
|
6
|
+
import { zoomIdentity, zoom } from "d3-zoom";
|
|
7
|
+
import { select } from "d3-selection";
|
|
8
|
+
import { timer } from "d3-timer";
|
|
9
|
+
import { Dispatcher } from "./events/Dispatcher.js";
|
|
10
|
+
import { MapEvent } from "./events/MapEvent.js";
|
|
11
|
+
import "d3-transition";
|
|
12
|
+
class Map {
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {Object} config - The configuration for the map.
|
|
16
|
+
* @param {Object} config.view - The view configuration for the map.
|
|
17
|
+
* @param {boolean} config.debug - Whether to enable debug mode or not.
|
|
18
|
+
* @param {HTMLElement} config.target - The target element to render the map into.
|
|
19
|
+
*/
|
|
20
|
+
constructor(config) {
|
|
21
|
+
if (config.debug) {
|
|
22
|
+
console.log("Map config", config);
|
|
23
|
+
}
|
|
24
|
+
this.options = config;
|
|
25
|
+
this.view = new View(config.view, config.debug);
|
|
26
|
+
this.target = config.target;
|
|
27
|
+
this.layers = [];
|
|
28
|
+
this.dispatcher = new Dispatcher(this);
|
|
29
|
+
this._viewport = document.createElement("div");
|
|
30
|
+
this._viewport.className = "gv-map";
|
|
31
|
+
this._viewport.style.position = "relative";
|
|
32
|
+
this._viewport.style.overflow = "hidden";
|
|
33
|
+
this._viewport.style.width = "100%";
|
|
34
|
+
this._viewport.style.height = "100%";
|
|
35
|
+
this.target.appendChild(this._viewport);
|
|
36
|
+
this._renderer = new MapRenderer(this);
|
|
37
|
+
this._resizeObserver = new ResizeObserver(() => {
|
|
38
|
+
this._updateSize();
|
|
39
|
+
});
|
|
40
|
+
this._resizeObserver.observe(this.target);
|
|
41
|
+
this._viewport.addEventListener("touchmove", (event) => {
|
|
42
|
+
if (event.targetTouches.length < 2 && this._collaborativeGesturesEnabled) {
|
|
43
|
+
this._filterEventCallback(true);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
destroy() {
|
|
48
|
+
this._resizeObserver.disconnect();
|
|
49
|
+
this._viewport.remove();
|
|
50
|
+
}
|
|
51
|
+
/** PUBLIC GETTERS */
|
|
52
|
+
get size() {
|
|
53
|
+
return this._size;
|
|
54
|
+
}
|
|
55
|
+
get viewPort() {
|
|
56
|
+
return this._viewport;
|
|
57
|
+
}
|
|
58
|
+
get zoomScale() {
|
|
59
|
+
return this.view.transform.k;
|
|
60
|
+
}
|
|
61
|
+
get isTransitioning() {
|
|
62
|
+
return this._isTransitioning;
|
|
63
|
+
}
|
|
64
|
+
/** PUBLIC METHODS */
|
|
65
|
+
collaborativeGesturesEnabled(enabled) {
|
|
66
|
+
if (enabled === void 0) return this._collaborativeGesturesEnabled;
|
|
67
|
+
this._collaborativeGesturesEnabled = enabled;
|
|
68
|
+
}
|
|
69
|
+
onFilterEvent(callback) {
|
|
70
|
+
this._filterEventCallback = callback;
|
|
71
|
+
}
|
|
72
|
+
fitObject(geoJSON) {
|
|
73
|
+
this.view.fitObject(geoJSON);
|
|
74
|
+
this._requestRender();
|
|
75
|
+
}
|
|
76
|
+
addLayer(layer) {
|
|
77
|
+
this.addLayers([layer]);
|
|
78
|
+
}
|
|
79
|
+
addLayers(layers) {
|
|
80
|
+
this.layers = this.layers.concat(layers);
|
|
81
|
+
layers.forEach((layer) => {
|
|
82
|
+
layer.on(MapEvent.CHANGE, () => {
|
|
83
|
+
this._requestRender();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
this._requestRender();
|
|
87
|
+
}
|
|
88
|
+
setLayers(layers) {
|
|
89
|
+
if (layers === this.layers) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
new Array(...this.layers).forEach((layer) => {
|
|
93
|
+
if (!layers.includes(layer)) {
|
|
94
|
+
this.removeLayer(layer);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.layers = [];
|
|
98
|
+
this.addLayers(layers);
|
|
99
|
+
}
|
|
100
|
+
removeLayer(layer) {
|
|
101
|
+
layer.tearDown();
|
|
102
|
+
const layerIndex = this.layers.indexOf(layer);
|
|
103
|
+
if (layerIndex < 0) return;
|
|
104
|
+
this.layers.splice(layerIndex, 1);
|
|
105
|
+
}
|
|
106
|
+
async zoomIn(options) {
|
|
107
|
+
return this.zoomTo(this.zoomScale * 2, options);
|
|
108
|
+
}
|
|
109
|
+
async zoomOut(options) {
|
|
110
|
+
return this.zoomTo(this.zoomScale * 0.5, options);
|
|
111
|
+
}
|
|
112
|
+
async zoomTo(zoomScale, options = { duration: 500 }) {
|
|
113
|
+
return select(this._viewport).transition().duration(options.duration).call(this._zoomBehaviour.scaleTo, zoomScale).end();
|
|
114
|
+
}
|
|
115
|
+
zoomToFeature(feature, focalPoint, padding = { top: 40, right: 40, bottom: 40, left: 40 }) {
|
|
116
|
+
const extent = feature.getExtent();
|
|
117
|
+
const {
|
|
118
|
+
minX: featureX,
|
|
119
|
+
minY: featureY,
|
|
120
|
+
width: featureWidth,
|
|
121
|
+
height: featureHeight
|
|
122
|
+
} = this.view.projectExtent(extent);
|
|
123
|
+
const [viewPortWidth, viewPortHeight] = this.view.viewPortSize;
|
|
124
|
+
const paddedViewPortWidth = viewPortWidth - padding.left - padding.right;
|
|
125
|
+
const paddedViewPortHeight = viewPortHeight - padding.top - padding.bottom;
|
|
126
|
+
const featureScale = Math.min(
|
|
127
|
+
paddedViewPortWidth / featureWidth,
|
|
128
|
+
paddedViewPortHeight / featureHeight
|
|
129
|
+
);
|
|
130
|
+
const zoomScale = Math.min(this.view.scaleExtent[1], featureScale);
|
|
131
|
+
const scaledPadding = {
|
|
132
|
+
top: padding.top / zoomScale,
|
|
133
|
+
right: padding.right / zoomScale,
|
|
134
|
+
bottom: padding.bottom / zoomScale,
|
|
135
|
+
left: padding.left / zoomScale
|
|
136
|
+
};
|
|
137
|
+
const paddedFeatureBounds = {
|
|
138
|
+
x: featureX - scaledPadding.left,
|
|
139
|
+
y: featureY - scaledPadding.top,
|
|
140
|
+
width: featureWidth + scaledPadding.left + scaledPadding.right,
|
|
141
|
+
height: featureHeight + scaledPadding.top + scaledPadding.bottom
|
|
142
|
+
};
|
|
143
|
+
const newTransform = zoomIdentity.translate(viewPortWidth / 2, viewPortHeight / 2).scale(zoomScale).translate(
|
|
144
|
+
-(paddedFeatureBounds.x + paddedFeatureBounds.width / 2),
|
|
145
|
+
-(paddedFeatureBounds.y + paddedFeatureBounds.height / 2)
|
|
146
|
+
);
|
|
147
|
+
select(this._viewport).transition().duration(500).call(this._zoomBehaviour.transform, newTransform, focalPoint);
|
|
148
|
+
}
|
|
149
|
+
/** @param {import("./layers").Layer[]} layers */
|
|
150
|
+
hasLayers(layers) {
|
|
151
|
+
if (layers.length !== this.layers.length) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
for (let i = 0; i < layers.length; i++) {
|
|
155
|
+
if (layers[i] !== this.layers[i]) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
async resetZoom(options) {
|
|
162
|
+
return this.zoomTo(1, options);
|
|
163
|
+
}
|
|
164
|
+
findFeatures(point) {
|
|
165
|
+
const mapCoordinate = this.view.invert(point);
|
|
166
|
+
const matchingFeatures = [];
|
|
167
|
+
for (const layer of this.layers) {
|
|
168
|
+
const layerExtent = layer.getExtent();
|
|
169
|
+
if (layer.hitDetectionEnabled && containsCoordinate(layerExtent, mapCoordinate)) {
|
|
170
|
+
const features = layer.findFeatures(mapCoordinate);
|
|
171
|
+
if (features) {
|
|
172
|
+
matchingFeatures.push(...features);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return matchingFeatures;
|
|
177
|
+
}
|
|
178
|
+
changed() {
|
|
179
|
+
this._requestRender();
|
|
180
|
+
}
|
|
181
|
+
async transition(options = { duration: 500 }, callback) {
|
|
182
|
+
const ease = options.ease || ((t) => t);
|
|
183
|
+
return new Promise((resolve) => {
|
|
184
|
+
this._isTransitioning = true;
|
|
185
|
+
this.dispatcher.dispatch(MapEvent.TRANSITION_START);
|
|
186
|
+
const _timer = timer((elapsed) => {
|
|
187
|
+
const t = Math.min(elapsed / options.duration, 1);
|
|
188
|
+
callback(ease(t));
|
|
189
|
+
this._renderFrame();
|
|
190
|
+
if (elapsed >= options.duration) {
|
|
191
|
+
_timer.stop();
|
|
192
|
+
this._isTransitioning = false;
|
|
193
|
+
this.dispatcher.dispatch(MapEvent.TRANSITION_END);
|
|
194
|
+
resolve();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/** PRIVATE METHODS */
|
|
200
|
+
_updateSize() {
|
|
201
|
+
const targetElement = this.target;
|
|
202
|
+
let newSize = sizeForElement(targetElement);
|
|
203
|
+
const oldSize = this.size;
|
|
204
|
+
if (newSize && (!oldSize || !arrayEquals(newSize, oldSize))) {
|
|
205
|
+
this._size = newSize;
|
|
206
|
+
this._updateViewportSize(newSize);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
_updateViewportSize(size) {
|
|
210
|
+
const view = this.view;
|
|
211
|
+
if (view) {
|
|
212
|
+
view.viewPortSize = size;
|
|
213
|
+
this._createZoomBehaviour(size);
|
|
214
|
+
}
|
|
215
|
+
this._requestRender();
|
|
216
|
+
}
|
|
217
|
+
_createZoomBehaviour(viewPortSize) {
|
|
218
|
+
if (this._zoomBehaviour) {
|
|
219
|
+
this._zoomBehaviour.on("zoom", null);
|
|
220
|
+
}
|
|
221
|
+
this._zoomBypassKey = navigator.userAgent.indexOf("Mac") !== -1 ? "metaKey" : "ctrlKey";
|
|
222
|
+
this._zoomBehaviour = zoom().extent([[0, 0], viewPortSize]).translateExtent([[0, 0], viewPortSize]).scaleExtent(this.view.scaleExtent).filter((event) => {
|
|
223
|
+
const filterEvent = (filter) => {
|
|
224
|
+
this._filterEventCallback(filter);
|
|
225
|
+
return !filter;
|
|
226
|
+
};
|
|
227
|
+
if (event.type === "wheel" && !event[this._zoomBypassKey]) {
|
|
228
|
+
return filterEvent(true);
|
|
229
|
+
}
|
|
230
|
+
if ("targetTouches" in event && this.collaborativeGesturesEnabled) {
|
|
231
|
+
if (event.targetTouches.length < 2) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
return filterEvent(false);
|
|
236
|
+
}
|
|
237
|
+
return (!event.ctrlKey || event.type === "wheel") && !event.button;
|
|
238
|
+
}).on("zoom", (event) => {
|
|
239
|
+
this.view.transform = event.transform;
|
|
240
|
+
this._requestRender();
|
|
241
|
+
this.dispatcher.dispatch(MapEvent.ZOOM, {
|
|
242
|
+
zoomScale: event.transform.k
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
select(this._viewport).call(this._zoomBehaviour);
|
|
246
|
+
}
|
|
247
|
+
_requestRender() {
|
|
248
|
+
if (!this._renderer || !!this._animationFrameRequestID || this._isTransitioning)
|
|
249
|
+
return;
|
|
250
|
+
this._animationFrameRequestID = requestAnimationFrame(
|
|
251
|
+
this._renderFrame.bind(this)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
_renderFrame() {
|
|
255
|
+
const frameState = {
|
|
256
|
+
size: this.size,
|
|
257
|
+
viewState: this.view.getState(),
|
|
258
|
+
debug: this.options.debug || false
|
|
259
|
+
};
|
|
260
|
+
this._renderer.renderFrame(frameState);
|
|
261
|
+
this._animationFrameRequestID = null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
Map.Component = void 0;
|
|
265
|
+
export {
|
|
266
|
+
Map
|
|
267
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Extent } from './util';
|
|
2
|
+
import { ZoomTransform } from 'd3-zoom';
|
|
3
|
+
/**
|
|
4
|
+
* @typedef ViewConfig
|
|
5
|
+
* @property {import("./projection").ProjectionFunction} projection - The projection to use for the view.
|
|
6
|
+
* @property {import("./util/bounds").GeoBounds} [bounds] - The bounds of the map view in projection coordinates.
|
|
7
|
+
* @property {import("./util/extent").ExtentLike} [extent] - The extent of the map view in screen coordinates (for preprojected geometry).
|
|
8
|
+
* @property {number} minZoom - The minimum zoom level for the view.
|
|
9
|
+
* @property {number} maxZoom - The maximum zoom level for the view.
|
|
10
|
+
* @property {Object} padding - The padding for the view in pixels.
|
|
11
|
+
* @property {boolean} [debug="false"] - Enable/disable debug mode.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Represents how the map is viewed.
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
export class View {
|
|
18
|
+
/**
|
|
19
|
+
* @constructor
|
|
20
|
+
* @property {ViewConfig} config - A view configuration object
|
|
21
|
+
*/
|
|
22
|
+
constructor({ projection, bounds, extent, minZoom, maxZoom, padding, }: {
|
|
23
|
+
projection?: {
|
|
24
|
+
(p: any): number[];
|
|
25
|
+
invert(p: any): number[];
|
|
26
|
+
stream(stream: any): any;
|
|
27
|
+
postclip(_: any, ...args: any[]): any;
|
|
28
|
+
clipExtent(_: any, ...args: any[]): any[][] | any;
|
|
29
|
+
scale(_: any, ...args: any[]): number | any;
|
|
30
|
+
translate(_: any, ...args: any[]): number[] | any;
|
|
31
|
+
angle(_: any, ...args: any[]): number | any;
|
|
32
|
+
reflectX(_: any, ...args: any[]): boolean | any;
|
|
33
|
+
reflectY(_: any, ...args: any[]): boolean | any;
|
|
34
|
+
fitExtent(extent: any, object: any): any;
|
|
35
|
+
fitSize(size: any, object: any): any;
|
|
36
|
+
fitWidth(width: any, object: any): any;
|
|
37
|
+
fitHeight(height: any, object: any): any;
|
|
38
|
+
};
|
|
39
|
+
bounds: any;
|
|
40
|
+
extent: any;
|
|
41
|
+
minZoom?: number;
|
|
42
|
+
maxZoom?: number;
|
|
43
|
+
padding?: {
|
|
44
|
+
top: number;
|
|
45
|
+
right: number;
|
|
46
|
+
bottom: number;
|
|
47
|
+
left: number;
|
|
48
|
+
};
|
|
49
|
+
}, debug?: boolean);
|
|
50
|
+
debug: boolean;
|
|
51
|
+
projection: {
|
|
52
|
+
(p: any): number[];
|
|
53
|
+
invert(p: any): number[];
|
|
54
|
+
stream(stream: any): any;
|
|
55
|
+
postclip(_: any, ...args: any[]): any;
|
|
56
|
+
clipExtent(_: any, ...args: any[]): any[][] | any;
|
|
57
|
+
scale(_: any, ...args: any[]): number | any;
|
|
58
|
+
translate(_: any, ...args: any[]): number[] | any;
|
|
59
|
+
angle(_: any, ...args: any[]): number | any;
|
|
60
|
+
reflectX(_: any, ...args: any[]): boolean | any;
|
|
61
|
+
reflectY(_: any, ...args: any[]): boolean | any;
|
|
62
|
+
fitExtent(extent: any, object: any): any;
|
|
63
|
+
fitSize(size: any, object: any): any;
|
|
64
|
+
fitWidth(width: any, object: any): any;
|
|
65
|
+
fitHeight(height: any, object: any): any;
|
|
66
|
+
};
|
|
67
|
+
bounds: Extent;
|
|
68
|
+
extent: Extent;
|
|
69
|
+
minZoom: number;
|
|
70
|
+
maxZoom: number;
|
|
71
|
+
_transform: ZoomTransform;
|
|
72
|
+
_padding: {
|
|
73
|
+
top: number;
|
|
74
|
+
right: number;
|
|
75
|
+
bottom: number;
|
|
76
|
+
left: number;
|
|
77
|
+
};
|
|
78
|
+
_viewPortSize: number[];
|
|
79
|
+
pixelRatio: number;
|
|
80
|
+
set viewPortSize(size: number[]);
|
|
81
|
+
get viewPortSize(): number[];
|
|
82
|
+
set transform(transform: ZoomTransform);
|
|
83
|
+
get transform(): ZoomTransform;
|
|
84
|
+
get mapSize(): any;
|
|
85
|
+
get padding(): {
|
|
86
|
+
top: number;
|
|
87
|
+
right: number;
|
|
88
|
+
bottom: number;
|
|
89
|
+
left: number;
|
|
90
|
+
};
|
|
91
|
+
get scaledPadding(): {
|
|
92
|
+
top: number;
|
|
93
|
+
right: number;
|
|
94
|
+
bottom: number;
|
|
95
|
+
left: number;
|
|
96
|
+
};
|
|
97
|
+
get baseResolution(): number;
|
|
98
|
+
/**
|
|
99
|
+
* Get the lower and upper zoom scales
|
|
100
|
+
* @returns {[number, number]} - The lower and upper zoom scales
|
|
101
|
+
*/
|
|
102
|
+
get scaleExtent(): [number, number];
|
|
103
|
+
setProjection(projection: any): void;
|
|
104
|
+
setRawProjection(projection: any): void;
|
|
105
|
+
/**
|
|
106
|
+
* @param {import("./util").Extent} extent
|
|
107
|
+
*/
|
|
108
|
+
fitExtent(extent: import('./util').Extent): void;
|
|
109
|
+
fitBounds(bounds: any): void;
|
|
110
|
+
/**
|
|
111
|
+
* @param {import("./formats/GeoJSON").GeoJSONFeature} geoJSON
|
|
112
|
+
*/
|
|
113
|
+
fitObject(geoJSON: import('./formats/GeoJSON').GeoJSONFeature): void;
|
|
114
|
+
/**
|
|
115
|
+
* Returns extent in projection coordinates
|
|
116
|
+
*
|
|
117
|
+
* @param {Extent} extent
|
|
118
|
+
* @returns {Extent} - The extent relative to the current viewport
|
|
119
|
+
*/
|
|
120
|
+
projectExtent(extent: Extent): Extent;
|
|
121
|
+
invert(point: any): number[];
|
|
122
|
+
invertBounds(bounds: any): number[][];
|
|
123
|
+
getResolution(): number;
|
|
124
|
+
getZoomLevel(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Function that returns the extent of the view in screen coordinates
|
|
127
|
+
* The extent is defined as [[minX, minY], [maxX, maxY]]
|
|
128
|
+
* @function getMapExtent
|
|
129
|
+
* @returns {[[number, number], [number, number]]}
|
|
130
|
+
*/
|
|
131
|
+
getMapExtent(): [[number, number], [number, number]];
|
|
132
|
+
/**
|
|
133
|
+
* Get map bounds for current view
|
|
134
|
+
*
|
|
135
|
+
* @function getBounds
|
|
136
|
+
* @param {ZoomTransform} transform
|
|
137
|
+
* @param {*} projection
|
|
138
|
+
* @returns {import("./util").GeoBoundsLike}
|
|
139
|
+
*/
|
|
140
|
+
getVisibleBounds(transform: ZoomTransform, projection: any): import('./util').GeoBoundsLike;
|
|
141
|
+
getState(): {
|
|
142
|
+
transform: ZoomTransform;
|
|
143
|
+
projection: {
|
|
144
|
+
(p: any): number[];
|
|
145
|
+
invert(p: any): number[];
|
|
146
|
+
stream(stream: any): any;
|
|
147
|
+
postclip(_: any, ...args: any[]): any;
|
|
148
|
+
clipExtent(_: any, ...args: any[]): any[][] | any;
|
|
149
|
+
scale(_: any, ...args: any[]): number | any;
|
|
150
|
+
translate(_: any, ...args: any[]): number[] | any;
|
|
151
|
+
angle(_: any, ...args: any[]): number | any;
|
|
152
|
+
reflectX(_: any, ...args: any[]): boolean | any;
|
|
153
|
+
reflectY(_: any, ...args: any[]): boolean | any;
|
|
154
|
+
fitExtent(extent: any, object: any): any;
|
|
155
|
+
fitSize(size: any, object: any): any;
|
|
156
|
+
fitWidth(width: any, object: any): any;
|
|
157
|
+
fitHeight(height: any, object: any): any;
|
|
158
|
+
};
|
|
159
|
+
zoomLevel: any;
|
|
160
|
+
pixelRatio: number;
|
|
161
|
+
padding: {
|
|
162
|
+
top: number;
|
|
163
|
+
right: number;
|
|
164
|
+
bottom: number;
|
|
165
|
+
left: number;
|
|
166
|
+
};
|
|
167
|
+
viewPortSize: number[];
|
|
168
|
+
sizeInPixels: any;
|
|
169
|
+
visibleExtent: import('./util').GeoBoundsLike;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export type ViewConfig = {
|
|
173
|
+
/**
|
|
174
|
+
* - The projection to use for the view.
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* - The projection to use for the view.
|
|
178
|
+
*/
|
|
179
|
+
projection: import('./projection').ProjectionFunction;
|
|
180
|
+
/**
|
|
181
|
+
* - The bounds of the map view in projection coordinates.
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* - The bounds of the map view in projection coordinates.
|
|
185
|
+
*/
|
|
186
|
+
bounds?: import('./util/bounds').GeoBounds;
|
|
187
|
+
/**
|
|
188
|
+
* - The extent of the map view in screen coordinates (for preprojected geometry).
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* - The extent of the map view in screen coordinates (for preprojected geometry).
|
|
192
|
+
*/
|
|
193
|
+
extent?: import('./util/extent').ExtentLike;
|
|
194
|
+
/**
|
|
195
|
+
* - The minimum zoom level for the view.
|
|
196
|
+
*/
|
|
197
|
+
/**
|
|
198
|
+
* - The minimum zoom level for the view.
|
|
199
|
+
*/
|
|
200
|
+
minZoom: number;
|
|
201
|
+
/**
|
|
202
|
+
* - The maximum zoom level for the view.
|
|
203
|
+
*/
|
|
204
|
+
/**
|
|
205
|
+
* - The maximum zoom level for the view.
|
|
206
|
+
*/
|
|
207
|
+
maxZoom: number;
|
|
208
|
+
/**
|
|
209
|
+
* - The padding for the view in pixels.
|
|
210
|
+
*/
|
|
211
|
+
/**
|
|
212
|
+
* - The padding for the view in pixels.
|
|
213
|
+
*/
|
|
214
|
+
padding: any;
|
|
215
|
+
/**
|
|
216
|
+
* - Enable/disable debug mode.
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* - Enable/disable debug mode.
|
|
220
|
+
*/
|
|
221
|
+
debug?: boolean;
|
|
222
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { scaleSize, scalePadding, sizeMinusPadding } from "./util/size.js";
|
|
2
|
+
import { zoomIdentity, ZoomTransform } from "d3-zoom";
|
|
3
|
+
import { zoomLevelToZoomScale, zoomLevelForResolution } from "./util/zoomLevel.js";
|
|
4
|
+
import { GeoBounds } from "./util/bounds.js";
|
|
5
|
+
import { Extent } from "./util/extent.js";
|
|
6
|
+
import { bboxFeature } from "./util/bboxFeature.js";
|
|
7
|
+
import { resolutionForExtent } from "./util/resolution.js";
|
|
8
|
+
import { Projection } from "./projection/index.js";
|
|
9
|
+
import { generateDebugUrl } from "./util/debug.js";
|
|
10
|
+
class View {
|
|
11
|
+
/**
|
|
12
|
+
* @constructor
|
|
13
|
+
* @property {ViewConfig} config - A view configuration object
|
|
14
|
+
*/
|
|
15
|
+
constructor({
|
|
16
|
+
projection = Projection.geoIdentity,
|
|
17
|
+
bounds,
|
|
18
|
+
extent,
|
|
19
|
+
minZoom = 1,
|
|
20
|
+
maxZoom = 10,
|
|
21
|
+
padding = { top: 0, right: 0, bottom: 0, left: 0 }
|
|
22
|
+
}, debug = false) {
|
|
23
|
+
this.debug = debug;
|
|
24
|
+
projection.revision = 0;
|
|
25
|
+
this.projection = projection;
|
|
26
|
+
this.bounds = this.extent = Extent.convert(extent) || GeoBounds.convert(bounds).toExtent();
|
|
27
|
+
this.minZoom = minZoom;
|
|
28
|
+
this.maxZoom = maxZoom;
|
|
29
|
+
this._transform = zoomIdentity;
|
|
30
|
+
this._padding = padding;
|
|
31
|
+
this._viewPortSize = [0, 0];
|
|
32
|
+
this.pixelRatio = window.devicePixelRatio;
|
|
33
|
+
}
|
|
34
|
+
set viewPortSize(size) {
|
|
35
|
+
const previousSize = this._viewPortSize;
|
|
36
|
+
this._viewPortSize = size;
|
|
37
|
+
if (previousSize !== size) {
|
|
38
|
+
if (this.extent) {
|
|
39
|
+
this.fitBounds(this.extent);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
get viewPortSize() {
|
|
44
|
+
return this._viewPortSize;
|
|
45
|
+
}
|
|
46
|
+
set transform(transform) {
|
|
47
|
+
this._transform = transform;
|
|
48
|
+
}
|
|
49
|
+
get transform() {
|
|
50
|
+
return new ZoomTransform(
|
|
51
|
+
this._transform.k,
|
|
52
|
+
this._transform.x * this.pixelRatio,
|
|
53
|
+
this._transform.y * this.pixelRatio
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
// map size in pixels (i.e. scaled by device pixel ratio)
|
|
57
|
+
get mapSize() {
|
|
58
|
+
return scaleSize(this.viewPortSize, this.pixelRatio);
|
|
59
|
+
}
|
|
60
|
+
get padding() {
|
|
61
|
+
return this._padding;
|
|
62
|
+
}
|
|
63
|
+
// padding in pixels (i.e. scaled by device pixel ratio)
|
|
64
|
+
get scaledPadding() {
|
|
65
|
+
const scaledPadding = { ...this._padding };
|
|
66
|
+
return scalePadding(scaledPadding, this.pixelRatio);
|
|
67
|
+
}
|
|
68
|
+
get baseResolution() {
|
|
69
|
+
const baseExtent = this.getVisibleBounds(zoomIdentity, this.projection);
|
|
70
|
+
const baseResolution = resolutionForExtent(baseExtent, this.viewPortSize);
|
|
71
|
+
return baseResolution;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the lower and upper zoom scales
|
|
75
|
+
* @returns {[number, number]} - The lower and upper zoom scales
|
|
76
|
+
*/
|
|
77
|
+
get scaleExtent() {
|
|
78
|
+
const maxScale = zoomLevelToZoomScale(this.maxZoom, this.baseResolution);
|
|
79
|
+
return [1, maxScale];
|
|
80
|
+
}
|
|
81
|
+
setProjection(projection) {
|
|
82
|
+
this.projection = projection;
|
|
83
|
+
this.fitObject(bboxFeature(this.extent));
|
|
84
|
+
}
|
|
85
|
+
// only set the raw projection when it has already been configured with projection.fitExtent()
|
|
86
|
+
setRawProjection(projection) {
|
|
87
|
+
this.projection = projection;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @param {import("./util").Extent} extent
|
|
91
|
+
*/
|
|
92
|
+
fitExtent(extent) {
|
|
93
|
+
const boundsFeature = bboxFeature(extent);
|
|
94
|
+
this.fitObject(boundsFeature);
|
|
95
|
+
if (this.debug) {
|
|
96
|
+
console.log("Fit extent", extent, generateDebugUrl(boundsFeature, false));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
fitBounds(bounds) {
|
|
100
|
+
const boundsFeature = bboxFeature(bounds);
|
|
101
|
+
this.fitObject(boundsFeature);
|
|
102
|
+
if (this.debug) {
|
|
103
|
+
console.log("Fit extent", bounds, generateDebugUrl(boundsFeature, false));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param {import("./formats/GeoJSON").GeoJSONFeature} geoJSON
|
|
108
|
+
*/
|
|
109
|
+
fitObject(geoJSON) {
|
|
110
|
+
this.projection.fitExtent(this.getMapExtent(), geoJSON);
|
|
111
|
+
++this.projection.revision;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns extent in projection coordinates
|
|
115
|
+
*
|
|
116
|
+
* @param {Extent} extent
|
|
117
|
+
* @returns {Extent} - The extent relative to the current viewport
|
|
118
|
+
*/
|
|
119
|
+
projectExtent(extent) {
|
|
120
|
+
const [minX, minY] = this.projection([extent.minX, extent.minY]);
|
|
121
|
+
const [maxX, maxY] = this.projection([extent.maxX, extent.maxY]);
|
|
122
|
+
return new Extent(minX, minY, maxX, maxY).scale(1 / this.pixelRatio);
|
|
123
|
+
}
|
|
124
|
+
invert(point) {
|
|
125
|
+
const { projection, pixelRatio, transform } = this.getState();
|
|
126
|
+
const scaledPoint = [point[0] * pixelRatio, point[1] * pixelRatio];
|
|
127
|
+
const untransformedPoint = transform.invert(scaledPoint);
|
|
128
|
+
const mapCoordinate = projection.invert(untransformedPoint);
|
|
129
|
+
return mapCoordinate;
|
|
130
|
+
}
|
|
131
|
+
// bounds is defined as [[minX, minY], [maxX, maxY]]
|
|
132
|
+
invertBounds(bounds) {
|
|
133
|
+
const topLeft = bounds[0];
|
|
134
|
+
const topRight = [bounds[1][0], bounds[0][1]];
|
|
135
|
+
const bottomRight = [bounds[1][0], bounds[1][1]];
|
|
136
|
+
const bottomLeft = [bounds[0][0], bounds[1][1]];
|
|
137
|
+
const points = [topLeft, topRight, bottomRight, bottomLeft, topLeft];
|
|
138
|
+
return points.map((d) => this.invert(d));
|
|
139
|
+
}
|
|
140
|
+
// map resolution (meters per pixel)
|
|
141
|
+
getResolution() {
|
|
142
|
+
return resolutionForExtent(
|
|
143
|
+
this.getVisibleBounds(this.transform, this.projection),
|
|
144
|
+
this.viewPortSize
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
// map zoom level (0 = the entire world)
|
|
148
|
+
getZoomLevel() {
|
|
149
|
+
return zoomLevelForResolution(this.getResolution());
|
|
150
|
+
}
|
|
151
|
+
//
|
|
152
|
+
/**
|
|
153
|
+
* Function that returns the extent of the view in screen coordinates
|
|
154
|
+
* The extent is defined as [[minX, minY], [maxX, maxY]]
|
|
155
|
+
* @function getMapExtent
|
|
156
|
+
* @returns {[[number, number], [number, number]]}
|
|
157
|
+
*/
|
|
158
|
+
getMapExtent() {
|
|
159
|
+
const mapSizeInPixels = this.mapSize;
|
|
160
|
+
const paddingInPixels = this.scaledPadding;
|
|
161
|
+
return [
|
|
162
|
+
[paddingInPixels.left, paddingInPixels.top],
|
|
163
|
+
sizeMinusPadding(mapSizeInPixels, {
|
|
164
|
+
...paddingInPixels,
|
|
165
|
+
left: 0,
|
|
166
|
+
top: 0
|
|
167
|
+
})
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get map bounds for current view
|
|
172
|
+
*
|
|
173
|
+
* @function getBounds
|
|
174
|
+
* @param {ZoomTransform} transform
|
|
175
|
+
* @param {*} projection
|
|
176
|
+
* @returns {import("./util").GeoBoundsLike}
|
|
177
|
+
*/
|
|
178
|
+
getVisibleBounds(transform, projection) {
|
|
179
|
+
const [width, height] = this.mapSize;
|
|
180
|
+
const southWest = projection.invert(transform.invert([0, height]));
|
|
181
|
+
const northEast = projection.invert(transform.invert([width, 0]));
|
|
182
|
+
const southWestLatitude = southWest[1];
|
|
183
|
+
const northEastLatitude = northEast[1];
|
|
184
|
+
const flippedY = southWestLatitude < northEastLatitude;
|
|
185
|
+
if (flippedY) {
|
|
186
|
+
return [southWest[0], southWest[1], northEast[0], northEast[1]];
|
|
187
|
+
} else {
|
|
188
|
+
return [southWest[0], northEast[1], northEast[0], southWest[1]];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
getState() {
|
|
192
|
+
const transform = this.transform;
|
|
193
|
+
const projection = this.projection;
|
|
194
|
+
return {
|
|
195
|
+
transform,
|
|
196
|
+
projection,
|
|
197
|
+
zoomLevel: transform.k,
|
|
198
|
+
pixelRatio: this.pixelRatio,
|
|
199
|
+
padding: this.padding,
|
|
200
|
+
viewPortSize: this.viewPortSize,
|
|
201
|
+
sizeInPixels: scaleSize(this.viewPortSize, this.pixelRatio),
|
|
202
|
+
visibleExtent: this.getVisibleBounds(transform, projection)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
View
|
|
208
|
+
};
|