| 577 | }); |
| 578 | } |
| 579 | _attachedToMap() { |
| 580 | // set i to the position of this layer element in the set of layers |
| 581 | var i = 0, |
| 582 | position = 1; |
| 583 | for (var nodes = this.parentNode.children; i < nodes.length; i++) { |
| 584 | if ( |
| 585 | this.parentNode.children[i].nodeName === 'MAP-LAYER' || |
| 586 | this.parentNode.children[i].nodeName === 'LAYER-' |
| 587 | ) { |
| 588 | if (this.parentNode.children[i] === this) { |
| 589 | position = i + 1; |
| 590 | } else if (this.parentNode.children[i]._layer) { |
| 591 | this.parentNode.children[i]._layer.setZIndex(i + 1); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | var proj = this.parentNode.projection |
| 596 | ? this.parentNode.projection |
| 597 | : 'OSMTILE'; |
| 598 | setOptions(this._layer, { |
| 599 | zIndex: position, |
| 600 | mapprojection: proj, |
| 601 | opacity: window.getComputedStyle(this).opacity |
| 602 | }); |
| 603 | |
| 604 | if (this.checked) { |
| 605 | this._layer.addTo(this.parentNode._map); |
| 606 | // toggle the this.disabled attribute depending on whether the layer |
| 607 | // is: same prj as map, within view/zoom of map |
| 608 | } |
| 609 | this.parentNode._map.on('moveend layeradd', this._validateDisabled, this); |
| 610 | |
| 611 | this._layer.on('add remove', this._validateDisabled, this); |
| 612 | |
| 613 | if (this.parentNode._layerControl) |
| 614 | this._layerControl = this.parentNode._layerControl; |
| 615 | // if controls option is enabled, insert the layer into the overlays array |
| 616 | if (this.parentNode._layerControl && !this.hidden) { |
| 617 | this._layerControl.addOrUpdateOverlay(this._layer, this.label); |
| 618 | } |
| 619 | |
| 620 | // the mapml document associated to this layer can in theory contain many |
| 621 | // link[@rel=legend] elements with different @type or other attributes; |
| 622 | // currently only support a single link, don't care about type, lang etc. |
| 623 | // TODO: add support for full LayerLegend object, and > one link. |
| 624 | if (this._layer._legendUrl) { |
| 625 | this.legendLinks = [ |
| 626 | { |
| 627 | type: 'application/octet-stream', |
| 628 | href: this._layer._legendUrl, |
| 629 | rel: 'legend', |
| 630 | lang: null, |
| 631 | hreflang: null, |
| 632 | sizes: null |
| 633 | } |
| 634 | ]; |
| 635 | } |
| 636 | } |