Select to view content in your preferred language

limit popup visibility to feature visibility

2582
9
09-11-2012 05:27 PM
AHay
by
Deactivated User
Hi
anyone tell me how i can hide the popup when the feature is no longer visible due to scale visibility (using map.infoWindow.hide())
i have feature that are no visible below 1:100000, if a click on a feature to get the popup, if i then zoom further ( i.e. below 1:100000) the feature is no longer visible but the popup is, if keep zooming i can zoom to map extent and the whole time the pop up is pointing to the feature )

i have made it hide popup  if the user changes to the zoom tool or the pan tool but if they use "double click" on map or the scroll wheel i cannot hide the popup

any ideas?
Tags (2)
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
A Hay,

   I would attach an event listener to the layer that would call the map.infoWindow.hide() when the layer reaches the min scale or maybe just on listening for the layers visibility.
0 Kudos
AHay
by
Deactivated User
Hi
sorry can you please point me towards some documentation on How To use Event Listeners, i thought i knew how to do it and that this was straight forward but i can not work it out ( missing something simple ).

As you mentioned all i need to do is add an event listener to the layer that checks its visibility and if not visible hides the info window
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
A Hay,

  So I need to know some more info from you then. Are you talking Flex Viewer 3.0 (you should always specify what version when asking code questions)? What type of layer is is feature, dynamic? Maybe you will not need to answer these if all you need is the code code snippet:

layer.addEventListener(FlexEvent.HIDE, layer_hideHandler);
0 Kudos
AHay
by
Deactivated User
Hi
sorry you are exactly correct. i should add details of project

viewer  -   2.4
layer   - feature layer

my problem is how and where to implement it

the layer gets added dynamically from a table the user selects project from.  some projects only want to have visibility down to 1:100000 i need to add an eventlistener on the ZOOM event and if map.scale < layer.visibility then infowindow.hide()

so i assume i just write a simple function with logic described above (map.scale < ... etc)that gets called when the zoom event is fired but where would i write this?
should i add this to mapManager.mxml?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
A Hay,

   So, yes in 2.4 you would add that in the MapManager.mxml in the addLayerToMap function
if (label == "Louisville Places")
                        {
                              featureLayer.addEventListener(LayerEvent.UPDATE_END, checkMapScale);
                        }


Than add this new function to the MapManager.mxml:

            private function checkMapScale(event:LayerEvent){
                if(map.scale < 100000){
                           map.infoWindow.hide();
                }
            }
0 Kudos
AHay
by
Deactivated User
Hi rscheitlin,

sorry but now i am really confused,

in example how would the checkMapScale function get called?

seem that it is calling itself if map.scale <100000

private function checkMapScale(event:LayerEvent){
                if(map.scale < 100000){
                            featureLayer.addEventListener(LayerEvent.UPDATE_END, checkMapScale);
                }
       }


i am missing something

would i put a line in the if statement within the addLayertoMap function (MapManager.mxml) which had the ventlistener in it and tell it to run checkMapScale ?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
A Hay,

   Sorry I messed the code all up when I posted.. I have edited the post, correcting the code.
0 Kudos
AHay
by
Deactivated User
Phew, thats is good news i thought i had totally misunderstood how event worked


thanks for your quick response

i will implement know and then tick box as answered etc
0 Kudos
AHay
by
Deactivated User
Hi Rschietlin

turns out i had implemented it in the way you corrected it.

and it still didn't work, but if i tried it in a 'clean' version of 2.4 flexveiwer ( i.e. no customisation) and it worked

got very depressed at this as i though it meant i would have major issues

Then by accident i tried it in my application with a layer that did not have a visibility limit ( visible at all scales )
and it worked 

so turns out that if i have the features visibility limited to a certain scale this method doesn't work

ANSWER is ( drum roll .....)

use
featureLayer.addEventListener(LayerEvent.IS_IN_SCALE_RANGE_CHANGE, checkMapScale);


instead of

featureLayer.addEventListener(LayerEvent.UPDATE_END, checkMapScale);
0 Kudos