ThinkGeo.com    |     Documentation    |     Premium Support

Highlight Click Event

Hello again,


I am having a problem with the highlight Click Event. I am using Google map, converting my latitudes/longitudes for projection, and creating shapes in the highlightoverlayer. At some point (a button click event) - I subscribe to the Highlight Click event 


Map1.HighlightOverlay.Click += new EventHandler<HighlightFeatureOverlayClickEventArgs>(HighlightOverlay_Click);


(1) Everything works, but my panning of the map becomes glitchy. Randomly, I will pan the map and the HighlightOverlay.Click will fire. 


(2) Also, I try to unsubscribe to the highlight click event and it will not work. 


Map1.HighlightOverlay.Click -= new EventHandler<HighlightFeatureOverlayClickEventArgs>(HighlightOverlay_Click);

Map1.HighlightOverlay.Click -= HighlightOverlay_Click;


I have tried to unsubscribe using both of these techniques and nothing will work. What am I missing? Or is there any solution for any of these problems I am having?


Thanks in advance, 


CF



Cruz,  
  
 In the current version, if you are trying to pan the map with the mouse on the highlight features, map is not supposed to be panned; if you are doing that too fast, the HighlightOverlay.Click event might be raised as the quick mouse down and mouse up is like a click. I think that’s the scenario of your first issue. Let me know if I’m not right. We will consider if we need to expand the panning so even the mouse is over the highlight features, the map can still be panned. 
  
 For your second issue, it’s a bug and it’ll be fixed in the next version. Thanks for pointing it out.  
  
 Thanks, 
  
 Ben

Ben, thanks for the info and your quick response. 
  
 For my first issue, I would agree with you that the map suite prob would or should fire the click event if I was trying to pan and I was on the highlighted features. In my case, It still happens even when I am panned out further away from the features and I pan somewhat slow or make sure I am not on a highlight feature. I will look into this further… It seems it is happening with Google/Yahoo map api’s. I am also converting decimal degree coodinates with the projection library to google/yahoo projections. 
  
 Thanks again, 
  
 Cruz




 


Cruz,


In my test, if the mouse is not on the highlighted features, I can pan the map pretty well even it is using GoogleMap as background and using projection for the data transformation. Could you have a look at the codes and see what the difference between yours?



 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));
                Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
                Map1.MapUnit = GeographyUnit.Meter;

                GoogleOverlay google = new GoogleOverlay("Google Map");
                google.JavaScriptLibraryUri = new Uri("maps.google.com/maps?file=api&v=2&key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q");
                google.GoogleMapType = GoogleMapType.Normal;
                Map1.CustomOverlays.Add(google);

                ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(Server.MapPath("~/SampleData/USA/states.shp"));
                Proj4Projection proj4 = new Proj4Projection(Proj4Projection.GetEpsgParametersString(4326), Proj4Projection.GetGoogleMapParametersString());
                statesLayer.FeatureSource.Projection = proj4;

                Map1.HighlightOverlay.HighlightStyle = new FeatureOverlayStyle(GeoColor.FromArgb(120, GeoColor.StandardColors.OrangeRed), GeoColor.StandardColors.Red, 1);
                statesLayer.Open();
                Collection<Feature> features = statesLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
                statesLayer.Close();
                foreach (Feature feature in features)
                {
                    Map1.HighlightOverlay.Features.Add(feature.Id, feature);
                }
            }
        }



Thanks,


Ben



Ben, here is an example that very closely resembles what I am doing.... Just to refresh, the issue I am having is the highlight click event is going off 'randomly' when clicking the map to pan around the areas. I have noticed most of the random times are when I move to the other side of the map crossing over a highlighted feature (it will happen occasionally if not as well). Just try it out for a little bit to see if you get the same results as me.


As your code shows, a real big difference is you add the google map layer to the customOverlay which I add to the backgroundOverlay so I can utilize the MarkerOverlay. Also, you add a predefined shape - I create features from points.


Let me know what you find out?


Thanks again,


Cruz



473-WebMap.zip (133 KB)

Cruz, 
  
 Thanks for pointing it out, it’s a bug. We will fix it in the coming version and for now, here is the code to work around. 
  
 
    function OnMapCreated(map) {
        var selectControls = map.getControlsByClass(“OpenLayers.Control.SelectFeature”);
        if (selectControls && selectControls.length > 0) {
            var selectControl = selectControls[0];
            selectControl.onSelect = function(feature) {
                SelectedFeature = feature;
            };
            selectControl.onUnselect = function() {
                SelectedFeature = null;
            };
            selectControl.activate();
        }

        var markerOverlay = map.getLayersByName(“MarkerOverlay”)[0];
        map.setLayerIndex(markerOverlay, 2);

        if (map.getLayersByName(“HighlightOverlay”).length > 0) {
            var highlightOverlay = map.getLayersByName(“HighlightOverlay”)[0];
            highlightOverlay.events.remove(‘click’);
            highlightOverlay.events.register(‘click’, highlightOverlay, function(evt) {
                var lonlat = this.getLonLatFromViewPortPx(evt.xy);
                var featureExtent = this.getDataExtent();
                if (featureExtent.containsLonLat(lonlat)) {
                    if (SelectedFeature)
                        __doPostBack(this.map.uniqueId, ‘HIGHLIGHTOVERLAYCLICK^’ + lonlat.lon + ‘^’ + lonlat.lat + ‘^’ + SelectedFeature.id);
                }
            });
            map.setLayerIndex(highlightOverlay, 1);
        }

        map.resetLayersZIndex();
    }

 
  
 Thanks, 
  
 Ben 
  


Ben, this fixed it! Thanks again… and probably again tomorrow! You guys have great customer support! 
  
 Cruz

Very glad to hear that! Cruz :-)

Ben,


You mentioned "In the current version, if you are trying to pan the map with the mouse on the highlight features, map is not supposed to be panned... We will consider if we need to expand the panning so even the mouse is over the highlight features, the map can still be panned".  Is there a workaround for this behavior?  We would like to be able to pan the map when using highlightoverlay features.


Thanks,


Chuck 

 



Chuck,


Please try the workaround javascript below:




[script removed]
        function OnMapCreated(map) {
            var selectControls = map.getControlsByClass("OpenLayers.Control.SelectFeature");
            var highlightOverlay = map.getLayer("HighlightOverlay");
            if (selectControls && selectControls.length > 0) {
                var selectControl = selectControls[0];
                highlightOverlay.events.register('mousedown', highlightOverlay, function() {
                    selectControl.deactivate();
                });
                highlightOverlay.events.register('mouseup', highlightOverlay, function() {
                    selectControl.activate();
                });
            }
        }
    [script removed]



thanks,


Johnny