|
40 | 40 | initialScrollPositionDelay: "${grailsApplication.config.getProperty('reports.initialScrollPositionDelay') ?: 1000}"
|
41 | 41 | },
|
42 | 42 | here = document.location.href;
|
| 43 | + <g:if test="${selectableFeaturesUrl}"> |
| 44 | + fcConfig.selectableFeaturesUrl = "${selectableFeaturesUrl}"; |
| 45 | + </g:if> |
43 | 46 | </script>
|
44 | 47 | <asset:stylesheet src="common-bs4.css"/>
|
45 | 48 | <asset:stylesheet src="activity.css"/>
|
|
143 | 146 | var metaModel = <fc:modelAsJavascript model="${metaModel}" default="{}"/>
|
144 | 147 | var master = null;
|
145 | 148 | var mapPopupSelector = '#map-modal';
|
146 |
| - var features = <fc:modelAsJavascript model="${features}" default="{}"/> |
147 | 149 | var reportMasterOptions = {
|
148 | 150 | locked: locked,
|
149 | 151 | activityUpdateUrl: fcConfig.activityUpdateUrl,
|
150 | 152 | healthCheckUrl: fcConfig.healthCheckUrl,
|
151 | 153 | projectTargetsAndScoresUrl: fcConfig.projectTargetsAndScoresUrl,
|
152 | 154 | performOverDeliveryCheck: true
|
153 | 155 | };
|
| 156 | + function categoriseSelectableSites(features) { |
| 157 | + if (!features || !_.isArray(features)) { |
| 158 | + return null; |
| 159 | + } |
| 160 | + var planningSitesCategory = 'Planning Sites'; |
| 161 | + var planningFeatures = []; |
| 162 | + var allFeatures = []; |
| 163 | + _.each(features, function (feature) { |
| 164 | + // Group the planning sites together into a single collection |
| 165 | + if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) { |
| 166 | + planningFeatures.push(feature); |
| 167 | + } else { |
| 168 | + allFeatures.push(feature); |
| 169 | + } |
| 170 | + }); |
| 171 | + if (planningFeatures.length > 0) { |
| 172 | + allFeatures.unshift({ |
| 173 | + type: 'Feature Collection', |
| 174 | + features: planningFeatures, |
| 175 | + properties: {category: planningSitesCategory, name: planningSitesCategory} |
| 176 | + }); |
| 177 | + } |
| 178 | + return allFeatures; |
| 179 | + } |
154 | 180 | if (metaModel.supportsSites) {
|
155 | 181 | // Workaround for problems with IE11 and leaflet draw
|
156 | 182 | L.Browser.touch = false;
|
|
159 | 185 | if (fcConfig.useGoogleBaseMap) {
|
160 | 186 | mapOptions.baseLayersName = 'Google'; // Default is Open Street Maps
|
161 | 187 | }
|
162 |
| - var planningSitesCategory = 'Planning Sites'; |
163 |
| - if (features && _.isArray(features)) { |
164 |
| - var planningFeatures = []; |
165 |
| - var allFeatures = []; |
166 |
| - _.each(features, function (feature) { |
167 |
| - // Group the planning sites together into a single collection |
168 |
| - if (feature.properties && feature.properties.category && feature.properties.category == planningSitesCategory) { |
169 |
| - planningFeatures.push(feature); |
170 |
| - } else { |
171 |
| - allFeatures.push(feature); |
172 |
| - } |
173 |
| - }); |
174 |
| - if (planningFeatures.length > 0) { |
175 |
| - allFeatures.unshift({ |
176 |
| - type: 'Feature Collection', |
177 |
| - features: planningFeatures, |
178 |
| - properties: {category: planningSitesCategory, name: planningSitesCategory} |
179 |
| - }); |
180 |
| - } |
181 |
| - mapOptions.selectableFeatures = allFeatures; |
182 |
| -
|
183 | 188 |
|
184 |
| - } |
| 189 | + mapOptions.selectableFeatures = $.Deferred(); |
| 190 | + $.get(fcConfig.selectableFeaturesUrl).done(function(features) { |
| 191 | + if (features && features.features) { |
| 192 | + mapOptions.selectableFeatures.resolve(categoriseSelectableSites(features.features)); |
| 193 | + } |
| 194 | + }); |
185 | 195 |
|
186 | 196 | var formFeatures = new ecodata.forms.FeatureCollection(reportSite ? reportSite.features : []);
|
187 | 197 | context.featureCollection = formFeatures;
|
|
0 commit comments