@@ -96,18 +96,32 @@ function DataLayerClusterer(optOptions) {
96
96
this . recolorSVG_ = typeof options . recolorSVG !== "undefined" && ( typeof options . recolorSVG === "string" || options . recolorSVG instanceof String || options . recolorSVG === false ) ? options . recolorSVG : 'g:first-child' ;
97
97
this . baseSVG_ = null ;
98
98
99
- this . setupStyles_ ( ) ;
99
+ if ( this . recolorSVG_ && this . imageExtension_ == 'svg' ) {
100
+ var self = this ,
101
+ xhr = new XMLHttpRequest ( ) ;
102
+ xhr . open ( "GET" , / \. s v g $ / . test ( this . imagePath_ ) ? this . imagePath_ : this . imagePath_ + '1.' + this . imageExtension_ ) ;
103
+ // Following line is just to be on the safe side;
104
+ // not needed if your server delivers SVG with correct MIME type
105
+ xhr . overrideMimeType ( "image/svg+xml" ) ;
106
+ xhr . send ( "" ) ;
100
107
101
- if ( this . setProperty_ ) {
102
- this . _dataLayer . forEach ( function ( feature ) {
103
- feature . setProperty ( 'in_cluster' , true ) ;
104
- } ) ;
105
- } else {
106
- this . _dataLayer . setStyle ( DataLayerClusterer . HIDDEN_FEATURE ) ;
107
- }
108
- if ( this . map !== null ) {
109
- this . setMap ( this . map ) ;
110
- }
108
+ xhr . onreadystatechange = function ( ) {
109
+ if ( this . readyState == 4 ) {
110
+ if ( this . status == 200 ) {
111
+ self . baseSVG_ = {
112
+ 'document' : xhr . responseXML . documentElement ,
113
+ 'colorElement' : xhr . responseXML . documentElement . querySelector ( self . recolorSVG_ )
114
+ } ;
115
+ if ( ! self . baseSVG_ . document || ! self . baseSVG_ . colorElement ) {
116
+ self . recolorSVG_ = false ;
117
+ }
118
+ } else {
119
+ self . recolorSVG_ = false ;
120
+ }
121
+ self . init_ ( ) ;
122
+ }
123
+ } ;
124
+ } else this . init_ ( ) ;
111
125
}
112
126
113
127
/* ---- Constants ---- */
@@ -1134,6 +1148,27 @@ DataLayerClusterer.MARKER_CLUSTER_IMAGE_PATH_ =
1134
1148
'https://cdn.rawgit.com/Connum/data-layer-clusterer/master/images/m' ;
1135
1149
DataLayerClusterer . MARKER_CLUSTER_IMAGE_EXTENSION_ = document . implementation . hasFeature ( "http://www.w3.org/TR/SVG11/feature#Image" , "1.1" ) ? 'svg' : 'png' ;
1136
1150
1151
+
1152
+ /**
1153
+ * Initialises the clustering when everything is ready
1154
+ *
1155
+ * @private
1156
+ */
1157
+ DataLayerClusterer . prototype . init_ = function ( ) {
1158
+ this . setupStyles_ ( ) ;
1159
+
1160
+ if ( this . setProperty_ ) {
1161
+ this . _dataLayer . forEach ( function ( feature ) {
1162
+ feature . setProperty ( 'in_cluster' , true ) ;
1163
+ } ) ;
1164
+ } else {
1165
+ this . _dataLayer . setStyle ( DataLayerClusterer . HIDDEN_FEATURE ) ;
1166
+ }
1167
+ if ( this . map !== null ) {
1168
+ this . setMap ( this . map ) ;
1169
+ }
1170
+ }
1171
+
1137
1172
/**
1138
1173
* Sets up the styles object.
1139
1174
*
@@ -1144,34 +1179,6 @@ DataLayerClusterer.prototype.setupStyles_ = function() {
1144
1179
return ;
1145
1180
}
1146
1181
1147
- if ( ! this . baseSVG_ && this . recolorSVG_ && this . imageExtension_ == 'svg' ) {
1148
- var self = this ,
1149
- xhr = new XMLHttpRequest ( ) ;
1150
- xhr . open ( "GET" , / \. s v g $ / . test ( this . imagePath_ ) ? this . imagePath_ : this . imagePath_ + '1.' + this . imageExtension_ ) ;
1151
- // Following line is just to be on the safe side;
1152
- // not needed if your server delivers SVG with correct MIME type
1153
- xhr . overrideMimeType ( "image/svg+xml" ) ;
1154
- xhr . send ( "" ) ;
1155
-
1156
- xhr . onreadystatechange = function ( ) {
1157
- if ( this . readyState == 4 ) {
1158
- if ( this . status == 200 ) {
1159
- self . baseSVG_ = {
1160
- 'document' : xhr . responseXML . documentElement ,
1161
- 'colorElement' : xhr . responseXML . documentElement . querySelector ( self . recolorSVG_ )
1162
- } ;
1163
- if ( ! self . baseSVG_ . document || ! self . baseSVG_ . colorElement ) {
1164
- self . recolorSVG_ = false ;
1165
- }
1166
- } else {
1167
- self . recolorSVG_ = false ;
1168
- }
1169
- self . setupStyles_ ( ) ;
1170
- }
1171
- } ;
1172
- return ;
1173
- }
1174
-
1175
1182
var ssizes = this . sizes . length ;
1176
1183
for ( var i = 0 ; i !== ssizes ; ++ i ) {
1177
1184
var thisSize = this . sizes [ i ] ,
0 commit comments