ThinkGeo.com    |     Documentation    |     Premium Support

Map onclick event

Hello Again,


I have been making a lot of progress in my proto-type project but I ran accross an issue.  I have wired up the Map onclick event to present a popup if you click on a feature location.  It works fine except when you move or zoom the map.  If I move or zoom the map, I can click all I want on a feature and nothing happens but If I click first on the map at a location that does not contain a feature THEN click on a feature, the popup works again.


Here is my code for the onclick event



protected void Map1_Click(object sender, MapClickedEventArgs e)
{
     Map1.Popups.Clear();

     LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays[2];
     InMemoryFeatureLayer featureLayer = (InMemoryFeatureLayer)(dynamicOverlay.Layers[0]);

     PointShape ulp = new PointShape((e.Position.X) - .02, (e.Position.Y) + .02);
     PointShape lrp = new PointShape((e.Position.X) + .02, (e.Position.Y) - .02);
     RectangleShape target = new RectangleShape(ulp, lrp);
     featureLayer.Open();
     Collection<Feature> selectedFeatures = featureLayer.QueryTools.GetFeaturesWithin(target, new string[] { "stnID", "stnName", "alarm", "pH", "Chlorine", "Turbidity", "Conductivity" });
     featureLayer.Close();

     if (selectedFeatures.Count > 0)
     {
         CloudPopup popup;
         popup = new CloudPopup("Popup", e.Position, string.Empty);
         popup.IsVisible = true;
         popup.HasCloseButton = true;
         Map1.Popups.Add(popup);

         popup.ContentHtml = GetPopupContent(selectedFeatures);
     }
}

Seems wierd the onclick works fine when I first pull up the map and do nothing and then click a feature, voila.. popup works.  But when I click a second time or pan or zoom the map.. nothing.  I even put a break point in the Onclick event and it doesn't hit the code!!!  that is what is really wierd to me.  Shouldn't the code be reached every single time you click on the map no matter what? 


So I guess the real problem is why doesn't the Map OnClick event fire everytime?  When it does fire, the popup works fine but it is not always firing... Maybe I need to do an update on my updatePane.  Since the code in the OnClick probably isnt the problem, I am attaching my aspx below 



@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ThinkGeo2.Default" %>

<%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Display a Simple Map</title>
    <style type="text/css">
        .filterStyle
        {
            -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
        }
    </style>

    <script type="text/javascript">
        var OnMapCreated = function(map) {
            var markerLayer = map.getLayer("MarkerOverlay");
            for (var i = 0, l = markerLayer.markers.length; i < l; i++) {
                var marker = markerLayer.markers<i>;
                if (marker != null && marker.icon != null) {
                    marker.icon.imageDiv.style.filter = 'alpha(opacity=0)';
                    marker.icon.imageDiv.firstChild.className = "filterStyle";
                    marker.icon.imageDiv.style.opacity = 0.0;
                }
            }
        }
    </script>

</head>
<body>
    <form> id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <table>
                <tr>
                    <td>
                        <cc1:Map ID="Map1" runat="server" Width="800px" Height="600px" 
                            OnClick="Map1_Click" onbaseoverlaychanged="Map1_BaseOverlayChanged" 
                            style="margin-right: 0px">
                        </cc1:Map>
                    </td>
                    <td valign="top">
                        <table>
                            <tr>
                                <td>
                                    <asp:Label ID="lblStation1" runat="server" Text="Station 1 - pH: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn1_pH" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="1,pH,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="1,pH,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="1,pH,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label1" runat="server" Text="Station 1 - Chlorine: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn1_Chlorine" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="1,Chlorine,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="1,Chlorine,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="1,Chlorine,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    &nbsp
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="lblStation5" runat="server" Text="Station 5 - Turbidity: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn5_Turbidity" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="5,Turbidity,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="5,Turbidity,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="5,Turbidity,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label2" runat="server" Text="Station 5 - Conductivity: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn5_Conductivity" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="5,Conductivity,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="5,Conductivity,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="5,Conductivity,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    &nbsp
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="lblStation7" runat="server" Text="Station 7 - pH: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn7_pH" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="7,pH,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="7,pH,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="7,pH,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label3" runat="server" Text="Station 7 - Chlorine: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn7_Chlorine" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="7,Chlorine,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="7,Chlorine,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="7,Chlorine,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label4" runat="server" Text="Station 7 - Turbidity: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn7_Turbidity" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="7,Turbidity,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="7,Turbidity,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="7,Turbidity,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label5" runat="server" Text="Station 7 - Conductivity: " />
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblStn7_Conductivity" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbl_SelectedIndexChanged" AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="Good" Value="7,Conductivity,Level1" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Warning" Value="7,Conductivity,Level2" />
                                        <asp:ListItem Enabled="true" Selected="false" Text="Bad" Value="7,Conductivity,Level3" />
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    &nbsp
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    &nbsp
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="lblStationSelector" runat="server" Text="Display Stations with the Following Measurements" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:CheckBoxList ID="chkBoxListMeasurements" runat="server"  
                                        OnSelectedIndexChanged="chkBoxListMeasurements_SelectedIndexChanged" 
                                        AutoPostBack="True">
                                        <asp:ListItem Enabled="true" Selected="True" Text="pH" Value="pH" />
                                        <asp:ListItem Enabled="true" Selected="True" Text="Chlorine" Value="Chlorine" />
                                        <asp:ListItem Enabled="true" Selected="True" Text="Turbidity" Value="Turbidity" />
                                        <asp:ListItem Enabled="true" Selected="True" Text="Conductivity" Value="Conductivity" />
                                    </asp:CheckBoxList>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>



thanks, Leon


 


 


 



Ok I found a solutions that will work for me I believe because this feature layer will only have about 30 or so features on it eventually though they will have many columns.


What I did was to an an OnExtentChanged event to the map object and redraw the feature layer in question.  Doing this makes the Map OnClick event always fire when I click on a feature.  May not be the best solution but it works.



protected void Map1_ExtentChanged(object sender, ExtentChangedEventArgs e)
        {
            ((LayerOverlay)Map1.CustomOverlays[2]).Redraw();
        }

Leon



 


 



Hi, Leon 
  
 I’m not sure there are some links between Click event and the Redraw method of LayerOverlay. I have used your code to test and can’t figure it out. If you still have this problem or have some interest on it please send us the entire codes you are consuming. That will be appreciated. 
  
 Thanks, 
  
 Khalil