Show hasFeatureAtPixel in example

This commit is contained in:
tsauerwein
2014-12-19 14:51:17 +01:00
parent bc71a36292
commit 3e5c4d0bf6
2 changed files with 34 additions and 1 deletions

View File

@@ -30,7 +30,7 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span8">
<h4 id="title">Icon sprite with WebGL example</h4> <h4 id="title">Icon sprite with WebGL example</h4>
<p id="shortdesc">Icon sprite with WebGL.</p> <p id="shortdesc">Icon sprite with WebGL.</p>
<div id="docs"> <div id="docs">
@@ -39,6 +39,11 @@
</div> </div>
<div id="tags">webgl, icon, sprite, vector, point</div> <div id="tags">webgl, icon, sprite, vector, point</div>
</div> </div>
<div class="span2 offset2">
<div id="info" class="alert alert-success">
&nbsp;
</div>
</div>
</div> </div>

View File

@@ -109,3 +109,31 @@ var featureOverlay = new ol.FeatureOverlay({
}), }),
features: overlayFeatures features: overlayFeatures
}); });
map.on('click', function(evt) {
var info = document.getElementById('info');
info.innerHTML =
'Hold on a second, while I catch those butterflies for you ...';
window.setTimeout(function() {
var features = [];
map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
features.push(features);
return false;
});
if (features.length === 1) {
info.innerHTML = 'Got one butterfly';
} else if (features.length > 1) {
info.innerHTML = 'Got ' + features.length + ' butterflies';
} else {
info.innerHTML = 'Couldn\'t catch a single butterfly';
}
}, 1);
});
$(map.getViewport()).on('mousemove', function(evt) {
var pixel = map.getEventPixel(evt.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTarget().style.cursor = hit ? 'pointer' : '';
});