OpenLayers Click Events

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenLayers Click Events

webedgegav
This post has NOT been accepted by the mailing list yet.
Hello,

I'm developing a web application where the user clicks on a map and we retrieve some property information and highlight the property on the map. As this request might take a second or 2 I display a waiting image when we receive the click event and remove it when we get the results, but this is still not great as there is actually a delay while the map click event is triggered (See the code below). To get round this I've put in jquery code to display the waiting image as soon as the jquery click event is received. This works ok when the user click on a single point on the map but if they click on the map so navigate to another point by dragging the map, the code triggers the jquery click by never gets the OpenLayers map click so so never triggers the request.

Can anyone help me differential between these 2 click events or is there a better way to do this.

Thanks


    OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
        defaultHandlerOptions: {
            'single': true,
            'double': false,
            'pixelTolerance': 0,
            'stopSingle': true,
            'stopDouble': true
        },

        initialize: function (options) {
            this.handlerOptions = OpenLayers.Util.extend(
                        {}, this.defaultHandlerOptions
                    );
            OpenLayers.Control.prototype.initialize.apply(
                        this, arguments
                    );
            this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.trigger
                        }, this.handlerOptions
                    );
        },

        trigger: function (e) {
            var lonlat = map.getLonLatFromViewPortPx(e.xy).transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));

            OpenLayers.ProxyHost = 'iWFSProxy.ashx?';

            var linzURL;
            linzURL = "http://api.data.linz.govt.nz/api/vectorQuery.json?key=[devkey]&layer=804&x=" + lonlat.lon + "&y=" + lonlat.lat + "&max_results=1&radius=10000&geometry=true&with_field_names=true"
            var request = OpenLayers.Request.GET({
                url: linzURL,
                callback: handler
            });

        }

    });

Reply | Threaded
Open this post in threaded view
|

Re: OpenLayers Click Events

webedgegav
This post has NOT been accepted by the mailing list yet.
Further Information for this post.

It seems that adding this click control, 'disables' the JQuery MouseDown event leaving only the MouseUp Event.

Also, if I change the PixelTolerance to NULL then this event is trigger on both the Click and the Drag event but I haven't found a way to tell which is which (ie. whether the event was triggered by a click or drag), in both cases the XY coordinates are the same. If there is a way to tell them apart I could hide the waiting image in the Drag case and call the web service in the Click case.