-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
acanimal
committed
Dec 14, 2014
1 parent
84b43dd
commit fddf79b
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!doctype html> | ||
<html class="no-js"> | ||
<head> | ||
include "head.html" | ||
|
||
<style> | ||
.toggle { | ||
width: 100px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<!--[if lt IE 10]> | ||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | ||
<![endif]--> | ||
|
||
<div class="container"> | ||
|
||
include "header.html" | ||
|
||
<h2>Selecting features within a vector box</h2> | ||
|
||
<p>The sample shows how we can combine the `ol.interacions.DragBox` and the `ol.interacions.Select` interactions to select those features that intersects with a given vector box:</p> | ||
|
||
<button id="select" type="button" class="btn btn-default btn-sm" data-toggle="button" aria-pressed="false">Box selection</button> | ||
|
||
<div id="map" class="map"></div> | ||
|
||
<h4 class="text-muted">Source code:</h4> | ||
<pre><code id="code_text" class="javascript"></code></pre> | ||
|
||
include "footer.html" | ||
|
||
</div> | ||
|
||
include "tail.html" | ||
|
||
include "ganalytics.html" | ||
|
||
<script id="code"> | ||
|
||
// Create vector layers | ||
var limitsLayer = new ol.layer.Vector({ | ||
source: new ol.source.StaticVector({ | ||
url: 'data/world_limits.json', | ||
format: new ol.format.TopoJSON(), | ||
projection: 'EPSG:3857' | ||
}) | ||
}); | ||
|
||
// Initialize the interactions | ||
var selectInteraction = new ol.interaction.Select({ | ||
condition: ol.events.condition.never | ||
}); | ||
var dragBoxInteraction = new ol.interaction.DragBox({ | ||
style: new ol.style.Style({ | ||
stroke: new ol.style.Stroke({ | ||
color: [250, 25, 25, 1] | ||
}) | ||
}) | ||
}); | ||
dragBoxInteraction.on('boxend', function(event) { | ||
var selectedFeatures = selectInteraction.getFeatures(); | ||
var extent = dragBoxInteraction.getGeometry().getExtent(); | ||
limitsLayer.getSource().forEachFeatureIntersectingExtent(extent, function(feature) { | ||
selectedFeatures.push(feature); | ||
}); | ||
}); | ||
|
||
// Create the map | ||
var map = new ol.Map({ | ||
target: 'map', // The DOM element that will contains the map | ||
renderer: 'canvas', // Force the renderer to be used | ||
layers: [ | ||
new ol.layer.Tile({ | ||
source: new ol.source.OSM() | ||
}), | ||
limitsLayer | ||
], | ||
view: new ol.View({ | ||
center: ol.proj.transform([2, 40], 'EPSG:4326', 'EPSG:3857'), | ||
zoom: 2 | ||
}) | ||
}); | ||
|
||
// Add or remove interactions | ||
$('#select').on('click', function(event) { | ||
var checked = !$('#select').hasClass('active'); | ||
if(checked) { | ||
map.addInteraction(selectInteraction); | ||
map.addInteraction(dragBoxInteraction); | ||
} else { | ||
map.removeInteraction(selectInteraction); | ||
map.removeInteraction(dragBoxInteraction); | ||
} | ||
}); | ||
</script> | ||
|
||
include "sourcecode.html" | ||
|
||
</body> | ||
</html> |