@@ -849,64 +849,77 @@ if (typeof global.process === 'undefined')
849849 this . _handleGeospatialResult ( result ) ;
850850 }
851851 } ,
852-
853- // If the given result contains geospatial data, show it on the map
854- _handleGeospatialResult : function ( bindings ) {
852+ _processMapData : function ( ) {
855853 var self = this ;
856- for ( const variableName in bindings ) {
857- // Check if the value has a geospatial datatype
858- const value = bindings [ variableName ] ;
859- if ( value . endsWith ( '^^http://www.openlinksw.com/schemas/virtrdf#Geometry' ) ||
854+ const resultsToProcess = this . _mapResultsBuffer . splice ( 0 ) ;
855+ for ( const bindings of resultsToProcess ) {
856+ for ( const variableName in bindings ) {
857+ // Check if the value has a geospatial datatype
858+ const value = bindings [ variableName ] ;
859+ if ( value . endsWith ( '^^http://www.openlinksw.com/schemas/virtrdf#Geometry' ) ||
860860 value . endsWith ( '^^http://www.opengis.net/ont/geosparql#wktLiteral' ) ) {
861- // Look for a corresponding variable with the 'Label' suffix.
862- const variableNameLabel = `${ variableName } Label` ;
863- const valueLabel = bindings [ variableNameLabel ] ;
864-
865- // Interpret geometry value as WKT string
866- const geometry = / ^ " ( .* ) " \^ \^ [ ^ \^ ] * $ / . exec ( value ) [ 1 ] ;
867- const wkt = new Wkt . Wkt ( ) ;
868- wkt . read ( geometry ) ;
869-
870- // Construct geo feature for WKT string
871- const geoFeature = { type : 'Feature' , properties : { } , geometry : wkt . toJson ( ) } ;
872- if ( valueLabel )
873- geoFeature . properties . name = valueLabel . split ( '@' , 1 ) [ 0 ] . replace ( / [ ' " ] + / g, '' ) ;
874-
875- // Add feature to map
876- let newMapLayer = L . geoJSON ( geoFeature , {
877- onEachFeature : function ( feature ) {
878- // Determine marker position for different geometry types
879- let lon ;
880- let lat ;
881- if ( feature . geometry . type === 'Polygon' ) {
882- const centroid = turf . centroid ( feature ) ;
883- lon = centroid . geometry . coordinates [ 0 ] ;
884- lat = centroid . geometry . coordinates [ 1 ] ;
885- }
886- // Handle points
887- if ( feature . geometry . type === 'Point' ) {
888- lon = feature . geometry . coordinates [ 0 ] ;
889- lat = feature . geometry . coordinates [ 1 ] ;
890- }
891- if ( lon && lat ) {
892- let marker = L . circleMarker ( [ lat , lon ] ) ;
893- self . mapLayer . addLayer ( marker ) . addTo ( self . map ) ;
894- self . markerArray . push ( marker ) ;
895- if ( valueLabel )
896- marker . bindPopup ( feature . properties . name ) ;
897- }
898- } ,
899- } ) ;
900- self . mapLayer . addLayer ( newMapLayer ) . addTo ( self . map ) ;
861+ // Look for a corresponding variable with the 'Label' suffix.
862+ const variableNameLabel = `${ variableName } Label` ;
863+ const valueLabel = bindings [ variableNameLabel ] ;
864+
865+ // Interpret geometry value as WKT string
866+ const geometry = / ^ " ( .* ) " \^ \^ [ ^ \^ ] * $ / . exec ( value ) [ 1 ] ;
867+ const wkt = new Wkt . Wkt ( ) ;
868+ wkt . read ( geometry ) ;
869+
870+ // Construct geo feature for WKT string
871+ const geoFeature = { type : 'Feature' , properties : { } , geometry : wkt . toJson ( ) } ;
872+ if ( valueLabel )
873+ geoFeature . properties . name = valueLabel . split ( '@' , 1 ) [ 0 ] . replace ( / [ ' " ] + / g, '' ) ;
874+
875+ // Add feature to map
876+ let newMapLayer = L . geoJSON ( geoFeature , {
877+ onEachFeature : function ( feature ) {
878+ // Determine marker position for different geometry types
879+ let lon ;
880+ let lat ;
881+ if ( feature . geometry . type === 'Polygon' ) {
882+ const centroid = turf . centroid ( feature ) ;
883+ lon = centroid . geometry . coordinates [ 0 ] ;
884+ lat = centroid . geometry . coordinates [ 1 ] ;
885+ }
886+ // Handle points
887+ if ( feature . geometry . type === 'Point' ) {
888+ lon = feature . geometry . coordinates [ 0 ] ;
889+ lat = feature . geometry . coordinates [ 1 ] ;
890+ }
891+ if ( lon && lat ) {
892+ let marker = L . circleMarker ( [ lat , lon ] ) ;
893+ self . mapLayer . addLayer ( marker ) . addTo ( self . map ) ;
894+ self . markerArray . push ( marker ) ;
895+ if ( valueLabel )
896+ marker . bindPopup ( feature . properties . name ) ;
897+ }
898+ } ,
899+ } ) ;
900+ self . mapLayer . addLayer ( newMapLayer ) . addTo ( self . map ) ;
901901
902- // Possibly rescale map view
903- self . map . fitBounds ( L . featureGroup ( self . markerArray ) . getBounds ( ) ) ;
902+ // Possibly rescale map view
903+ self . map . fitBounds ( L . featureGroup ( self . markerArray ) . getBounds ( ) ) ;
904904
905- // Show map if it's not visible yet
906- if ( ! self . $mapWrapper . is ( ':visible' ) )
907- self . $mapWrapper . show ( ) ;
905+ // Show map if it's not visible yet
906+ if ( ! self . $mapWrapper . is ( ':visible' ) )
907+ self . $mapWrapper . show ( ) ;
908+ }
908909 }
909910 }
911+ this . _processingScheduled = false ;
912+ } ,
913+
914+ // If the given result contains geospatial data, show it on the map
915+ _handleGeospatialResult : function ( bindings ) {
916+ if ( ! this . _mapResultsBuffer ) this . _mapResultsBuffer = [ ] ;
917+ this . _mapResultsBuffer . push ( bindings ) ;
918+
919+ if ( ! this . _processingScheduled ) {
920+ this . _processingScheduled = true ;
921+ requestAnimationFrame ( this . _processMapData . bind ( this ) ) ;
922+ }
910923 } ,
911924
912925 // Finalizes the display after all results have been added
0 commit comments