[OpenLayers-Users] geoExt and geojson file loading

Brad Spencer brad at numaps.com.au
Fri Oct 14 17:49:43 EDT 2011


 

List,

 

I am in desperate need of assistance on this problem. 

 

I have a number of GEOJSON files that I want to allow the user to select
from. They can only have one Geojson file active at any one time so I must
remove the last before loading the next. They can select from a list in a
menu object inside the Toolbar.

 

No problem listing the files in a menu list and the first file loads just
fine and the app sets itself to the BBox of the geojson group of vectors
which can be a mix of point, lines and polygons.

 

Subsequent files load Ok as well but my problem is when I select the second
or next geojson file I get an error on the execution of the "featuresadded"
event when doing the getDataExtent. Firebug tells me that GeoExt.js line 38
returns with "this.layer is null" for the next file load.

 

The actual zoomtoextent works as well but try as I may I cannot remove this
error.

 

I have listed my initializeMarkup function below which is called from the
menu in a handler for each file load. This is pretty much how the examples
do it but I'm not sure why this error is occurring on the next file load.

 

Maybe someone can see an obvious error in my code?

 

Thanks in anticipation.

 

Cheers, Brad....

 

function initializeMarkup(newSourceData)

{

                // remove any existing GEOJSON loaded layer

                if(markupLayerLoaded)

                {

                                markupLayerLoaded.destroy(); 

                                markupLayerLoaded=null;

                                saveStrategy.destroy();

                                saveStrategy=null;

                }

                

                // check if new data set being requested is 'none'

                if(newSourceData == 'none'){    return;                  }

                

                // setup a save strategy and symbology

                saveStrategy = new OpenLayers.Strategy.Save();

                saveStrategy.events.register('success', null, saveSuccess);

                saveStrategy.events.register('fail', null, saveFail);


                

                // setup symbology if not already setup

                if(!loadedMarkupSymbolizers){
loadedMarkupSymbology();       }

 

                // create the imported markup layer

                markupLayerLoaded = new
OpenLayers.Layer.Vector("LoadedLayer", 

                {

                                eventListeners: { "featuresadded":
dataLoaded  },

                                strategies: 

                                [

                                                new
OpenLayers.Strategy.Fixed(),

                                                saveStrategy

                                ],                                        

                                protocol: new OpenLayers.Protocol.HTTP

                                ({

                                                url: newSourceData,


                                                format: new
OpenLayers.Format.GeoJSON

                                                ({

 
//ignoreExtraDims: true,


 
internalProjection: P900913,

 
externalProjection: P4326

                                                })

                                }),

                                styleMap: loadedMarkupSymbolizers


                });

                map.addLayer(markupLayerLoaded);

}

 

function dataLoaded(event)       

{              this.map.zoomToExtent(event.object.getDataExtent()); }

 

function saveSuccess(event) 

{              alert('Changes saved');}

function saveFail(event)    

{              alert('Error! Changes not saved');}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111015/08083c2d/attachment-0001.html


More information about the Users mailing list