1

I am trying to create a tap/touch on a feature to handle some action. It works on the Chrome browser. But when I install the apk on the Android phone/tablet it does not work.

My environment:
- Cordova 8
- Angular 6
- Open Layers 4.5

this.map.on('singleclick', (evt) => {
  //console.log("map clicked");
  let coord = this.map.getEventCoordinate(evt.originalEvent);
  let feature = this.map.forEachFeatureAtPixel(evt.pixel,
    (feature) => {
      //console.log("Feature found on click!")
      return feature;
    }, {hitTolerance: 10});
  if (feature) {
    var coordinates = feature.getGeometry().getCoordinates();
    //console.log("Feature Clicked: " + feature.getId() + "("+ feature.name +")"+ " [ " + coordinates[0] + ", " + coordinates[1] + " ]");
    this.toggleTooltip(feature, true); 
  }
  else {
    //console.log("Feature not found on click");
    this.toggleTooltip(null, null);
  }
  feature.changed();
});

I tried using hitTolerance but without any luck.

Please help!

JGH
  • 15,928
  • 4
  • 31
  • 48
  • what does evt.originalEvent return on your device? Is this some jQuery thing? – Rob Mar 19 '19 at 09:34
  • I get the following lines from logcat: 03-19 12:33:17.628 23199-23199/? I/chromium: [INFO:CONSOLE(1)] "Original Event{"isTrusted":true}", source: file:///android_asset/www/main.079628547cd90690f2b8.js (1) 03-19 12:33:45.768 23199-23199/? D/SystemWebChromeClient: file:///android_asset/www/main.079628547cd90690f2b8.js: Line 1 : Original Event{"isTrusted":true} 03-19 12:33:45.768 23199-23199/? I/chromium: [INFO:CONSOLE(1)] "Original Event{"isTrusted":true}", source: file:///android_asset/www/main.079628547cd90690f2b8.js (1) – Giridhar Kandachar Mar 19 '19 at 10:35
  • Browser debug gives the following output: b: Ld {type: "pointerdown", target: Xd, b: PointerEvent, buttons: 1, pressure: 1, …} coordinate: (2) [2774739.095753681, 8437388.503773717] dragging: false frameState: {animate: false, attributions: {…}, coordinateToPixelTransform: Array(6), extent: Array(4), focus: Array(2), …} map: J {Va: {…}, qa: {…}, oa: {…}, g: 0, op: 17, …} originalEvent: PointerEvent {isTrusted: true, pointerId: 6, width: 23, height: 23, pressure: 1, …} pixel: (2) [211, 189] target: J {Va: {…}, qa: {…}, oa: {…}, g: 0, op: 17, …} type: "singleclick" __proto__: ed – Giridhar Kandachar Mar 19 '19 at 10:36
  • you get 'coord' with this.map.getCoordinate(evt.originalEvent), but you don't do anything with it. You use the evt.pixel for forEachFeatureAtPixel. You could try to get this.map.getEventPixel(event) instead of getting the coordinate, an then use that pixel for map.forEachFeatureAtPixel – Rob Mar 19 '19 at 11:03
  • Hi Rob, Please ignore the coord which I get. I am using evt.pixel to fetch the Feature with hitTolerance of 10. – Giridhar Kandachar Mar 19 '19 at 11:16

0 Answers0