@@ -9,8 +9,6 @@ import {createRequire} from 'module';
99const require = createRequire ( import . meta. url ) ;
1010
1111export default function localizeURLs ( style , port ) {
12- localizeStyleURLs ( style , port ) ;
13-
1412 if ( style . imports ) {
1513 for ( const importSpec of style . imports ) {
1614 localizeURLs ( importSpec . data , port ) ;
@@ -19,9 +17,7 @@ export default function localizeURLs(style, port) {
1917
2018 if ( style . metadata && style . metadata . test && style . metadata . test . operations ) {
2119 style . metadata . test . operations . forEach ( ( op ) => {
22- if ( op [ 0 ] === 'addSource' ) {
23- localizeSourceURLs ( op [ 2 ] , port ) ;
24- } else if ( op [ 0 ] === 'setStyle' ) {
20+ if ( op [ 0 ] === 'setStyle' ) {
2521 if ( typeof op [ 1 ] === 'object' ) {
2622 localizeURLs ( op [ 1 ] , port ) ;
2723 return ;
@@ -48,76 +44,9 @@ export default function localizeURLs(style, port) {
4844 return ;
4945 }
5046
51- localizeStyleURLs ( styleJSON , port ) ;
52-
5347 op [ 1 ] = styleJSON ;
5448 op [ 2 ] = { diff : false } ;
5549 }
5650 } ) ;
5751 }
58- }
59-
60- function localizeURL ( url , port ) {
61- return url . replace ( / ^ l o c a l : \/ \/ / , `http://localhost:${ port } /` ) ;
62- }
63-
64- function localizeMapboxSpriteURL ( url , port ) {
65- return url . replace ( / ^ m a p b o x : \/ \/ / , `http://localhost:${ port } /` ) ;
66- }
67-
68- function localizeMapboxFontsURL ( url , port ) {
69- return url . replace ( / ^ m a p b o x : \/ \/ f o n t s / , `http://localhost:${ port } /glyphs` ) ;
70- }
71-
72- function localizeMapboxTilesURL ( url , port ) {
73- return url . replace ( / ^ m a p b o x : \/ \/ / , `http://localhost:${ port } /tiles/` ) ;
74- }
75-
76- function localizeMapboxTilesetURL ( url , port ) {
77- return url . replace ( / ^ m a p b o x : \/ \/ / , `http://localhost:${ port } /tilesets/` ) ;
78- }
79-
80- export function localizeSourceURLs ( source , port ) {
81- for ( const tile in source . tiles ) {
82- source . tiles [ tile ] = localizeMapboxTilesURL ( source . tiles [ tile ] , port ) ;
83- source . tiles [ tile ] = localizeURL ( source . tiles [ tile ] , port ) ;
84- }
85-
86- if ( source . urls ) {
87- source . urls = source . urls . map ( ( url ) => localizeMapboxTilesetURL ( url , port ) ) ;
88- source . urls = source . urls . map ( ( url ) => localizeURL ( url , port ) ) ;
89- }
90-
91- if ( source . url ) {
92- source . url = localizeMapboxTilesetURL ( source . url , port ) ;
93- source . url = localizeURL ( source . url , port ) ;
94- }
95-
96- if ( source . data && typeof source . data == 'string' ) {
97- source . data = localizeURL ( source . data , port ) ;
98- }
99-
100- for ( const model in source . models ) {
101- source . models [ model ] . uri = localizeURL ( source . models [ model ] . uri , port ) ;
102- }
103- }
104-
105- function localizeStyleURLs ( style , port ) {
106- for ( const source in style . sources ) {
107- localizeSourceURLs ( style . sources [ source ] , port ) ;
108- }
109- if ( style . models ) {
110- for ( const modelId in style . models ) {
111- style . models [ modelId ] = localizeURL ( style . models [ modelId ] , port ) ;
112- }
113- }
114- if ( style . sprite ) {
115- style . sprite = localizeMapboxSpriteURL ( style . sprite , port ) ;
116- style . sprite = localizeURL ( style . sprite , port ) ;
117- }
118-
119- if ( style . glyphs ) {
120- style . glyphs = localizeMapboxFontsURL ( style . glyphs , port ) ;
121- style . glyphs = localizeURL ( style . glyphs , port ) ;
122- }
123- }
52+ }
0 commit comments