@@ -8,6 +8,7 @@ App.map = (function ($, publ) {
8
8
9
9
var map , vector , bounds , contents , toolbar , geolocation = null ;
10
10
var features = [ ] ;
11
+ var layerArr = [ ]
11
12
12
13
// Quick hack
13
14
var quick_hack = {
@@ -50,6 +51,19 @@ App.map = (function ($, publ) {
50
51
// through the template causes encoding problems
51
52
publ . updateForm ( features ) ;
52
53
54
+ contents . layers . forEach ( function ( layer ) {
55
+ var s = layer . type . split ( "." ) ;
56
+ layerArr . push (
57
+ new ol . layer . Tile ( {
58
+ title : layer . name ,
59
+ baseLayer : true ,
60
+ visible : false ,
61
+ source : new ol [ s [ 1 ] ] [ s [ 2 ] ] ( layer . options )
62
+ } )
63
+ ) ;
64
+ } ) ;
65
+ layerArr [ 0 ] . setVisible ( true ) ;
66
+
53
67
// Layer for vector features
54
68
vector = new ol . layer . Vector ( {
55
69
title : "Features" ,
@@ -61,30 +75,7 @@ App.map = (function ($, publ) {
61
75
renderOrder : ol . ordering . yOrdering ( ) ,
62
76
style : this . getStyle
63
77
} ) ;
64
-
65
- var osm = new ol . layer . Tile ( {
66
- title : "OSM" ,
67
- baseLayer : true ,
68
- preview : "/plugin_assets/redmine_gtt/images/preview_osm.jpg" ,
69
- // source: new ol.source.OSM()
70
- source : new ol . source . OSM ( {
71
- url : "https://tile.openstreetmap.jp/{z}/{x}/{y}.png" ,
72
- attributions : '<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>' ,
73
- crossOrigin : null ,
74
- } )
75
- } ) ;
76
-
77
- var cmj = new ol . layer . Tile ( {
78
- title : "国土地理院" ,
79
- baseLayer : true ,
80
- preview : "/plugin_assets/redmine_gtt/images/preview_gsi.png" ,
81
- visible : false ,
82
- source : new ol . source . OSM ( {
83
- url : "https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png" ,
84
- attributions : '<a href="https://portal.cyberjapan.jp/help/termsofuse.html" target="_blank">国土地理院</a>' ,
85
- crossOrigin : null ,
86
- } )
87
- } ) ;
78
+ layerArr . push ( vector ) ;
88
79
89
80
// Layer for project boundary
90
81
bounds = new ol . layer . Vector ( {
@@ -101,6 +92,7 @@ App.map = (function ($, publ) {
101
92
} )
102
93
} )
103
94
} ) ;
95
+ layerArr . push ( bounds ) ;
104
96
105
97
// Render project boundary if bounds are available
106
98
if ( contents . bounds && contents . bounds !== null ) {
@@ -112,22 +104,20 @@ App.map = (function ($, publ) {
112
104
) ;
113
105
bounds . getSource ( ) . addFeature ( boundary ) ;
114
106
115
- cmj . addFilter ( new ol . filter . Mask ( {
116
- feature : boundary ,
117
- inner : false ,
118
- fill : new ol . style . Fill ( { color :[ 255 , 255 , 255 , 0.4 ] } )
119
- } ) ) ;
120
-
121
- osm . addFilter ( new ol . filter . Mask ( {
122
- feature : boundary ,
123
- inner : false ,
124
- fill : new ol . style . Fill ( { color :[ 255 , 255 , 255 , 0.4 ] } )
125
- } ) ) ;
107
+ layerArr . forEach ( function ( layer ) {
108
+ if ( layer . get ( "baseLayer" ) ) {
109
+ layer . addFilter ( new ol . filter . Mask ( {
110
+ feature : boundary ,
111
+ inner : false ,
112
+ fill : new ol . style . Fill ( { color :[ 255 , 255 , 255 , 0.4 ] } )
113
+ } ) ) ;
114
+ }
115
+ } ) ;
126
116
}
127
117
128
118
map = new ol . Map ( {
129
119
target : options . target ,
130
- layers : [ osm , cmj , bounds , vector ] ,
120
+ layers : layerArr ,
131
121
controls : ol . control . defaults ( {
132
122
attributionOptions : ( {
133
123
collapsible : false
@@ -179,7 +169,7 @@ App.map = (function ($, publ) {
179
169
} ) ;
180
170
181
171
// Add LayerSwitcher Image Toolbar
182
- map . addControl ( new ol . control . LayerSwitcherImage ( ) ) ;
172
+ map . addControl ( new ol . control . LayerPopup ( ) ) ;
183
173
} ;
184
174
185
175
publ . getColor = function ( feature ) {
0 commit comments