1
1
import { createEl } from '../core/util/dom' ;
2
2
import Control , { ControlOptionsType } from './Control' ;
3
3
import Map from '../map/Map' ;
4
+ import { isString } from '../core/util' ;
4
5
5
6
/**
6
7
* @property {Object } options - options
@@ -14,7 +15,8 @@ const options: AttributionOptionsType = {
14
15
'bottom' : 0 ,
15
16
'left' : 0
16
17
} ,
17
- 'content' : '<a href="http://maptalks.org" target="_blank">maptalks</a>'
18
+ 'content' : '<a href="http://maptalks.org" target="_blank">maptalks</a>' ,
19
+ 'custom' : false
18
20
} ;
19
21
20
22
const layerEvents = 'addlayer removelayer setbaselayer baselayerremove' ;
@@ -58,6 +60,16 @@ class Attribution extends Control {
58
60
return this . _attributionContainer ;
59
61
}
60
62
63
+ getContent ( ) {
64
+ return this . options . content ;
65
+ }
66
+
67
+ setContent ( content : string | HTMLElement ) {
68
+ this . options . content = content ;
69
+ this . _update ( ) ;
70
+ return this ;
71
+ }
72
+
61
73
onAdd ( ) {
62
74
this . getMap ( ) . on ( layerEvents , this . _update , this ) ;
63
75
}
@@ -66,8 +78,28 @@ class Attribution extends Control {
66
78
this . getMap ( ) . off ( layerEvents , this . _update , this ) ;
67
79
}
68
80
81
+ //@internal
82
+ _updateContent ( ) {
83
+ const container = this . _attributionContainer ;
84
+ const content = this . options . content || '' ;
85
+ if ( container ) {
86
+ //clear
87
+ container . innerHTML = '' ;
88
+ if ( isString ( content ) ) {
89
+ container . innerHTML = content ;
90
+ } else if ( content instanceof HTMLElement ) {
91
+ container . appendChild ( container ) ;
92
+ }
93
+ }
94
+ return this ;
95
+ }
96
+
69
97
//@internal
70
98
_update ( ) {
99
+ if ( this . options . custom ) {
100
+ this . _updateContent ( ) ;
101
+ return ;
102
+ }
71
103
const map = this . getMap ( ) ;
72
104
if ( ! map ) {
73
105
return ;
@@ -99,5 +131,6 @@ Map.addOnLoadHook(function () {
99
131
export default Attribution ;
100
132
101
133
export type AttributionOptionsType = {
102
- content ?: string ;
134
+ content ?: string | HTMLElement ;
135
+ custom ?: boolean ;
103
136
} & ControlOptionsType ;
0 commit comments