initial Layer commit (base class for all layers)

This commit is contained in:
Vladimir Agafonkin 2013-12-05 19:16:17 +02:00
parent 1974ae7003
commit a30a872a78
9 changed files with 37 additions and 64 deletions

View File

@ -17,6 +17,7 @@ var deps = {
'geo/crs/CRS.Simple.js', 'geo/crs/CRS.Simple.js',
'geo/crs/CRS.EPSG3857.js', 'geo/crs/CRS.EPSG3857.js',
'geo/crs/CRS.EPSG4326.js', 'geo/crs/CRS.EPSG4326.js',
'layer/Layer.js',
'map/Map.js'], 'map/Map.js'],
desc: 'The core of the library, including OOP, events, DOM facilities, basic units, projections (EPSG:3857 and EPSG:4326) and the base Map class.' desc: 'The core of the library, including OOP, events, DOM facilities, basic units, projections (EPSG:3857 and EPSG:4326) and the base Map class.'
}, },

View File

@ -4,7 +4,6 @@
*/ */
L.FeatureGroup = L.LayerGroup.extend({ L.FeatureGroup = L.LayerGroup.extend({
includes: L.Mixin.Events,
statics: { statics: {
EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose' EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose'

View File

@ -2,8 +2,7 @@
* L.ImageOverlay is used to overlay images over the map (to specific geographical bounds). * L.ImageOverlay is used to overlay images over the map (to specific geographical bounds).
*/ */
L.ImageOverlay = L.Class.extend({ L.ImageOverlay = L.Layer.extend({
includes: L.Mixin.Events,
options: { options: {
opacity: 1 opacity: 1
@ -24,7 +23,7 @@ L.ImageOverlay = L.Class.extend({
this._initImage(); this._initImage();
} }
this._getPane().appendChild(this._image); this.getPane().appendChild(this._image);
map.on(this._getEvents(), this); map.on(this._getEvents(), this);
@ -37,11 +36,6 @@ L.ImageOverlay = L.Class.extend({
map.off(this._getEvents(), this); map.off(this._getEvents(), this);
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
setOpacity: function (opacity) { setOpacity: function (opacity) {
this.options.opacity = opacity; this.options.opacity = opacity;
this._updateOpacity(); this._updateOpacity();
@ -51,13 +45,13 @@ L.ImageOverlay = L.Class.extend({
// TODO remove bringToFront/bringToBack duplication from TileLayer/Path // TODO remove bringToFront/bringToBack duplication from TileLayer/Path
bringToFront: function () { bringToFront: function () {
if (this._image) { if (this._image) {
this._getPane().appendChild(this._image); this.getPane().appendChild(this._image);
} }
return this; return this;
}, },
bringToBack: function () { bringToBack: function () {
var pane = this._getPane(); var pane = this.getPane();
if (this._image) { if (this._image) {
pane.insertBefore(this._image, pane.firstChild); pane.insertBefore(this._image, pane.firstChild);
} }
@ -73,10 +67,6 @@ L.ImageOverlay = L.Class.extend({
return this.options.attribution; return this.options.attribution;
}, },
_getPane: function () {
return this._map._panes.overlayPane;
},
_getEvents: function () { _getEvents: function () {
var events = {viewreset: this._reset}; var events = {viewreset: this._reset};

18
src/layer/Layer.js Normal file
View File

@ -0,0 +1,18 @@
L.Layer = L.Class.extend({
includes: L.Mixin.Events,
options: {
pane: 'overlayPane'
},
addTo: function (map) {
map.addLayer(this);
return this;
},
getPane: function () {
// TODO make pane if not present
return this._map._panes[this.options.pane];
}
});

View File

@ -3,7 +3,8 @@
* you can manipulate the group (e.g. add/remove it) as one layer. * you can manipulate the group (e.g. add/remove it) as one layer.
*/ */
L.LayerGroup = L.Class.extend({ L.LayerGroup = L.Layer.extend({
initialize: function (layers) { initialize: function (layers) {
this._layers = {}; this._layers = {};
@ -76,11 +77,6 @@ L.LayerGroup = L.Class.extend({
this._map = null; this._map = null;
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
eachLayer: function (method, context) { eachLayer: function (method, context) {
for (var i in this._layers) { for (var i in this._layers) {
method.call(context, this._layers[i]); method.call(context, this._layers[i]);

View File

@ -6,10 +6,11 @@ L.Map.mergeOptions({
closePopupOnClick: true closePopupOnClick: true
}); });
L.Popup = L.Class.extend({ L.Popup = L.Layer.extend({
includes: L.Mixin.Events,
options: { options: {
pane: 'popupPane',
minWidth: 50, minWidth: 50,
maxWidth: 300, maxWidth: 300,
// maxHeight: <Number>, // maxHeight: <Number>,
@ -46,7 +47,7 @@ L.Popup = L.Class.extend({
L.DomUtil.setOpacity(this._container, 0); L.DomUtil.setOpacity(this._container, 0);
} }
this._getPane().appendChild(this._container); this.getPane().appendChild(this._container);
map.on(this._getEvents(), this); map.on(this._getEvents(), this);
this.update(); this.update();
@ -63,11 +64,6 @@ L.Popup = L.Class.extend({
} }
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
openOn: function (map) { openOn: function (map) {
map.openPopup(this); map.openPopup(this);
return this; return this;
@ -130,10 +126,6 @@ L.Popup = L.Class.extend({
this._adjustPan(); this._adjustPan();
}, },
_getPane: function () {
return this._map._panes.popupPane;
},
_getEvents: function () { _getEvents: function () {
var events = {viewreset: this._updatePosition}, var events = {viewreset: this._updatePosition},
options = this.options; options = this.options;

View File

@ -2,9 +2,7 @@
* L.Marker is used to display clickable/draggable icons on the map. * L.Marker is used to display clickable/draggable icons on the map.
*/ */
L.Marker = L.Class.extend({ L.Marker = L.Layer.extend({
includes: L.Mixin.Events,
options: { options: {
icon: new L.Icon.Default(), icon: new L.Icon.Default(),
@ -40,11 +38,6 @@ L.Marker = L.Class.extend({
} }
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
onRemove: function (map) { onRemove: function (map) {
if (this.dragging) { if (this.dragging) {
this.dragging.disable(); this.dragging.disable();

View File

@ -2,11 +2,11 @@
* L.GridLayer is used as base class for grid-like layers like TileLayer. * L.GridLayer is used as base class for grid-like layers like TileLayer.
*/ */
L.GridLayer = L.Class.extend({ L.GridLayer = L.Layer.extend({
includes: L.Mixin.Events,
options: { options: {
pane: 'tilePane',
tileSize: 256, tileSize: 256,
opacity: 1, opacity: 1,
@ -53,14 +53,9 @@ L.GridLayer = L.Class.extend({
this._container = this._map = null; this._container = this._map = null;
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
bringToFront: function () { bringToFront: function () {
if (this._map) { if (this._map) {
var pane = this._getPane(); var pane = this.getPane();
pane.appendChild(this._container); pane.appendChild(this._container);
this._setAutoZIndex(pane, Math.max); this._setAutoZIndex(pane, Math.max);
} }
@ -69,7 +64,7 @@ L.GridLayer = L.Class.extend({
bringToBack: function () { bringToBack: function () {
if (this._map) { if (this._map) {
var pane = this._getPane(); var pane = this.getPane();
pane.insertBefore(this._container, pane.firstChild); pane.insertBefore(this._container, pane.firstChild);
this._setAutoZIndex(pane, Math.min); this._setAutoZIndex(pane, Math.min);
} }
@ -108,11 +103,6 @@ L.GridLayer = L.Class.extend({
return this; return this;
}, },
_getPane: function () {
// TODO pane in options?
return this._map._panes.tilePane;
},
_getEvents: function () { _getEvents: function () {
var events = { var events = {
viewreset: this._reset, viewreset: this._reset,
@ -191,7 +181,7 @@ L.GridLayer = L.Class.extend({
this._updateOpacity(); this._updateOpacity();
} }
this._getPane().appendChild(this._container); this.getPane().appendChild(this._container);
}, },
_reset: function (e) { _reset: function (e) {

View File

@ -2,8 +2,7 @@
* L.Path is a base class for rendering vector paths on a map. Inherited by Polyline, Circle, etc. * L.Path is a base class for rendering vector paths on a map. Inherited by Polyline, Circle, etc.
*/ */
L.Path = L.Class.extend({ L.Path = L.Layer.extend({
includes: [L.Mixin.Events],
statics: { statics: {
// how much to extend the clip area around the map view // how much to extend the clip area around the map view
@ -64,11 +63,6 @@ L.Path = L.Class.extend({
}, this); }, this);
}, },
addTo: function (map) {
map.addLayer(this);
return this;
},
onRemove: function (map) { onRemove: function (map) {
L.DomUtil.remove(this._container); L.DomUtil.remove(this._container);