• collective.geo discussion

Improved Mapwidget Loading

from Denis Krienbühl on Oct 23, 2012 09:46 AM
Hi everyone,

I'm working on a tabbed form where the map widget is hidden on load.
In the process I found a bug in collective.geo.mapwidget which
prevents the mapwidget from being loaded, if it is not visible at page
load. A comment in collectivegeo.js promises to fix this problem, but
that code is never called because OpenLayers 2.12 raises an exception
when it tries to get the size of the hidden div.


I had a look at the map loading code on collectivegeo.js and rewrote
it slightly, fixing my bug and making it a bit easier to work with
loaded maps:

You might want to have a look at the following commit to make sense of
my explanation below:

https://github.com/seantis/collective.geo.mapwidget/commit/47056fc47e04e565f0304822fcac506dbccca81e


With my rewrite the map is now loaded in a separate function
(load_map) which can be called at any time (before it was an anonymous
event function). This function is called for each map widget found
when the page is loaded.

load_map will load the map unless the map is found to be inside a
hidden formpanel. Loading the map will be delayed in this case until
the formpanel is made visible. Before, the click handler would do some
manual map refreshing, now the map is simply loaded later.

Once the map is loaded a map-load event is triggered on the window and
an instance of the map is passed. This event as well as the map
instance is consumed by all widgets and functions dealing with the
map, that would before consume the load event of the window. It is no
longer necessary to look up the map instance, it is always passed.

This change means that all existing javascript code attaching itself
to $(window).bind('load', ) must be rewritten to use 'map-load'
instead. The following commits cover all the instances of code where
this is the case:

https://github.com/seantis/collective.geo.contentlocations/commit/6118c724d81969ccb6eab2f0b3c2cdd81682b9bf
https://github.com/seantis/collective.z3cform.mapwidget/commit/b553e864c65fb994fdadaf1a9ee47b7c1643ce7c
https://github.com/seantis/collective.geo.kml/commit/b8f2face5e28797a9450cc496f291dd2ef41cd80

Now, I have the following questions:

What do you think about this change?
Does anyone know if I missed anything?
What tests can I run or conduct to ensure that all the existing
features still work?

I tested my changes in my local Plone 4.2 environment with all the
latest commits of collective.geo modules. I'm however not sure if
that's enough. If someone could point me to test that I could conduct
or if anyone is willing to try out my changes I would appreciate it.

Regards,

Denis Krienbühl
Return to date view: threaded or flat