Skip to content

Commit 0cf3dc5

Browse files
committed
Website updates
1 parent 9e18454 commit 0cf3dc5

19 files changed

+272
-132
lines changed

dist/en/main/examples/box-selection.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ <h5 class="modal-title" id="tag-example-title"></h5>
156156

157157
<div class="row-fluid">
158158
<p id="shortdesc">Using a DragBox interaction to select features.</p>
159-
<div id="docs"><p>This example shows how to use a <code>DragBox</code> interaction to select features. Selected features are added to the feature overlay of a select interaction (<code>ol/interaction/Select</code>) for highlighting.</p> <p>Use <code>Ctrl+Drag</code> (<code>Command+Drag</code> on Mac) to draw boxes.</p>
159+
<div id="docs"><p>This example shows how to use a <code>DragBox</code> interaction to select features. Features are selected using a select interaction (<code>ol/interaction/Select</code>), to recieve highlighting and apply filters (features with color <span style="background-color: #CC6767;">#CC6767</span> are not selectable)</p> <p>Use <code>Ctrl+Drag</code> (<code>Command+Drag</code> on Mac) to draw boxes.</p>
160160
</div>
161161
</div>
162162

@@ -218,6 +218,9 @@ <h5 class="source-heading">main.js</h5>
218218

219219
// a normal select interaction to handle click
220220
const select &#x3D; new Select({
221+
filter: function (feature) {
222+
return !(feature.get(&#x27;COLOR_BIO&#x27;) &#x3D;&#x3D;&#x3D; &#x27;#CC6767&#x27;);
223+
},
221224
style: function (feature) {
222225
const color &#x3D; feature.get(&#x27;COLOR_BIO&#x27;) || &#x27;#eeeeee&#x27;;
223226
selectedStyle.getFill().setColor(color);
@@ -226,8 +229,6 @@ <h5 class="source-heading">main.js</h5>
226229
});
227230
map.addInteraction(select);
228231

229-
const selectedFeatures &#x3D; select.getFeatures();
230-
231232
// a DragBox interaction used to select features by drawing boxes
232233
const dragBox &#x3D; new DragBox({
233234
condition: platformModifierKeyOnly,
@@ -251,11 +252,7 @@ <h5 class="source-heading">main.js</h5>
251252

252253
const boxFeatures &#x3D; vectorSource
253254
.getFeaturesInExtent(extent)
254-
.filter(
255-
(feature) &#x3D;&gt;
256-
!selectedFeatures.getArray().includes(feature) &amp;&amp;
257-
feature.getGeometry().intersectsExtent(extent),
258-
);
255+
.filter((feature) &#x3D;&gt; feature.getGeometry().intersectsExtent(extent));
259256

260257
// features that intersect the box geometry are added to the
261258
// collection of selected features
@@ -281,26 +278,29 @@ <h5 class="source-heading">main.js</h5>
281278
const geometry &#x3D; feature.getGeometry().clone();
282279
geometry.rotate(-rotation, anchor);
283280
if (geometry.intersectsExtent(extent)) {
284-
selectedFeatures.push(feature);
281+
select.selectFeature(feature);
285282
}
286283
});
287284
} else {
288-
selectedFeatures.extend(boxFeatures);
285+
boxFeatures.forEach(select.selectFeature.bind(select));
289286
}
290287
}
291288
});
292289

293290
// clear selection when drawing a new box and when clicking on the map
294291
dragBox.on(&#x27;boxstart&#x27;, function () {
295-
selectedFeatures.clear();
292+
select.clearSelection();
296293
});
297294

298295
const infoBox &#x3D; document.getElementById(&#x27;info&#x27;);
299296

300-
selectedFeatures.on([&#x27;add&#x27;, &#x27;remove&#x27;], function () {
301-
const names &#x3D; selectedFeatures.getArray().map((feature) &#x3D;&gt; {
302-
return feature.get(&#x27;ECO_NAME&#x27;);
303-
});
297+
select.on(&#x27;select&#x27;, function () {
298+
const names &#x3D; select
299+
.getFeatures()
300+
.getArray()
301+
.map((feature) &#x3D;&gt; {
302+
return feature.get(&#x27;ECO_NAME&#x27;);
303+
});
304304
if (names.length &gt; 0) {
305305
infoBox.innerHTML &#x3D; names.join(&#x27;, &#x27;);
306306
} else {

dist/en/main/examples/box-selection.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)