layer extent example changes for testing
- add draw extent tool - rotation control
This commit is contained in:
@@ -14,3 +14,4 @@ tags: "extent, tilejson"
|
||||
<button type="button" class="btn btn-default" id="southeast">southeast</button>
|
||||
<button type="button" class="btn btn-default" id="southwest">southwest</button>
|
||||
<button type="button" class="btn btn-default" id="world">world</button>
|
||||
<button type="button" class="btn btn-default" id="draw">draw</button>
|
||||
|
||||
@@ -3,6 +3,8 @@ goog.require('ol.View');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.TileJSON');
|
||||
goog.require('ol.interaction.Draw');
|
||||
goog.require('ol.interaction.DragRotateAndZoom');
|
||||
|
||||
function transform(extent) {
|
||||
return ol.proj.transformExtent(extent, 'EPSG:4326', 'EPSG:3857');
|
||||
@@ -43,6 +45,37 @@ var map = new ol.Map({
|
||||
})
|
||||
});
|
||||
|
||||
function box(coordinates, geometry) {
|
||||
if (!geometry) {
|
||||
geometry = new ol.geom.Polygon(null);
|
||||
}
|
||||
var start = coordinates[0];
|
||||
var end = coordinates[1];
|
||||
|
||||
geometry.setCoordinates([
|
||||
[start, [start[0], end[1]], end, [end[0], start[1]], start]
|
||||
]);
|
||||
return geometry;
|
||||
}
|
||||
|
||||
|
||||
var draw = new ol.interaction.Draw({
|
||||
type: /** @type {ol.geom.GeometryType} */ ('LineString'),
|
||||
geometryFunction: box,
|
||||
maxPoints: 2
|
||||
});
|
||||
|
||||
draw.on('drawend', function(ev) {
|
||||
var extent = ev.feature.getGeometry().getExtent();
|
||||
overlay.setExtent(extent);
|
||||
});
|
||||
|
||||
map.addInteraction(new ol.interaction.DragRotateAndZoom());
|
||||
|
||||
document.getElementById('draw').onclick = function() {
|
||||
map.addInteraction(draw);
|
||||
};
|
||||
|
||||
for (var key in extents) {
|
||||
document.getElementById(key).onclick = function(event) {
|
||||
overlay.setExtent(extents[event.target.id]);
|
||||
|
||||
Reference in New Issue
Block a user