Created
July 19, 2015 15:41
-
-
Save kerel-fs/318cda5a1aa58cba4776 to your computer and use it in GitHub Desktop.
xcsoar map generator - openlayers-fronted
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
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