Remove map from OverlayOptions

This commit is contained in:
Éric Lemoine
2013-09-02 14:14:04 +02:00
parent dd4b2e3e88
commit 7e25ecb3dc
6 changed files with 27 additions and 28 deletions

View File

@@ -37,9 +37,9 @@ geolocation.on('change', function() {
}); });
var marker = new ol.Overlay({ var marker = new ol.Overlay({
map: map,
element: /** @type {Element} */ ($('<i/>').addClass('icon-flag').get(0)) element: /** @type {Element} */ ($('<i/>').addClass('icon-flag').get(0))
}); });
map.addOverlay(marker);
// bind the marker position to the device location. // bind the marker position to the device location.
marker.bindTo('position', geolocation); marker.bindTo('position', geolocation);

View File

@@ -63,9 +63,9 @@ var map = new ol.Map({
var element = document.getElementById('popup'); var element = document.getElementById('popup');
var popup = new ol.Overlay({ var popup = new ol.Overlay({
map: map,
element: element element: element
}); });
map.addOverlay(popup);
map.on('click', function(evt) { map.on('click', function(evt) {

View File

@@ -24,17 +24,18 @@ var map = new ol.Map({
// Vienna label // Vienna label
var vienna = new ol.Overlay({ var vienna = new ol.Overlay({
map: map,
position: ol.proj.transform( position: ol.proj.transform(
[16.3725, 48.208889], 'EPSG:4326', 'EPSG:3857'), [16.3725, 48.208889], 'EPSG:4326', 'EPSG:3857'),
element: document.getElementById('vienna') element: document.getElementById('vienna')
}); });
map.addOverlay(vienna);
// Popup showing the position the user clicked // Popup showing the position the user clicked
var popup = new ol.Overlay({ var popup = new ol.Overlay({
map: map,
element: document.getElementById('popup') element: document.getElementById('popup')
}); });
map.addOverlay(popup);
map.on('click', function(evt) { map.on('click', function(evt) {
var element = popup.getElement(); var element = popup.getElement();
var coordinate = evt.getCoordinate(); var coordinate = evt.getCoordinate();

View File

@@ -7,24 +7,6 @@ goog.require('ol.proj');
goog.require('ol.source.TileJSON'); goog.require('ol.source.TileJSON');
var layer = new ol.layer.TileLayer({
source: new ol.source.TileJSON({
url: 'http://api.tiles.mapbox.com/v3/' +
'mapbox.natural-earth-hypso-bathy.jsonp',
crossOrigin: 'anonymous'
})
});
var map = new ol.Map({
layers: [layer],
target: 'map',
view: new ol.View2D({
center: [0, 0],
zoom: 2
})
});
/** /**
* Elements that make up the popup. * Elements that make up the popup.
*/ */
@@ -48,11 +30,32 @@ closer.onclick = function() {
* Create an overlay to anchor the popup to the map. * Create an overlay to anchor the popup to the map.
*/ */
var overlay = new ol.Overlay({ var overlay = new ol.Overlay({
map: map,
element: container element: container
}); });
/**
* Create the map.
*/
var map = new ol.Map({
layers: [
new ol.layer.TileLayer({
source: new ol.source.TileJSON({
url: 'http://api.tiles.mapbox.com/v3/' +
'mapbox.natural-earth-hypso-bathy.jsonp',
crossOrigin: 'anonymous'
})
})
],
overlays: [overlay],
target: 'map',
view: new ol.View2D({
center: [0, 0],
zoom: 2
})
});
/** /**
* Add a click handler to the map to render the popup. * Add a click handler to the map to render the popup.
*/ */

View File

@@ -60,7 +60,6 @@
* Object literal with config options for the overlay. * Object literal with config options for the overlay.
* @typedef {Object} ol.OverlayOptions * @typedef {Object} ol.OverlayOptions
* @property {Element|undefined} element The overlay element. * @property {Element|undefined} element The overlay element.
* @property {ol.Map|undefined} map The map to overlay onto.
* @property {ol.Coordinate|undefined} position The overlay position in map * @property {ol.Coordinate|undefined} position The overlay position in map
* projection. * projection.
* @property {ol.OverlayPositioning|undefined} positioning Positioning. * @property {ol.OverlayPositioning|undefined} positioning Positioning.

View File

@@ -42,7 +42,6 @@ ol.OverlayPositioning = {
* Example: * Example:
* *
* var popup = new ol.Overlay({ * var popup = new ol.Overlay({
* map: map,
* element: document.getElementById('popup') * element: document.getElementById('popup')
* }); * });
* popup.setPosition(coordinate); * popup.setPosition(coordinate);
@@ -110,9 +109,6 @@ ol.Overlay = function(options) {
if (goog.isDef(options.positioning)) { if (goog.isDef(options.positioning)) {
this.setPositioning(options.positioning); this.setPositioning(options.positioning);
} }
if (goog.isDef(options.map)) {
this.setMap(options.map);
}
}; };
goog.inherits(ol.Overlay, ol.Object); goog.inherits(ol.Overlay, ol.Object);