[OpenLayers-Users] Stop drawing when two points are close together / doubleclicking with a touch-screen

Jelmer Baas jelmerbs at xs4all.nl
Wed Jun 16 12:36:37 EDT 2010


Hello list,

Could please get a confirmation that this message reached the mailing list?

Thanks,

Regards,
Jelmer Baas
> Hi,
>
> We are using OpenLayers for an application that will run on a laptop
> with a touchscreen. This makes double-clicking (to end drawing new
> geometry) very difficult. So instead I wanted to check (while drawing)
> if two points are very close together, and if so, stop drawing after that.
>
> Right now I have:
> myLayer.events.register('sketchmodified', myLayer, sketchModified);
>
> function sketchModified(obj) {
>    var tmp = obj.feature.geometry.components;
>    var intCount = tmp[0].components.length;
>     if (intCount>  4) {
>      var p1 = map.getPixelFromLonLat(new
> OpenLayers.LonLat(tmp[0].components[intCount-4].x,tmp[0].components[intCount-4].y));
>      var p2 = map.getPixelFromLonLat(new
> OpenLayers.LonLat(tmp[0].components[intCount-3].x,tmp[0].components[intCount-3].y));
>      var x = Math.abs(p1.x - p2.x);
>      var y = Math.abs(p1.y - p2.y);
>      var length = Math.sqrt(x * x + y * y);
>      if (length<  10) {
>        alert('stop drawing here');
>      }
>    }
> }
>
> Although very wonky code, it actually does work. I however can't seem to
> figure out how to "submit" the geometry that has been drawn so far
> (i.e., simulate a double-click and let my control do it's save-refresh
> dance).
>
> Anyone can help me with that?
>
> And yes, I'm aware that the sketchmodified event is fired much more
> often than neccesary, that's not really an issue with touchscreens,
> though. Of course, better solutions (perhaps even a setting to make
> double-clicks easier? Or give double-clicks a few pixel tolerance?) are
> more than welcome!
>
> P.S.: I also sent this same email from my work account, but somehow it
> didn't show up in the mailing list... Very odd.
>
> Regards,
> Jelmer Baas
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>    




More information about the Users mailing list