1
1
import { Margin , ORIENTATION , PAPER_FORMAT } from "@giscience/ol-print-layout-control" ;
2
2
import { get as getProjection , toLonLat , transformExtent } from "ol/proj" ;
3
3
import { SKETCH_MAP_MARGINS } from "./sketchMapMargins" ;
4
- import { fillSelectOptions } from "../shared" ;
5
4
6
5
function bindFormToPrintLayoutControl ( printLayoutControl , messageController ) {
7
6
const paperFormats = { ...PAPER_FORMAT } ;
@@ -10,12 +9,6 @@ function bindFormToPrintLayoutControl(printLayoutControl, messageController) {
10
9
// TODO: This is temporary. Delete once A0 works
11
10
delete paperFormats . A0 ;
12
11
13
- // property: format
14
- fillSelectOptions ( "format" , paperFormats ) ;
15
-
16
- // set initial form value from ol-control
17
- document . getElementById ( "format" ) . value = printLayoutControl . getFormat ( ) ;
18
-
19
12
// bind listeners to update ol-control from form
20
13
document . getElementById ( "format" )
21
14
. addEventListener ( "change" , ( event ) => {
@@ -27,9 +20,6 @@ function bindFormToPrintLayoutControl(printLayoutControl, messageController) {
27
20
) ;
28
21
} ) ;
29
22
30
- // property: orientation
31
- fillSelectOptions ( "orientation" , ORIENTATION ) ;
32
-
33
23
// set initial form value from ol-control
34
24
document . getElementById ( "orientation" ) . value = printLayoutControl . getOrientation ( ) ;
35
25
@@ -78,6 +68,10 @@ function bindFormToPrintLayoutControl(printLayoutControl, messageController) {
78
68
79
69
// disable form submit and display info if zoom is lower than 9
80
70
function handleZoomChange ( zoom ) {
71
+ document . getElementById ( "zoom" ) . value = zoom ;
72
+ document . getElementById ( "page-setup-form" ) . dispatchEvent ( new CustomEvent ( "zoom-updated" , {
73
+ detail : { value : zoom } ,
74
+ } ) ) ;
81
75
if ( zoom < 9 ) {
82
76
messageController . addWarning ( "zoom-info" ) ;
83
77
} else {
@@ -132,19 +126,24 @@ function bindFormToPrintLayoutControl(printLayoutControl, messageController) {
132
126
printLayoutControl . on ( "change:bbox" , ( event ) => {
133
127
// update the URL when the selection is changed (e.g. to bookmark the current selection)
134
128
const newCenter = printLayoutControl . getMap ( ) . getView ( ) . getCenter ( ) ;
135
- window . history . replaceState ( { } , "" , `?center=${ newCenter } ` ) ;
129
+ document . getElementById ( "center" ) . value = newCenter ;
130
+ document . getElementById ( "page-setup-form" ) . dispatchEvent ( new CustomEvent ( "center-updated" , {
131
+ detail : { value : newCenter } ,
132
+ } ) ) ;
136
133
// show warning and disable form if bbox crosses the antimeridian
137
134
handleAntimeridian ( event . target . getBboxAsLonLat ( ) ) ;
138
135
} ) ;
139
136
}
140
137
141
138
function bindFormToLayerSwitcherControl ( layerSwitcherControl ) {
142
- // set initial form value from ol-control
139
+ // set initial form value from ol-control
143
140
document . getElementById ( "layer" ) . value = layerSwitcherControl . get ( "activeLayer" ) . name ;
144
-
145
141
function handleLayerSwitch ( event ) {
146
142
const activeLayerName = event . target . get ( "activeLayer" ) . name ;
147
143
document . getElementById ( "layer" ) . value = activeLayerName ;
144
+ document . getElementById ( "page-setup-form" ) . dispatchEvent ( new CustomEvent ( "layer-updated" , {
145
+ detail : { value : activeLayerName } ,
146
+ } ) ) ;
148
147
}
149
148
layerSwitcherControl . on ( "change:activeLayer" , handleLayerSwitch ) ;
150
149
}
0 commit comments