[OpenLayers-Users] How to programmatically open/close Popup?

Stephen Woodbridge woodbri at swoodbridge.com
Fri Mar 12 10:08:28 EST 2010


Alexandre Dube wrote:
> Hi Steve,
> 
> You could manually trigger the "unselect" method of the ModifyFeature 
> control to unselect the currently selected feature, something like this :
> 
> map.controls[7].selectControl.unselect(map.layers[1].selectedFeatures[0]);
> 
> Instead of using the control and layer from their arrays, I would use 
> variable names (when creating them), like instead of doing 
> map.addControl(new OpenLayers.Control....), I prefer doing var myVar= 
> new OL.ctrl.... and then map.addCtrl(myVar)

Hi Alexandre,

OK, I'm not sure how this will work because the control is added in 
OpenLayers.Control.MyToolbar class and it seems like bad practice to 
globally reference a control belonging to a class. So I thinking that 
maybe I can track the openpopup as an attribute of MyToolbar and then 
assign MyToolBar to a var like:

var mytoolbar = new OpenLayers.Control.MyToolbar(...);
map.addControl(mytoolbar);

then I can access it like:

if (mytoolbar.openpopup) {
   mytoolbar.openpopup.unselect(mytoolbar.openpopup.feature);
}

I already track feature in the popup object. I would have to null 
mytoolbar.openpopup after it is unselected.

I'll try this. Let me know your thoughts?

-Steve

> Also, instead of using onSelect and onUnselect methods of the 
> ModifyFeature control, try registering "select" and "unselect" events on 
> the layer, because the above solution won't work unless you do so.
> 
> Try that and tell me about it.
> 
> Best regards,
> 
> Alexandre
> 
> 
> Stephen Woodbridge wrote:
>> Hi all,
>>
>> I have an OpenLayers.Popup.FramedCloud popup that contains a form for 
>> entering/editing a features attributes. The form has a save button 
>> with an onClick function attached that needs to save the data to the 
>> server then close the popup. Currently the button only issue an alert.
>>
>> How can I programmatically trigger the close from my onclick handler?
>>
>> You can see example here:
>> http://imaptools.com:8080/tilecache/test.html?zoom=17&lat=33.89595&lon=35.49935&layers=BT 
>>
>>
>> 1) load page, pan slightly to work around feature load bug
>> 2) click left most tool in tool bar
>> 3) click on green POI (you should get popup)
>>
>> I have only worked on this in FF, others might not work yet.
>>
>> I have looked over the event code and the popup code, but I'm not 
>> seeing a way to do this.
>>
>> Thanks,
>>    -Steve
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>   
> 
> 




More information about the Users mailing list