[OpenLayers-Dev] Map Initialization (was [GeoExt] Map widgets)

Tim Coulter tcoulter at opengeo.org
Wed Jan 14 14:55:09 EST 2009


FYI:

http://trac.openlayers.org/ticket/1901

Tim

-- 
Tim Coulter
OpenGeo - http://www.opengeo.org
Expert service straight from the developers.

On Wed, 2009-01-14 at 12:38 -0500, Tim Coulter wrote:
> Thanks for the feedback, Eric. CC'ing to the OL dev list.
> 
> Back story for the OL developers: 
> 
> When working with Ext and OpenLayers, I realized that due to
> OpenLayer's
> Map class requiring a div on initialization, my code contained a
> circular dependency. The problem was that Ext's Viewport code needed
> things initialized before it laid out HTML elements for each
> component;
> on the other hand, OL needed HTML elements defined before it could
> create a map. Because they both needed each other, I was at an
> impasse.
> 
> To get around this, I edited OpenLayers to not require a div on
> initialization. At the same time, I added the named argument
> "renderTo"
> to get rid of the reliance on positional arguments if
> rendering-on-initialization was required.
> 
> http://trac.openlayers.org/changeset/8608
> 
> Examples of this code's use are here[1] and here[2]. Note that in the
> second case, I'm initializing a map with no parameters.
> 
> The implementation (as far as arguments are concerned) is backwards
> compatible. You can still use the positional argument if you'd like
> to,
> but preference is given to renderTo. Neither are required. 
> 
> I'd be very interested if this is helpful for others in the community.
> I'd also be happy to give more back story if needed.
> 
> On the GeoExt list (geoext at lists.opengoe.org), Eric Lemoine asked the
> question:
>  
> > With your new OpenLayers code, can one do:
> > 
> > 1 map = new OpenLayers.Map();
> > 2 map.addLayer(new OpenLayers.Layer.WMS());
> > 3 map.render("map-div")
> 
> That was the intention, yes. Aside from needing to call some form of
> setCenter/zoomToExtent/etc. after render(), the above should work.
> 
> He brought up a good bug:
> 
> > I'm concerned with addLayer failing if maxResolution is "auto" - the
> > map doesn't have a div at addLayer time, so resolutions can't be
> > calculated. Even if I'm correct, that may be ok, users should just
> be
> > warned.
> 
> Is the default value for maxResolution "auto"? If not, I haven't run
> into a case where this happens. Can you provide an example?
> 
> What does everyone think? I plan on opening a ticket today and
> submitting a patch to get this discussion going there.
> 
> Tim
> 
> [1]
> http://dev.openlayers.org/sandbox/tcoulter/teleporter/examples/teleportation.html
> [2]
> http://dev.openlayers.org/sandbox/tcoulter/teleporter/examples/late-render.html
> 
> On Wed, 2009-01-14 at 07:34 +0100, Eric Lemoine wrote:
> > On Tue, Jan 13, 2009 at 6:55 PM, Tim Coulter <tcoulter at opengeo.org>
> wrote:
> > > 2) It supports both passing an already-created map (as per my last
> > > email), as well as allowing a configuration to be passed as
> this.map. In
> > > the latter case, the map is created for the developer by the
> MapPanel.
> > 
> > I like the idea of having the map option either be a Map instance or
> a
> > Map config.
> > 
> > > 3) I've removed synonymous functions. I've also removed TimS's
> layer and
> > > control convenience functions/features; I think these could be put
> back
> > > in, though if OpenLayers allows the "layers" and "controls" named
> > > parameters (I know "controls" is there), then there may be no need
> for
> > > MapPanel to handle it.
> > 
> > Adding support to OpenLayers for a "layers" map option would be very
> > useful I think. Otherwise, if I'm correct with the above
> > "maxResolution set to auto" issue, we'd need the MapPanel to trigger
> > an event to know when layers can be safely added to the map.
> > 
> > In any way, I think we'd need our map panel to trigger events, at
> > least one to tell the world that the map instance is created. This
> > discussed with Andreas and Bart, they even started coding things
> > around that if I remember correctly.
> > 
> > > 4) I haven't yet gotten the changes to Map.js looked at or
> approved by
> > > the OpenLayers folks, so if it's something we'd like to use, we
> should
> > > start some conversation over there. (I know a lot of you guys are
> on
> > > this list. :) )
> > >
> > > Given that the circular dependencies in Map.js are removed, and
> the
> > > MapPanel accepts a map as well as a configuration, it more
> reflects my
> > > coding style while (I think) supporting everyone else's.
> > >
> > > Let me know what you guys think. I'm really interested in knowing
> if
> > > others find this useful.
> > 
> > Thanks Tim,
> > 
> > --
> > Eric
> > 
> > 
> > --
> > Archive:
> http://lists.opengeo.org/geoext/archive/2009/01/1231915041656
> > To unsubscribe send an email with subject "unsubscribe" to
> geoext at lists.opengeo.org.  Please contact
> geoext-manager at lists.opengeo.org for questions.
> 
> 
> 
> --
> Archive: http://lists.opengeo.org/geoext/archive/2009/01/1231954920273
> To unsubscribe send an email with subject "unsubscribe" to
> geoext at lists.opengeo.org.  Please contact
> geoext-manager at lists.opengeo.org for questions.




More information about the Dev mailing list