Files
openlayers/examples/anchored-elements.js
Tom Payne dda51ecec2 Replace ol.overlay.Overlay with ol.AnchoredElement
This commit adds several features:
- rename of class to better reflect its behaviour
- full ol.Object support
- integration with postrender event for integration with animations and
  render loop
- minimised DOM modifications
- more precise positioning
- element placed in DIV to avoid modifications to user-supplied element
- correctly handle changes to the positioning property
2013-01-22 15:12:25 +01:00

54 lines
1.5 KiB
JavaScript

goog.require('goog.debug.Console');
goog.require('goog.debug.Logger');
goog.require('goog.debug.Logger.Level');
goog.require('ol.AnchoredElement');
goog.require('ol.Collection');
goog.require('ol.Coordinate');
goog.require('ol.Map');
goog.require('ol.RendererHints');
goog.require('ol.View2D');
goog.require('ol.source.MapQuestOpenAerial');
if (goog.DEBUG) {
goog.debug.Console.autoInstall();
goog.debug.Logger.getLogger('ol').setLevel(goog.debug.Logger.Level.INFO);
}
var layer = new ol.layer.TileLayer({
source: new ol.source.MapQuestOpenAerial()
});
var map = new ol.Map({
layers: new ol.Collection([layer]),
renderers: ol.RendererHints.createFromQueryData(),
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(0, 0),
zoom: 2
})
});
// Vienna label
var vienna = new ol.AnchoredElement({
map: map,
position: ol.Projection.transformWithCodes(
new ol.Coordinate(16.3725, 48.208889), 'EPSG:4326', 'EPSG:3857'),
element: document.getElementById('vienna')
});
// Popup showing the position the user clicked
var popup = new ol.AnchoredElement({
map: map,
element: document.getElementById('popup')
});
map.addEventListener('click', function(evt) {
var coordinate = evt.getCoordinate();
popup.getElement().innerHTML =
'Welcome to ol3. The location you clicked was<br>' +
ol.Coordinate.toStringHDMS(ol.Projection.transformWithCodes(
coordinate, 'EPSG:3857', 'EPSG:4326'));
popup.setPosition(coordinate);
});