Skip to content

Instantly share code, notes, and snippets.

@kerel-fs
Created July 19, 2015 15:41
Show Gist options
  • Save kerel-fs/318cda5a1aa58cba4776 to your computer and use it in GitHub Desktop.
Save kerel-fs/318cda5a1aa58cba4776 to your computer and use it in GitHub Desktop.
xcsoar map generator - openlayers-fronted
var map = new ol.Map({
layers: [
new ol.layer.Tile({ source: new ol.source.OSM() })
],
view: new ol.View({
center: [0,0],
zoom: 2
}),
target: 'map'
});
// a DragBox interaction used to select features by drawing boxes
var dragBox = new ol.interaction.DragBox({
condition: ol.events.condition.ctrlKeyOnly,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: [0, 0, 255, 1]
})
})
});
map.addInteraction(dragBox);
dragBox.on('boxstart', function(boxcoord) {
fill_boxes(boxcoord.coordinate,false);
});
dragBox.on('boxend', function(boxcoord) {
fill_boxes(boxcoord.coordinate,true);
});
function fill_boxes(coordinates,is_end) {
var lonlat = ol.proj.transform(coordinates,"EPSG:900913","EPSG:4326");
var coor0 = lonlat[0];
var coor1 = lonlat[1];
if (is_end) {
$("#left").val(coor0);
$("#top").val(coor1);
} else {
$("#right").val(coor0);
$("#bottom").val(coor1);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment