Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created May 10, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixlindemann/db8001461a7aa52d072c801d5265dd15 to your computer and use it in GitHub Desktop.
Save felixlindemann/db8001461a7aa52d072c801d5265dd15 to your computer and use it in GitHub Desktop.
altered version of the olMap.Demo.js
var map;
var highlightStyleCache = {};
$('#btnAddDemo').click(function (evt) {
evt.preventDefault();
olMapControls.Layers.ReadGpx("gpx/track.gpx", "Bycycle Tour Wuppertal 100km", "id_gpx100km");
addHoverSupport();
$(this).parent().remove();
});
$("#" + olMapControls.map.div).on('ReadGpx', function(){
var index = olMapControls.Layers.Tiles.length-1;
var value = olMapControls.Layers.Tiles[index];
console.log("index: " + index);
console.log("value: " + value);
AddButtonToOverlay("tracks",index, value);
});
var addHoverSupport = function(){
map = olMapControls.map.olmap;
var featureOverlay = new ol.FeatureOverlay({
map: map,
style: function(feature, resolution) {
var text = resolution < 5000 ? feature.get('name') : '';
if (!highlightStyleCache[text]) {
highlightStyleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#f00',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.1)'
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#f00',
width: 3
})
})
})];
}
return highlightStyleCache[text];
}
});
map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureInfo(pixel);
});
map.on('click', function(evt) {
displayFeatureInfo(evt.pixel);
});
};
var highlight;
var displayFeatureInfo = function(pixel) {
var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
return feature;
});
if (feature !== highlight) {
if (highlight) {
featureOverlay.removeFeature(highlight);
}
if (feature) {
featureOverlay.addFeature(feature);
}
highlight = feature;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment