|
1 | 1 |
|
2 |
| -//import Store from '../Store'; |
3 |
| -import Mstyle from './Mstyle'; |
4 | 2 | import Msource from './Msource';
|
| 3 | +import Mstyle from './Mstyle'; |
| 4 | + |
5 | 5 | import NameFromURL from '../utility/NameFromURL';
|
| 6 | +import SourceReader from '../utility/SourceReader'; |
6 | 7 |
|
7 | 8 | export default {
|
8 | 9 | addFromSource:function(sourceUrl){
|
9 | 10 | return new Promise((resolve,reject)=>{
|
10 |
| - const rec = { |
11 |
| - name:NameFromURL.get(sourceUrl) |
12 |
| - }; |
13 |
| - Mstyle.add(rec).then((style)=>{ |
14 |
| - Mstyle.define(style); |
15 |
| - console.log('style defined:',style); |
16 |
| - // add source |
17 |
| - Msource.add({ |
18 |
| - url:sourceUrl, |
19 |
| - type:'vector' |
20 |
| - }).then((source)=>{ |
21 |
| - //console.log('added source:',source); |
22 |
| - const json = Msource.getJson(source.url); |
23 |
| - console.log('added source json:',json); |
24 |
| - const center = [ |
25 |
| - json.getIn(['center',0]), |
26 |
| - json.getIn(['center',1]) |
27 |
| - ]; |
28 |
| - if (json.has('center')) Mstyle.setIn(['center'],center); |
29 |
| - if (json.has('maxzoom') && json.has('minzoom')){ |
30 |
| - const zoom = json.getIn(['center',2]) || (json.get('maxzoom') - json.get('minzoom'))/2; |
31 |
| - Mstyle.setIn(['zoom'],zoom); |
32 |
| - } |
33 |
| - Mstyle.save(); |
34 |
| - return resolve(style); |
| 11 | + SourceReader.load(sourceUrl).then(()=>{ |
| 12 | + const rec = { |
| 13 | + name:NameFromURL.get(sourceUrl) |
| 14 | + }; |
| 15 | + Mstyle.add(rec).then((style)=>{ |
| 16 | + Mstyle.define(style); |
| 17 | + //console.log('style defined:',style); |
| 18 | + // add source |
| 19 | + Msource.add({ |
| 20 | + url:sourceUrl, |
| 21 | + type:'vector' |
| 22 | + }).then((source)=>{ |
| 23 | + //console.log('added source:',source); |
| 24 | + const json = Msource.getJson(source.url); |
| 25 | + console.log('added source json:',json); |
| 26 | + const center = [ |
| 27 | + json.getIn(['center',0]), |
| 28 | + json.getIn(['center',1]) |
| 29 | + ]; |
| 30 | + if (json.has('center')) Mstyle.setIn(['center'],center); |
| 31 | + if (json.has('maxzoom') && json.has('minzoom')){ |
| 32 | + const zoom = json.getIn(['center',2]) || (json.get('maxzoom') - json.get('minzoom'))/2; |
| 33 | + Mstyle.setIn(['zoom'],zoom); |
| 34 | + } |
| 35 | + Mstyle.save(); |
| 36 | + return resolve(style); |
| 37 | + }).catch((e)=>{ |
| 38 | + reject({message:'source not found'}); |
| 39 | + }); |
| 40 | + }).catch((e)=>{ |
| 41 | + reject(e); |
35 | 42 | });
|
36 | 43 | }).catch((e)=>{
|
37 |
| - reject(e); |
| 44 | + reject({message:'source not found'}); |
38 | 45 | });
|
39 | 46 | });
|
40 | 47 | },
|
|
0 commit comments