[OpenLayers-Users] Problem with click event in mobile browsers

Christian Spanring cspanring at gmail.com
Mon Jul 18 22:35:14 EDT 2011


Thanks! That did it, my map is now working with touch events.

Christian

On Sun, Jul 17, 2011 at 8:22 PM,  <christopher.schmidt at nokia.com> wrote:
> This is the right way to do it. Because of how we have to handle touch events,
> if you want to handle clicks on touch devices, you're best off using the click
> handler.
>
> -- Chris
>
> On Jul 17, 2011, at 6:48 PM, ext Richard Greenwood wrote:
>
>> On Sun, Jul 17, 2011 at 4:41 PM, Christian Spanring <cspanring at gmail.com> wrote:
>>> Hi,
>>>
>>> I'm having problems with a 'click' event in mobile browsers. A 'click'
>>> event registered with
>>>
>>>    map.events.register('click', map, clickEvent);
>>>
>>> doesn't seem to fire in default browsers on Android 2.3, 3.2 and iOS
>>> 4.2 (works without error on desktop browsers).
>>>
>>> I'm trying to read the coordinates a user 'tapped' on a map with something like
>>>
>>>    function clickEvent(e) {
>>>        var clickCoord = e.object.getLonLatFromPixel(e.xy);
>>>    }
>>>
>>> without much luck so far.
>>>
>>> Is there something fundamentally wrong with my approach or is this a
>>> known issue with mobile browsers?
>>>
>>> I'm working with OpenLayers 2.x at 0b9555a4c81fb1f94d56.
>>>
>>> Thanks!
>>> Christian
>>
>> Christian,
>>
>> I won't say that this is the right way, but it does work for me.
>>
>> 1. Create a click handler. This is basically just a copy and paste from
>> http://dev.openlayers.org/docs/files/OpenLayers/Handler/Click-js.html
>>
>> OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
>>  defaultHandlerOptions: {
>>    'single': true,
>>    'double': false,
>>    'pixelTolerance': 0,
>>    'stopSingle': false,
>>    'stopDouble': false
>>  },
>>  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
>>    );
>>  }
>> });
>>
>>
>> 2. Use the click handler:
>>
>> var click = new OpenLayers.Control.Click( { trigger: function(e) {
>>    /* do your thing */
>> }
>>
>> Other may be able to provide a bteer approach.
>>
>> Rich
>>
>> --
>> Richard Greenwood
>> richard.greenwood at gmail.com
>> www.greenwoodmap.com
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>


More information about the Users mailing list