2020import android .graphics .BitmapFactory ;
2121import android .util .Log ;
2222
23+ import androidx .annotation .Nullable ;
2324import androidx .annotation .RawRes ;
2425
2526import com .google .android .gms .maps .GoogleMap ;
@@ -59,7 +60,7 @@ public class KmlLayer extends Layer {
5960 */
6061 public KmlLayer (GoogleMap map , int resourceId , Context context )
6162 throws XmlPullParserException , IOException {
62- this (map , context .getResources ().openRawResource (resourceId ), context , new MarkerManager (map ), new PolygonManager (map ), new PolylineManager (map ), new GroundOverlayManager (map ), null );
63+ this (map , context .getResources ().openRawResource (resourceId ), context , new MarkerManager (map ), new PolygonManager (map ), new PolylineManager (map ), new GroundOverlayManager (map ), null , null );
6364 }
6465
6566 /**
@@ -75,7 +76,7 @@ public KmlLayer(GoogleMap map, int resourceId, Context context)
7576 */
7677 public KmlLayer (GoogleMap map , InputStream stream , Context context )
7778 throws XmlPullParserException , IOException {
78- this (map , stream , context , new MarkerManager (map ), new PolygonManager (map ), new PolylineManager (map ), new GroundOverlayManager (map ), null );
79+ this (map , stream , context , new MarkerManager (map ), new PolygonManager (map ), new PolylineManager (map ), new GroundOverlayManager (map ), null , null );
7980 }
8081
8182 /**
@@ -106,7 +107,7 @@ public KmlLayer(GoogleMap map,
106107 GroundOverlayManager groundOverlayManager ,
107108 Renderer .ImagesCache cache )
108109 throws XmlPullParserException , IOException {
109- this (map , context .getResources ().openRawResource (resourceId ), context , markerManager , polygonManager , polylineManager , groundOverlayManager , cache );
110+ this (map , context .getResources ().openRawResource (resourceId ), context , markerManager , polygonManager , polylineManager , groundOverlayManager , cache , null );
110111 }
111112
112113 /**
@@ -137,10 +138,43 @@ public KmlLayer(GoogleMap map,
137138 GroundOverlayManager groundOverlayManager ,
138139 Renderer .ImagesCache cache )
139140 throws XmlPullParserException , IOException {
141+ this (map , stream , context , markerManager , polygonManager , polylineManager , groundOverlayManager , cache , null );
142+ }
143+
144+ /**
145+ * Creates a new KmlLayer object - addLayerToMap() must be called to trigger rendering onto a map.
146+ *
147+ * Constructor may be called on a background thread, as I/O and parsing may be long-running.
148+ *
149+ * Use this constructor with shared object managers in order to handle multiple layers with
150+ * their own event handlers on the map.
151+ *
152+ * @param map GoogleMap object
153+ * @param stream InputStream containing KML or KMZ file
154+ * @param context The Context
155+ * @param markerManager marker manager to create marker collection from
156+ * @param polygonManager polygon manager to create polygon collection from
157+ * @param polylineManager polyline manager to create polyline collection from
158+ * @param groundOverlayManager ground overlay manager to create ground overlay collection from
159+ * @param cache cache to be used for fetched images
160+ * @param urlSanitizer sanitizer to be used for external URLs
161+ * @throws XmlPullParserException if file cannot be parsed
162+ * @throws IOException if I/O error
163+ */
164+ public KmlLayer (GoogleMap map ,
165+ InputStream stream ,
166+ Context context ,
167+ MarkerManager markerManager ,
168+ PolygonManager polygonManager ,
169+ PolylineManager polylineManager ,
170+ GroundOverlayManager groundOverlayManager ,
171+ Renderer .ImagesCache cache ,
172+ @ Nullable KmlUrlSanitizer urlSanitizer )
173+ throws XmlPullParserException , IOException {
140174 if (stream == null ) {
141175 throw new IllegalArgumentException ("KML InputStream cannot be null" );
142176 }
143- KmlRenderer renderer = new KmlRenderer (map , context , markerManager , polygonManager , polylineManager , groundOverlayManager , cache );
177+ KmlRenderer renderer = new KmlRenderer (map , context , markerManager , polygonManager , polylineManager , groundOverlayManager , cache , urlSanitizer );
144178
145179 BufferedInputStream bis = new BufferedInputStream (stream );
146180 bis .mark (1024 );
0 commit comments