popups and non-base layers not working when re-init'ing map in same div

classic Classic list List threaded Threaded
3 messages Options
crb
Reply | Threaded
Open this post in threaded view
|

popups and non-base layers not working when re-init'ing map in same div

crb
We have a .NET app using OL 2.9.1 and it has a "results" map that is invoked when the user clicks on a button in a results page. The map is loaded in a div that's inside a .NET control (the div is pretty much the only thing in the control). Whenever the user does a search in the app and gets results, if they invoke the results map then the app first does a callback to get all the locations in the result set and passes those (in JSON) to the results map.  The results map then has just three layers (a base streets layer, a base imagery layer, and a vector layer with the locations) and a select control for a popup on the vector layer.  It creates a vector layer from the locations JSON and zooms to the extent that encompasses those locations.

Everything works fine the first time the user invokes the results map, but for subsequent invokations only the streets base layer works:  the popup doesn't work, and the extent for the imagery base layer goes to a default extent (and not all tiles are rendered).

I've tried deleting the variable that contains the results map as follows:

if (typeof(myResultsMap) != "undefined") {
   delete myResultsMap;
}

myResultsMap = new ResultsMap(initSettings, "MapSearchResultsControl", mapLocs);

// where initSettings are JSON map setting results from one callback and mapLocs are location details from another callback, and MapSearchResultsControl is the div within the .NET control

When I step through the code I clearly see that the myResultsMap variable is undefined before instantiating a new ResultsMap class, but the behaviour is no different.  The init for the ResultsMap class looks like this:

ResultsMap = OpenLayers.Class(null,
{
    rm: null,
    map: null,
    mapProjection: null,
    displayProjection: null,
    initSettings: null,
    mapDiv: null,
    mapLocs: null,
    locsLayerName: null,
    locsLayer: null,

    initialize: function (initSettings, mapDiv, mapLocs) {
        rm = this; // needed to workaround fact that 'this' can change scope within the class because of callback handlers
        rm.mapDiv = mapDiv;
        rm.initSettings = initSettings;
        rm.mapLocs = mapLocs;
        . . .
        var mapOptions = . . .
        . . .
        rm.map = new OpenLayers.Map(rm.mapDiv, mapOptions);
    }
. . .
}

Am I doing something inherently wrong in re-initializing a map within the same div multiple times?
Reply | Threaded
Open this post in threaded view
|

Re: popups and non-base layers not working when re-init'ing map in same div

Andreas Hocevar-2
Hi,

On Oct 22, 2010, at 03:49 , crb wrote:

> We have a .NET app using OL 2.9.1 and it has a "results" map that is invoked
> when the user clicks on a button in a results page. The map is loaded in a
> div that's inside a .NET control (the div is pretty much the only thing in
> the control). Whenever the user does a search in the app and gets results,
> if they invoke the results map then the app first does a callback to get all
> the locations in the result set and passes those (in JSON) to the results
> map.  The results map then has just three layers (a base streets layer, a
> base imagery layer, and a vector layer with the locations) and a select
> control for a popup on the vector layer.  It creates a vector layer from the
> locations JSON and zooms to the extent that encompasses those locations.
>
> Everything works fine the first time the user invokes the results map, but
> for subsequent invokations only the streets base layer works:  the popup
> doesn't work, and the extent for the imagery base layer goes to a default
> extent (and not all tiles are rendered).
>
> I've tried deleting the variable that contains the results map as follows:
>
>
> if (typeof(myResultsMap) != "undefined") {

   myResultsMap.destroy();

>   delete myResultsMap;
> }
>
> myResultsMap = new ResultsMap(initSettings, "MapSearchResultsControl",
> mapLocs);

Does ResultsMap inherit from OpenLayers.Map? If not, then you have to make sure that the ResultsMap's destroy method also destroys the OpenLayers.Map instance.

Regards,
Andreas.


>
> // where initSettings are JSON map setting results from one callback and
> mapLocs are location details from another callback, and
> MapSearchResultsControl is the div within the .NET control
>
>
> When I step through the code I clearly see that the myResultsMap variable is
> undefined before instantiating a new ResultsMap class, but the behaviour is
> no different.  The init for the ResultsMap class looks like this:
>
>
> ResultsMap = OpenLayers.Class(null,
> {
>    rm: null,
>    map: null,
>    mapProjection: null,
>    displayProjection: null,
>    initSettings: null,
>    mapDiv: null,
>    mapLocs: null,
>    locsLayerName: null,
>    locsLayer: null,
>
>    initialize: function (initSettings, mapDiv, mapLocs) {
>        rm = this; // needed to workaround fact that 'this' can change scope
> within the class because of callback handlers
>        rm.mapDiv = mapDiv;
>        rm.initSettings = initSettings;
>        rm.mapLocs = mapLocs;
>        . . .
>        var mapOptions = . . .
>        . . .
>        rm.map = new OpenLayers.Map(rm.mapDiv, mapOptions);
>    }
> . . .
> }
>
>
> Am I doing something inherently wrong in re-initializing a map within the
> same div multiple times?
>
> --
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/popups-and-non-base-layers-not-working-when-re-init-ing-map-in-same-div-tp5661031p5661031.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
crb
Reply | Threaded
Open this post in threaded view
|

Re: popups and non-base layers not working when re-init'ing map in same div

crb
Cheers, thanks Andreas.

myResultsMap.map.destroy() did the trick.