@@ -25,6 +25,7 @@ define([
25
25
'../Core/loadXML' ,
26
26
'../Core/Math' ,
27
27
'../Core/NearFarScalar' ,
28
+ '../Core/objectToQuery' ,
28
29
'../Core/PinBuilder' ,
29
30
'../Core/PolygonHierarchy' ,
30
31
'../Core/Rectangle' ,
@@ -84,6 +85,7 @@ define([
84
85
loadXML ,
85
86
CesiumMath ,
86
87
NearFarScalar ,
88
+ objectToQuery ,
87
89
PinBuilder ,
88
90
PolygonHierarchy ,
89
91
Rectangle ,
@@ -272,22 +274,25 @@ define([
272
274
}
273
275
}
274
276
275
- function applyBasePath ( div , elementType , attributeName , proxy , sourceUri ) {
277
+ function applyBasePath ( div , elementType , attributeName , proxy , sourceUri , query ) {
276
278
var elements = div . querySelectorAll ( elementType ) ;
277
279
for ( var i = 0 ; i < elements . length ; i ++ ) {
278
280
var element = elements [ i ] ;
279
281
var value = element . getAttribute ( attributeName ) ;
280
- var uri = resolveHref ( value , proxy , sourceUri ) ;
282
+ var uri = resolveHref ( value , proxy , sourceUri , query ) ;
281
283
element . setAttribute ( attributeName , uri ) ;
282
284
}
283
285
}
284
286
285
- function proxyUrl ( url , proxy ) {
287
+ function proxyUrl ( url , proxy , query ) {
286
288
if ( defined ( proxy ) ) {
287
289
if ( new Uri ( url ) . isAbsolute ( ) ) {
288
290
url = proxy . getURL ( url ) ;
289
291
}
290
292
}
293
+ if ( defined ( query ) ) {
294
+ url = joinUrls ( url , '?' + query , false ) ;
295
+ }
291
296
return url ;
292
297
}
293
298
@@ -467,7 +472,7 @@ define([
467
472
return undefined ;
468
473
}
469
474
470
- function resolveHref ( href , proxy , sourceUri , uriResolver ) {
475
+ function resolveHref ( href , proxy , sourceUri , uriResolver , query ) {
471
476
if ( ! defined ( href ) ) {
472
477
return undefined ;
473
478
}
@@ -487,9 +492,11 @@ define([
487
492
}
488
493
}
489
494
}
490
- if ( ! hrefResolved && defined ( sourceUri ) ) {
491
- href = getAbsoluteUri ( href , getAbsoluteUri ( sourceUri ) ) ;
492
- href = proxyUrl ( href , proxy ) ;
495
+ if ( ! hrefResolved ) {
496
+ if ( defined ( sourceUri ) ) {
497
+ href = getAbsoluteUri ( href , getAbsoluteUri ( sourceUri ) ) ;
498
+ }
499
+ href = proxyUrl ( href , proxy , query ) ;
493
500
}
494
501
return href ;
495
502
}
@@ -630,7 +637,7 @@ define([
630
637
return label ;
631
638
}
632
639
633
- function getIconHref ( iconNode , dataSource , sourceUri , uriResolver , canRefresh ) {
640
+ function getIconHref ( iconNode , dataSource , sourceUri , uriResolver , canRefresh , query ) {
634
641
var href = queryStringValue ( iconNode , 'href' , namespaces . kml ) ;
635
642
if ( ! defined ( href ) || ( href . length === 0 ) ) {
636
643
return undefined ;
@@ -649,7 +656,7 @@ define([
649
656
href = 'https://maps.google.com/mapfiles/kml/pal' + palette + '/icon' + iconNum + '.png' ;
650
657
}
651
658
652
- href = resolveHref ( href , dataSource . _proxy , sourceUri , uriResolver ) ;
659
+ href = resolveHref ( href , dataSource . _proxy , sourceUri , uriResolver , query ) ;
653
660
654
661
if ( canRefresh ) {
655
662
var refreshMode = queryStringValue ( iconNode , 'refreshMode' , namespaces . kml ) ;
@@ -673,13 +680,13 @@ define([
673
680
return href ;
674
681
}
675
682
676
- function processBillboardIcon ( dataSource , node , targetEntity , sourceUri , uriResolver ) {
683
+ function processBillboardIcon ( dataSource , node , targetEntity , sourceUri , uriResolver , query ) {
677
684
var scale = queryNumericValue ( node , 'scale' , namespaces . kml ) ;
678
685
var heading = queryNumericValue ( node , 'heading' , namespaces . kml ) ;
679
686
var color = queryColorValue ( node , 'color' , namespaces . kml ) ;
680
687
681
688
var iconNode = queryFirstNode ( node , 'Icon' , namespaces . kml ) ;
682
- var icon = getIconHref ( iconNode , dataSource , sourceUri , uriResolver , false ) ;
689
+ var icon = getIconHref ( iconNode , dataSource , sourceUri , uriResolver , false , query ) ;
683
690
var x = queryNumericValue ( iconNode , 'x' , namespaces . gx ) ;
684
691
var y = queryNumericValue ( iconNode , 'y' , namespaces . gx ) ;
685
692
var w = queryNumericValue ( iconNode , 'w' , namespaces . gx ) ;
@@ -748,11 +755,11 @@ define([
748
755
}
749
756
}
750
757
751
- function applyStyle ( dataSource , styleNode , targetEntity , sourceUri , uriResolver ) {
758
+ function applyStyle ( dataSource , styleNode , targetEntity , sourceUri , uriResolver , query ) {
752
759
for ( var i = 0 , len = styleNode . childNodes . length ; i < len ; i ++ ) {
753
760
var node = styleNode . childNodes . item ( i ) ;
754
761
if ( node . localName === 'IconStyle' ) {
755
- processBillboardIcon ( dataSource , node , targetEntity , sourceUri , uriResolver ) ;
762
+ processBillboardIcon ( dataSource , node , targetEntity , sourceUri , uriResolver , query ) ;
756
763
} else if ( node . localName === 'LabelStyle' ) {
757
764
var label = targetEntity . label ;
758
765
if ( ! defined ( label ) ) {
@@ -814,7 +821,7 @@ define([
814
821
}
815
822
816
823
//Processes and merges any inline styles for the provided node into the provided entity.
817
- function computeFinalStyle ( entity , dataSource , placeMark , styleCollection , sourceUri , uriResolver ) {
824
+ function computeFinalStyle ( entity , dataSource , placeMark , styleCollection , sourceUri , uriResolver , query ) {
818
825
var result = new Entity ( ) ;
819
826
var styleEntity ;
820
827
@@ -832,7 +839,7 @@ define([
832
839
if ( styleIndex !== - 1 ) {
833
840
var inlineStyleNode = childNodes [ styleIndex ] ;
834
841
if ( inlineStyleNode . localName === 'Style' ) {
835
- applyStyle ( dataSource , inlineStyleNode , result , sourceUri , uriResolver ) ;
842
+ applyStyle ( dataSource , inlineStyleNode , result , sourceUri , uriResolver , query ) ;
836
843
} else { // StyleMap
837
844
var pairs = queryChildNodes ( inlineStyleNode , 'Pair' , namespaces . kml ) ;
838
845
for ( var p = 0 ; p < pairs . length ; p ++ ) {
@@ -850,7 +857,7 @@ define([
850
857
}
851
858
} else {
852
859
var node = queryFirstNode ( pair , 'Style' , namespaces . kml ) ;
853
- applyStyle ( dataSource , node , result , sourceUri , uriResolver ) ;
860
+ applyStyle ( dataSource , node , result , sourceUri , uriResolver , query ) ;
854
861
}
855
862
} else {
856
863
console . log ( 'KML - Unsupported StyleMap key: ' + key ) ;
@@ -885,8 +892,8 @@ define([
885
892
}
886
893
887
894
//Asynchronously processes an external style file.
888
- function processExternalStyles ( dataSource , uri , styleCollection ) {
889
- return loadXML ( proxyUrl ( uri , dataSource . _proxy ) ) . then ( function ( styleKml ) {
895
+ function processExternalStyles ( dataSource , uri , styleCollection , query ) {
896
+ return loadXML ( proxyUrl ( uri , dataSource . _proxy , query ) ) . then ( function ( styleKml ) {
890
897
return processStyles ( dataSource , styleKml , styleCollection , uri , true ) ;
891
898
} ) ;
892
899
}
@@ -895,7 +902,7 @@ define([
895
902
//their id into the provided styleCollection.
896
903
//Returns an array of promises that will resolve when
897
904
//each style is loaded.
898
- function processStyles ( dataSource , kml , styleCollection , sourceUri , isExternal , uriResolver ) {
905
+ function processStyles ( dataSource , kml , styleCollection , sourceUri , isExternal , uriResolver , query ) {
899
906
var i ;
900
907
var id ;
901
908
var styleEntity ;
@@ -917,7 +924,7 @@ define([
917
924
id : id
918
925
} ) ;
919
926
styleCollection . add ( styleEntity ) ;
920
- applyStyle ( dataSource , node , styleEntity , sourceUri , uriResolver ) ;
927
+ applyStyle ( dataSource , node , styleEntity , sourceUri , uriResolver , query ) ;
921
928
}
922
929
}
923
930
}
@@ -958,7 +965,7 @@ define([
958
965
}
959
966
} else {
960
967
node = queryFirstNode ( pair , 'Style' , namespaces . kml ) ;
961
- applyStyle ( dataSource , node , styleEntity , sourceUri , uriResolver ) ;
968
+ applyStyle ( dataSource , node , styleEntity , sourceUri , uriResolver , query ) ;
962
969
}
963
970
}
964
971
} else {
@@ -987,7 +994,7 @@ define([
987
994
if ( defined ( sourceUri ) ) {
988
995
uri = getAbsoluteUri ( uri , getAbsoluteUri ( sourceUri ) ) ;
989
996
}
990
- promises . push ( processExternalStyles ( dataSource , uri , styleCollection , sourceUri ) ) ;
997
+ promises . push ( processExternalStyles ( dataSource , uri , styleCollection , query ) ) ;
991
998
}
992
999
}
993
1000
}
@@ -1547,10 +1554,10 @@ define([
1547
1554
entity . description = tmp ;
1548
1555
}
1549
1556
1550
- function processFeature ( dataSource , parent , featureNode , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1557
+ function processFeature ( dataSource , parent , featureNode , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1551
1558
var entity = createEntity ( featureNode , entityCollection , context ) ;
1552
1559
var kmlData = entity . kml ;
1553
- var styleEntity = computeFinalStyle ( entity , dataSource , featureNode , styleCollection , sourceUri , uriResolver ) ;
1560
+ var styleEntity = computeFinalStyle ( entity , dataSource , featureNode , styleCollection , sourceUri , uriResolver , query ) ;
1554
1561
1555
1562
var name = queryStringValue ( featureNode , 'name' , namespaces . kml ) ;
1556
1563
entity . name = name ;
@@ -1625,7 +1632,7 @@ define([
1625
1632
Model : processUnsupportedGeometry
1626
1633
} ;
1627
1634
1628
- function processDocument ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1635
+ function processDocument ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1629
1636
var featureTypeNames = Object . keys ( featureTypes ) ;
1630
1637
var featureTypeNamesLength = featureTypeNames . length ;
1631
1638
@@ -1639,19 +1646,19 @@ define([
1639
1646
var child = childNodes [ q ] ;
1640
1647
if ( child . localName === featureName &&
1641
1648
( ( namespaces . kml . indexOf ( child . namespaceURI ) !== - 1 ) || ( namespaces . gx . indexOf ( child . namespaceURI ) !== - 1 ) ) ) {
1642
- processFeatureNode ( dataSource , parent , child , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1649
+ processFeatureNode ( dataSource , parent , child , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1643
1650
}
1644
1651
}
1645
1652
}
1646
1653
}
1647
1654
1648
- function processFolder ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1649
- var r = processFeature ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1650
- processDocument ( dataSource , r . entity , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1655
+ function processFolder ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1656
+ var r = processFeature ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1657
+ processDocument ( dataSource , r . entity , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1651
1658
}
1652
1659
1653
- function processPlacemark ( dataSource , parent , placemark , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1654
- var r = processFeature ( dataSource , parent , placemark , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1660
+ function processPlacemark ( dataSource , parent , placemark , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1661
+ var r = processFeature ( dataSource , parent , placemark , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1655
1662
var entity = r . entity ;
1656
1663
var styleEntity = r . styleEntity ;
1657
1664
@@ -1674,8 +1681,8 @@ define([
1674
1681
}
1675
1682
}
1676
1683
1677
- function processGroundOverlay ( dataSource , parent , groundOverlay , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1678
- var r = processFeature ( dataSource , parent , groundOverlay , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1684
+ function processGroundOverlay ( dataSource , parent , groundOverlay , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1685
+ var r = processFeature ( dataSource , parent , groundOverlay , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1679
1686
var entity = r . entity ;
1680
1687
1681
1688
var geometry ;
@@ -1720,7 +1727,7 @@ define([
1720
1727
}
1721
1728
1722
1729
var iconNode = queryFirstNode ( groundOverlay , 'Icon' , namespaces . kml ) ;
1723
- var href = getIconHref ( iconNode , dataSource , sourceUri , uriResolver , true ) ;
1730
+ var href = getIconHref ( iconNode , dataSource , sourceUri , uriResolver , true , query ) ;
1724
1731
if ( defined ( href ) ) {
1725
1732
if ( isLatLonQuad ) {
1726
1733
console . log ( 'KML - gx:LatLonQuad Icon does not support texture projection.' ) ;
@@ -1932,8 +1939,8 @@ define([
1932
1939
return queryString ;
1933
1940
}
1934
1941
1935
- function processNetworkLink ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
1936
- var r = processFeature ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
1942
+ function processNetworkLink ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
1943
+ var r = processFeature ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
1937
1944
var networkEntity = r . entity ;
1938
1945
1939
1946
var link = queryFirstNode ( node , 'Link' , namespaces . kml ) ;
@@ -1945,7 +1952,7 @@ define([
1945
1952
var href = queryStringValue ( link , 'href' , namespaces . kml ) ;
1946
1953
if ( defined ( href ) ) {
1947
1954
var newSourceUri = href ;
1948
- href = resolveHref ( href , undefined , sourceUri , uriResolver ) ;
1955
+ href = resolveHref ( href , undefined , sourceUri , uriResolver , query ) ;
1949
1956
var linkUrl ;
1950
1957
1951
1958
// We need to pass in the original path if resolveHref returns a data uri because the network link
@@ -2079,16 +2086,16 @@ define([
2079
2086
Tour : processUnsupportedFeature
2080
2087
} ;
2081
2088
2082
- function processFeatureNode ( dataSource , node , parent , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) {
2089
+ function processFeatureNode ( dataSource , node , parent , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) {
2083
2090
var featureProcessor = featureTypes [ node . localName ] ;
2084
2091
if ( defined ( featureProcessor ) ) {
2085
- featureProcessor ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
2092
+ featureProcessor ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
2086
2093
} else {
2087
2094
processUnsupportedFeature ( dataSource , parent , node , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
2088
2095
}
2089
2096
}
2090
2097
2091
- function loadKml ( dataSource , entityCollection , kml , sourceUri , uriResolver , context ) {
2098
+ function loadKml ( dataSource , entityCollection , kml , sourceUri , uriResolver , context , query ) {
2092
2099
entityCollection . removeAll ( ) ;
2093
2100
2094
2101
var promises = [ ] ;
@@ -2105,7 +2112,7 @@ define([
2105
2112
}
2106
2113
2107
2114
var styleCollection = new EntityCollection ( dataSource ) ;
2108
- return when . all ( processStyles ( dataSource , kml , styleCollection , sourceUri , false , uriResolver , context ) ) . then ( function ( ) {
2115
+ return when . all ( processStyles ( dataSource , kml , styleCollection , sourceUri , false , uriResolver , query ) ) . then ( function ( ) {
2109
2116
var element = kml . documentElement ;
2110
2117
if ( element . localName === 'kml' ) {
2111
2118
var childNodes = element . childNodes ;
@@ -2118,7 +2125,7 @@ define([
2118
2125
}
2119
2126
}
2120
2127
entityCollection . suspendEvents ( ) ;
2121
- processFeatureNode ( dataSource , element , undefined , entityCollection , styleCollection , sourceUri , uriResolver , promises , context ) ;
2128
+ processFeatureNode ( dataSource , element , undefined , entityCollection , styleCollection , sourceUri , uriResolver , promises , context , query ) ;
2122
2129
entityCollection . resumeEvents ( ) ;
2123
2130
2124
2131
return when . all ( promises ) . then ( function ( ) {
@@ -2187,10 +2194,11 @@ define([
2187
2194
var sourceUri = options . sourceUri ;
2188
2195
var uriResolver = options . uriResolver ;
2189
2196
var context = options . context ;
2197
+ var query = defined ( options . query ) ? objectToQuery ( options . query ) : undefined ;
2190
2198
2191
2199
var promise = data ;
2192
2200
if ( typeof data === 'string' ) {
2193
- promise = loadBlob ( proxyUrl ( data , dataSource . _proxy ) ) ;
2201
+ promise = loadBlob ( proxyUrl ( data , dataSource . _proxy , query ) ) ;
2194
2202
sourceUri = defaultValue ( sourceUri , data ) ;
2195
2203
}
2196
2204
@@ -2228,11 +2236,11 @@ define([
2228
2236
//Return the error
2229
2237
throw new RuntimeError ( msg ) ;
2230
2238
}
2231
- return loadKml ( dataSource , entityCollection , kml , sourceUri , uriResolver , context ) ;
2239
+ return loadKml ( dataSource , entityCollection , kml , sourceUri , uriResolver , context , query ) ;
2232
2240
} ) ;
2233
2241
} ) ;
2234
2242
} else {
2235
- return loadKml ( dataSource , entityCollection , dataToLoad , sourceUri , uriResolver , context ) ;
2243
+ return loadKml ( dataSource , entityCollection , dataToLoad , sourceUri , uriResolver , context , query ) ;
2236
2244
}
2237
2245
} )
2238
2246
. otherwise ( function ( error ) {
@@ -2327,6 +2335,7 @@ define([
2327
2335
* @param {DefaultProxy } [options.proxy] A proxy to be used for loading external data.
2328
2336
* @param {String } [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
2329
2337
* @param {Boolean } [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline.
2338
+ * @param {Object } [options.query] Key-value pairs which are appended to all URIs in the CZML.
2330
2339
*
2331
2340
* @returns {Promise.<KmlDataSource> } A promise that will resolve to a new KmlDataSource instance once the KML is loaded.
2332
2341
*/
@@ -2473,6 +2482,7 @@ define([
2473
2482
* @param {Number } [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
2474
2483
* @returns {Promise.<KmlDataSource> } A promise that will resolve to this instances once the KML is loaded.
2475
2484
* @param {Boolean } [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline.
2485
+ * @param {Object } [options.query] Key-value pairs which are appended to all URIs in the CZML.
2476
2486
*/
2477
2487
KmlDataSource . prototype . load = function ( data , options ) {
2478
2488
//>>includeStart('debug', pragmas.debug);
0 commit comments