olwidget popups for InfoMap GML layers

35 views
Skip to first unread message

omat

unread,
Nov 14, 2009, 10:40:25 AM11/14/09
to geodjango
Hi,

I have an olwidget.InfoMap with one initial layer, and I am adding new
layers of sets of points with:

...
var layer = new OpenLayers.Layer.GML(id, '/path/to/kml/', {...});
map.addLayer(layer);
selectControl = new OpenLayers.Control.SelectFeature(layer,
{onSelect: onFeatureSelect, onFeatureUnselect});
map.addControl(selectControl);
selectControl.activate();
...

And it is working fine.

In onFeatureSelect() I can assign OpenLayers.Popup instances and they
also work fine. But I want to use the auto-sized, good-looking, css
customizable popups provided by olwidget. I went through the codes
many times trying to figure-out how. The closest I can get is setting
the select / unselect callbacks as:

function onFeatureSelect(feature) {
selectedFeature = feature;
popup = new olwidget.Popup("thepopup",
feature.geometry.getBounds().getCenterLonLat(),
null,
feature.attributes.description,
null,
true,
function (feature) {map.removePopup(feature.popup)},
'auto',
'/' // pagination separator);
feature.popup = popup;
map.addPopup(popup, true);
}

function onFeatureUnselect(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}


This creates the popups as desired, but clicking on a feature creates
continuously increasing number of:

"TypeError: Result of expression 'this.popup' [undefined] is not an
object."

errors, referring to olwidget.js line 604 in the debug console, and
the popups cannot be closed by clicking on the cross.


Due to lack of documentation and examples, and my limited
understanding of javascript, I am stuck. Any help would be greatly
appreciated.


Thanks,
omat

Charlie DeTar

unread,
Nov 16, 2009, 9:40:18 PM11/16/09
to geod...@googlegroups.com
Hi Omat,

I believe the problem is in the close box callback you defined. You said:

> function (feature) {map.removePopup(feature.popup)},

However, the close box callback is called with an 'event' as its
argument, not the feature, so the event lacks a "popup" attribute. You
ought to be able to get the desired effect by instead using this closure:

function() {map.removePopup(feature.popup)},

In order to get the nice CSS stylability, olwidget.Popup doesn't use the
built-in close box functionality, but just defines a generic close box
that responds to an on-click event that has no knowledge of the feature.
Fortunately, javascript lets us enclose the feature in a closure.

-charlie
> --
>
> You received this message because you are subscribed to the Google Groups "geodjango" group.
> To post to this group, send email to geod...@googlegroups.com.
> To unsubscribe from this group, send email to geodjango+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/geodjango?hl=.
>
>

omat

unread,
Nov 17, 2009, 4:05:13 AM11/17/09
to geodjango
Hi Charlie,

Thanks for the reply, it mostly solved the problem. But only for the
first time a feature is clicked:

"TypeError: Result of expression 'this.popup' [undefined] is not an
object."

errors start appearing in the javascript console and the popup
flickers. When the popup is closed the error messages stop and does
not appear. Next time a feature is clicked everything is all fine.


Thanks a lot.


On Nov 17, 4:40 am, Charlie DeTar <cha...@gmail.com> wrote:
> HiOmat,

Charlie DeTar

unread,
Nov 17, 2009, 7:06:51 AM11/17/09
to geod...@googlegroups.com
Could you send me a complete failing example?

thanks,
Charlie

omat

unread,
Nov 17, 2009, 11:04:17 AM11/17/09
to geodjango
Hi,

I put the views and the template on dpaste.

views.py:
http://dpaste.com/hold/121584/

template:
http://dpaste.com/hold/121587/

As you will see, the index() in the views initially loads a feature (1
polygon). Then a javascript call fetches the settlements kml, calling
the kml() in the views, when the map is loaded.

Btw, is it possible to disable the popup for the initial layer? Or at
least change its name, so that it won't popup as 'data'? The 'name'
attribute given during map initialization does not seem to have an
effect.


Thank you...

-- omat

Charlie DeTar

unread,
Nov 17, 2009, 10:02:51 PM11/17/09
to geod...@googlegroups.com
Thanks Omat,

>>> "TypeError: Result of expression 'this.popup' [undefined] is not an
>>> object."

I fixed a bug in the popup handling that was causing this error message
you saw. Pull the latest from http://github.com/yourcelf/olwidget and
it ought to work now.

> Btw, is it possible to disable the popup for the initial layer? Or at
> least change its name, so that it won't popup as 'data'? The 'name'
> attribute given during map initialization does not seem to have an
> effect.

You can remove the default vector layer after creating the map:

map = olwidget.InfoMap(....);
map.removeLayer(map.vectorLayer);

You can change the name of the default vector layer by passing a 'name'
parameter either in the django or javascript map constructors. In my
testing, this works as it should. If it's not working for you, please
file an issue on github with a failing example and I'll look into it.

cheers,
Charlie

p.s. Omat, it may be appropriate to leave issues with olwidget to other
channels, such as the github issues list, rather than the geodjango
mailing list. I am working on http://code.djangoproject.com/ticket/5472
to incorporate olwidget into Django trunk, but until that happens, it's
probably best to keep olwidget discussions here topical to that ticket.
If folks disagree please correct me.

Skylar Saveland

unread,
Nov 17, 2009, 11:00:43 PM11/17/09
to geod...@googlegroups.com

p.s. Omat, it may be appropriate to leave issues with olwidget to other
channels, such as the github issues list, rather than the geodjango
mailing list.  I am working on http://code.djangoproject.com/ticket/5472
to incorporate olwidget into Django trunk, but until that happens, it's
probably best to keep olwidget discussions here topical to that ticket.
 If folks disagree please correct me.

I like to see the olwidget stuff here but no one should take my opinion too seriously ;-)

omat

unread,
Nov 18, 2009, 4:43:34 AM11/18/09
to geodjango
The update fixed the problem. Thanks a lot.

The tickets I opened at github before turned out to be my bad most of
the time, that's why I came here first this time :)

For the layer name always appearing as "data" for the initial layer in
InfoMap, I am opening a ticket now.


Thanks,
-- omat


On Nov 18, 6:00 am, Skylar Saveland <skylar.savel...@gmail.com> wrote:
> > p.s. Omat, it may be appropriate to leave issues with olwidget to other
> > channels, such as the github issues list, rather than the geodjango
> > mailing list.  I am working onhttp://code.djangoproject.com/ticket/5472
Reply all
Reply to author
Forward
0 new messages