1
1
import { Map , View } from "ol" ;
2
- import type { ViewOptions } from "ol/View" ;
2
+ // import type { ViewOptions } from "ol/View";
3
3
4
4
// import TileLayer from "ol/layer/Tile";
5
5
@@ -33,26 +33,43 @@ import type { MyMapOptions } from ".";
33
33
import type { Coordinate } from "ol/coordinate" ;
34
34
35
35
// ...
36
+ /*
36
37
type LayerStore = {
37
38
[key: string]: Layer;
38
39
};
40
+ */
39
41
40
- //
42
+ //
43
+ /*
41
44
type ControlStore = {
42
45
[key: string]: Control;
43
46
};
47
+ */
44
48
45
49
//
46
50
type Metadata = {
47
- layers : any [ ] ; //{ [key: string]: any };
48
- controls : any [ ] ; //{ [key: string]: any };
51
+ layers : any [ ] ;
52
+ controls : any [ ] ;
49
53
} ;
50
54
51
55
const TYPE_IDENTIFIER = "@@type" ;
52
56
const GEOJSON_IDENTIFIER = "@@geojson" ;
53
57
54
58
const jsonConverter = new JSONConverter ( ) ;
55
59
60
+ function parseViewDef ( viewDef : JSONDef ) : View {
61
+ const view = jsonConverter . parse ( viewDef ) as View ;
62
+ const center = view . getCenter ( ) ;
63
+ console . log ( "view center" , center )
64
+ if ( center && view . getProjection ( ) . getCode ( ) !== "EPSG:4326" ) {
65
+ const centerTransformed = fromLonLat ( center ) ;
66
+ console . log ( "view center transformed" , centerTransformed ) ;
67
+ view . setCenter ( centerTransformed ) ;
68
+ }
69
+
70
+ return view ;
71
+ }
72
+
56
73
function parseLayerDef ( layerDef : JSONDef ) : Layer {
57
74
const layer = jsonConverter . parse ( layerDef ) ;
58
75
layer . set ( "id" , layerDef . id ) ;
@@ -74,8 +91,6 @@ export default class MapWidget {
74
91
_container : HTMLElement ;
75
92
_map : Map ;
76
93
_metadata : Metadata = { layers : [ ] , controls : [ ] } ;
77
- // _layerStore: LayerStore = {};
78
- // _controlStore: ControlStore = {};
79
94
80
95
constructor ( mapElement : HTMLElement , mapOptions : MyMapOptions ) {
81
96
let baseLayers : Layer [ ] = [ ] // defaultLayers;
@@ -108,6 +123,7 @@ export default class MapWidget {
108
123
*/
109
124
110
125
// TODO: Move to func 'parseView'
126
+ /*
111
127
const view = jsonConverter.parse(mapOptions.view) as View;
112
128
const center = view.getCenter();
113
129
console.log("center", center)
@@ -116,6 +132,8 @@ export default class MapWidget {
116
132
console.log("centerTransformed", centerTransformed);
117
133
view.setCenter(centerTransformed);
118
134
}
135
+ */
136
+ const view = parseViewDef ( mapOptions . view ) ;
119
137
120
138
this . _container = mapElement ;
121
139
this . _map = new Map ( {
0 commit comments