@@ -30,28 +30,22 @@ const leafletMap = require('./leafletMap.js');
3030 console . log ( `leaflet.map:data:mimeType: ${ output . mimeType } ` ) ;
3131 const outputLoader : OutputLoader = new OutputLoader ( output . value , output . mimeType ) ;
3232 let data : any = outputLoader . getData ( ) ;
33- if ( data . features ) { // has geometry features collection
33+ if ( data . features && data . features . length > 0 ) { // has geometry features to display
3434 // create leaflet map and add it to notebook cell output display
3535 const mapContainer : HTMLDivElement = document . createElement ( 'div' ) ;
3636 mapContainer . className = 'map-container' ;
3737 output . container . appendChild ( mapContainer ) ;
38- const map = leafletMap . createMap ( data , mapContainer ) ;
39- }
40- else {
41- // create text output display nodes
42- const pre = document . createElement ( 'pre' ) ;
43- pre . className = 'text-output' ;
44- const code = document . createElement ( 'code' ) ;
45- if ( typeof data !== 'string' ) {
46- // stringify json data
47- code . textContent = JSON . stringify ( data , null , 2 ) ;
38+ try {
39+ // try to load geo data into leaflet map
40+ const map = leafletMap . createMap ( data , mapContainer ) ;
4841 }
49- else {
50- // show cell output text
51- code . textContent = output . value . text ( ) ;
42+ catch ( error : any ) {
43+ console . error ( 'leaflet.map:data: GeoJSON parse error:\n' , error ) ;
44+ showTextData ( data , output ) ;
5245 }
53- pre . appendChild ( code ) ;
54- output . container . appendChild ( pre ) ;
46+ }
47+ else {
48+ showTextData ( data , output ) ;
5549 }
5650}
5751
@@ -60,3 +54,23 @@ if (module.hot) {
6054 // cleanup or stash any state on renderer dispose
6155 } ) ;
6256}
57+
58+ /**
59+ * Displays text data.
60+ */
61+ function showTextData ( data : any , output : IRenderInfo ) : void {
62+ // create text output display nodes
63+ const pre = document . createElement ( 'pre' ) ;
64+ pre . className = 'text-output' ;
65+ const code = document . createElement ( 'code' ) ;
66+ if ( typeof data !== 'string' ) {
67+ // stringify json data
68+ code . textContent = JSON . stringify ( data , null , 2 ) ;
69+ }
70+ else {
71+ // show cell output text
72+ code . textContent = output . value . text ( ) ;
73+ }
74+ pre . appendChild ( code ) ;
75+ output . container . appendChild ( pre ) ;
76+ }
0 commit comments