OpenLayers 4 hover popup delayOpenLayers 3, hover (select interaction with pointMove condition) on...

A ​Note ​on ​N!

How to reduce LED flash rate (frequency)

What's the polite way to say "I need to urinate"?

How can I place the product on a social media post better?

What is Niska's accent?

Question about かな and だろう

Why was primality test thought to be NP?

Will tsunami waves travel forever if there was no land?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

Does holding a wand and speaking its command word count as V/S/M spell components?

555 timer FM transmitter

Size of electromagnet needed to replicate Earth's magnetic field

Lock file naming pattern

Refer to page numbers where table is referenced

Is there really no use for MD5 anymore?

Why do games have consumables?

How could Tony Stark make this in Endgame?

what is the sudo password for a --disabled-password user

Can someone publish a story that happened to you?

Why does processed meat contain preservatives, while canned fish needs not?

How does a program know if stdout is connected to a terminal or a pipe?

How exactly does Hawking radiation decrease the mass of black holes?

Relationship between strut and baselineskip

Was there a shared-world project before "Thieves World"?



OpenLayers 4 hover popup delay


OpenLayers 3, hover (select interaction with pointMove condition) on overlapping featuresError with popup overlay in OpenLayers 3?OpenLayers 3 popup on marker mouseoverOpenLayers 3 - popup auto panopenlayers-3 popup getfeatureinfoOpenlayers 3 getGetFeatureInfoUrl geoserver problemCORS issue with OpenLayers3 getGetFeatureInfoUrlOpenLayers 4 popupOpenLayer4 click AND hover popupOpenLayers 4 getGetFeatureInfoUrl and HitTollerance






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I added a function to display a popup on hover to the feature layer but it doesn't work very well.



Here my code:



map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}

var info = $('#info');
info.html("");
var pixel = map.getEventPixel(evt.originalEvent);
var feature = map.forEachLayerAtPixel(pixel, function(feature) { return true; }, null, function(layer) { return layer === pmfeatlayer; });
var viewResolution = map.getView().getResolution();
var coordinate = evt.coordinate;
url = pmfeatlayer.getSource().getGetFeatureInfoUrl(coordinate, viewResolution, projection, {'INFO_FORMAT': 'text/html'});

if (feature && url) {

info.css({
left: pixel[0] + 'px',
top: pixel[1] + 'px'
});
// setTimeout(function() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", url, true);
xhttp.send();
xhttp.onreadystatechange = function (aEvt) {
if (xhttp.readyState == 4 && xhttp.status == 200) {

var parser = new window.DOMParser();
var res = parser.parseFromString(xhttp.responseText, "text/xml");
var myitems = res.getElementsByTagName('item');

if(res.getElementsByTagName('item').length != 0){
info.html("<div class='hoverPopup'>" + hover(xhttp.responseText) + "</div>").delay( 1000 ).fadeIn( 400 );
} else {
info.html("");
}

} // end if 4 && 200
}; // end onreadystatechange
//}, 1000);
} // end if (feature && url)
}); // end pointermove


As you can see I'm using map.on('pointermove'... But it's not the exact event, What can I use to detect that the cursor is above the feature layer and it's not moving, for example, .5 seconds?



I tried to add a delay function but still, it doesn't work properly, it made a lot of requests and the popup display buggy due to the delay and the cursor can be on other parts of the map at the time is displayed.










share|improve this question





























    1















    I added a function to display a popup on hover to the feature layer but it doesn't work very well.



    Here my code:



    map.on('pointermove', function(evt) {
    if (evt.dragging) {
    return;
    }

    var info = $('#info');
    info.html("");
    var pixel = map.getEventPixel(evt.originalEvent);
    var feature = map.forEachLayerAtPixel(pixel, function(feature) { return true; }, null, function(layer) { return layer === pmfeatlayer; });
    var viewResolution = map.getView().getResolution();
    var coordinate = evt.coordinate;
    url = pmfeatlayer.getSource().getGetFeatureInfoUrl(coordinate, viewResolution, projection, {'INFO_FORMAT': 'text/html'});

    if (feature && url) {

    info.css({
    left: pixel[0] + 'px',
    top: pixel[1] + 'px'
    });
    // setTimeout(function() {
    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", url, true);
    xhttp.send();
    xhttp.onreadystatechange = function (aEvt) {
    if (xhttp.readyState == 4 && xhttp.status == 200) {

    var parser = new window.DOMParser();
    var res = parser.parseFromString(xhttp.responseText, "text/xml");
    var myitems = res.getElementsByTagName('item');

    if(res.getElementsByTagName('item').length != 0){
    info.html("<div class='hoverPopup'>" + hover(xhttp.responseText) + "</div>").delay( 1000 ).fadeIn( 400 );
    } else {
    info.html("");
    }

    } // end if 4 && 200
    }; // end onreadystatechange
    //}, 1000);
    } // end if (feature && url)
    }); // end pointermove


    As you can see I'm using map.on('pointermove'... But it's not the exact event, What can I use to detect that the cursor is above the feature layer and it's not moving, for example, .5 seconds?



    I tried to add a delay function but still, it doesn't work properly, it made a lot of requests and the popup display buggy due to the delay and the cursor can be on other parts of the map at the time is displayed.










    share|improve this question

























      1












      1








      1


      1






      I added a function to display a popup on hover to the feature layer but it doesn't work very well.



      Here my code:



      map.on('pointermove', function(evt) {
      if (evt.dragging) {
      return;
      }

      var info = $('#info');
      info.html("");
      var pixel = map.getEventPixel(evt.originalEvent);
      var feature = map.forEachLayerAtPixel(pixel, function(feature) { return true; }, null, function(layer) { return layer === pmfeatlayer; });
      var viewResolution = map.getView().getResolution();
      var coordinate = evt.coordinate;
      url = pmfeatlayer.getSource().getGetFeatureInfoUrl(coordinate, viewResolution, projection, {'INFO_FORMAT': 'text/html'});

      if (feature && url) {

      info.css({
      left: pixel[0] + 'px',
      top: pixel[1] + 'px'
      });
      // setTimeout(function() {
      var xhttp = new XMLHttpRequest();
      xhttp.open("GET", url, true);
      xhttp.send();
      xhttp.onreadystatechange = function (aEvt) {
      if (xhttp.readyState == 4 && xhttp.status == 200) {

      var parser = new window.DOMParser();
      var res = parser.parseFromString(xhttp.responseText, "text/xml");
      var myitems = res.getElementsByTagName('item');

      if(res.getElementsByTagName('item').length != 0){
      info.html("<div class='hoverPopup'>" + hover(xhttp.responseText) + "</div>").delay( 1000 ).fadeIn( 400 );
      } else {
      info.html("");
      }

      } // end if 4 && 200
      }; // end onreadystatechange
      //}, 1000);
      } // end if (feature && url)
      }); // end pointermove


      As you can see I'm using map.on('pointermove'... But it's not the exact event, What can I use to detect that the cursor is above the feature layer and it's not moving, for example, .5 seconds?



      I tried to add a delay function but still, it doesn't work properly, it made a lot of requests and the popup display buggy due to the delay and the cursor can be on other parts of the map at the time is displayed.










      share|improve this question














      I added a function to display a popup on hover to the feature layer but it doesn't work very well.



      Here my code:



      map.on('pointermove', function(evt) {
      if (evt.dragging) {
      return;
      }

      var info = $('#info');
      info.html("");
      var pixel = map.getEventPixel(evt.originalEvent);
      var feature = map.forEachLayerAtPixel(pixel, function(feature) { return true; }, null, function(layer) { return layer === pmfeatlayer; });
      var viewResolution = map.getView().getResolution();
      var coordinate = evt.coordinate;
      url = pmfeatlayer.getSource().getGetFeatureInfoUrl(coordinate, viewResolution, projection, {'INFO_FORMAT': 'text/html'});

      if (feature && url) {

      info.css({
      left: pixel[0] + 'px',
      top: pixel[1] + 'px'
      });
      // setTimeout(function() {
      var xhttp = new XMLHttpRequest();
      xhttp.open("GET", url, true);
      xhttp.send();
      xhttp.onreadystatechange = function (aEvt) {
      if (xhttp.readyState == 4 && xhttp.status == 200) {

      var parser = new window.DOMParser();
      var res = parser.parseFromString(xhttp.responseText, "text/xml");
      var myitems = res.getElementsByTagName('item');

      if(res.getElementsByTagName('item').length != 0){
      info.html("<div class='hoverPopup'>" + hover(xhttp.responseText) + "</div>").delay( 1000 ).fadeIn( 400 );
      } else {
      info.html("");
      }

      } // end if 4 && 200
      }; // end onreadystatechange
      //}, 1000);
      } // end if (feature && url)
      }); // end pointermove


      As you can see I'm using map.on('pointermove'... But it's not the exact event, What can I use to detect that the cursor is above the feature layer and it's not moving, for example, .5 seconds?



      I tried to add a delay function but still, it doesn't work properly, it made a lot of requests and the popup display buggy due to the delay and the cursor can be on other parts of the map at the time is displayed.







      javascript openlayers event-listener






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 31 '18 at 11:28









      SebastianoSebastiano

      17416




      17416






















          3 Answers
          3






          active

          oldest

          votes


















          1














          You can try a debounce or throttle function to delay the calls for the popup.



          A very simple way could look like this:



          var stillMoving = [];
          function delayPopup() {
          stillMoving.push(true); // add my call to array

          setTimeout(function() {
          stillMoving.shift(); // remove my call from array

          // check if more calls are pending
          // if yes stop propagation
          if ( stillMoving[ 0 ] ) {
          return;
          }
          else {
          // load the popup here
          loadPopup();
          }
          }, 500);
          }





          share|improve this answer
























          • I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

            – Sebastiano
            Jan 31 '18 at 13:35











          • And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

            – Sebastiano
            Jan 31 '18 at 13:40













          • In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

            – bennos
            Jan 31 '18 at 13:53











          • I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

            – Sebastiano
            Jan 31 '18 at 13:58













          • Can you create a simple fiddle with the problem?

            – bennos
            Jan 31 '18 at 14:01



















          0














          I am doing something similar and found a way to delay based on mouse position:



              $.pixelDistance = 0.01;
          $.pastPixel = undefined;
          map.on('pointermove', function(evt) {
          if (evt.dragging) {
          return;
          }
          var pixel = map.getEventPixel(evt.originalEvent);
          $.pastPixel = pixel;
          setTimeout(function(){
          console.log((pixel=== $.pastPixel));
          if(pixel===$.pastPixel)
          {
          var feature1 = map.forEachLayerAtPixel( $.pastPixel, function(feature1) { return true; }, null, function(layer) { return layer === vector; });
          console.log(feature1); // end if (feature && url)
          console.log( $.pastPixel); // end if (feature && url)
          }
          }, 1000);

          }); // end pointermove





          share|improve this answer































            0














            There is a simpler method by canceling the delayed execution whenever the mouse is moved again.



            var LastTimeoutRequest;
            var LastLonLat;

            function DisplayInfo(){
            console.log('executed now');
            document.getElementById("pointerposition").innerHTML = '<b>' + LastLonLat + '</b>';
            }

            map.on('pointermove', function(evt) {
            if (evt.dragging) return;

            if (typeof LastTimeoutRequest !== 'undefined') { // cancel timeout when the mouse moves
            clearTimeout(LastTimeoutRequest);
            }

            LastLonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
            document.getElementById("pointerposition").innerHTML = LastLonLat ;

            LastTimeoutRequest = setTimeout(DisplayInfoAtPosition, 2000);
            });


            This example will display the mouse postition and turn it in bold it it does not move for 2000 ms.





            share








            New contributor




            A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "79"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f269858%2fopenlayers-4-hover-popup-delay%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You can try a debounce or throttle function to delay the calls for the popup.



              A very simple way could look like this:



              var stillMoving = [];
              function delayPopup() {
              stillMoving.push(true); // add my call to array

              setTimeout(function() {
              stillMoving.shift(); // remove my call from array

              // check if more calls are pending
              // if yes stop propagation
              if ( stillMoving[ 0 ] ) {
              return;
              }
              else {
              // load the popup here
              loadPopup();
              }
              }, 500);
              }





              share|improve this answer
























              • I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

                – Sebastiano
                Jan 31 '18 at 13:35











              • And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

                – Sebastiano
                Jan 31 '18 at 13:40













              • In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

                – bennos
                Jan 31 '18 at 13:53











              • I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

                – Sebastiano
                Jan 31 '18 at 13:58













              • Can you create a simple fiddle with the problem?

                – bennos
                Jan 31 '18 at 14:01
















              1














              You can try a debounce or throttle function to delay the calls for the popup.



              A very simple way could look like this:



              var stillMoving = [];
              function delayPopup() {
              stillMoving.push(true); // add my call to array

              setTimeout(function() {
              stillMoving.shift(); // remove my call from array

              // check if more calls are pending
              // if yes stop propagation
              if ( stillMoving[ 0 ] ) {
              return;
              }
              else {
              // load the popup here
              loadPopup();
              }
              }, 500);
              }





              share|improve this answer
























              • I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

                – Sebastiano
                Jan 31 '18 at 13:35











              • And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

                – Sebastiano
                Jan 31 '18 at 13:40













              • In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

                – bennos
                Jan 31 '18 at 13:53











              • I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

                – Sebastiano
                Jan 31 '18 at 13:58













              • Can you create a simple fiddle with the problem?

                – bennos
                Jan 31 '18 at 14:01














              1












              1








              1







              You can try a debounce or throttle function to delay the calls for the popup.



              A very simple way could look like this:



              var stillMoving = [];
              function delayPopup() {
              stillMoving.push(true); // add my call to array

              setTimeout(function() {
              stillMoving.shift(); // remove my call from array

              // check if more calls are pending
              // if yes stop propagation
              if ( stillMoving[ 0 ] ) {
              return;
              }
              else {
              // load the popup here
              loadPopup();
              }
              }, 500);
              }





              share|improve this answer













              You can try a debounce or throttle function to delay the calls for the popup.



              A very simple way could look like this:



              var stillMoving = [];
              function delayPopup() {
              stillMoving.push(true); // add my call to array

              setTimeout(function() {
              stillMoving.shift(); // remove my call from array

              // check if more calls are pending
              // if yes stop propagation
              if ( stillMoving[ 0 ] ) {
              return;
              }
              else {
              // load the popup here
              loadPopup();
              }
              }, 500);
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 31 '18 at 12:28









              bennosbennos

              1,4041018




              1,4041018













              • I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

                – Sebastiano
                Jan 31 '18 at 13:35











              • And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

                – Sebastiano
                Jan 31 '18 at 13:40













              • In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

                – bennos
                Jan 31 '18 at 13:53











              • I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

                – Sebastiano
                Jan 31 '18 at 13:58













              • Can you create a simple fiddle with the problem?

                – bennos
                Jan 31 '18 at 14:01



















              • I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

                – Sebastiano
                Jan 31 '18 at 13:35











              • And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

                – Sebastiano
                Jan 31 '18 at 13:40













              • In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

                – bennos
                Jan 31 '18 at 13:53











              • I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

                – Sebastiano
                Jan 31 '18 at 13:58













              • Can you create a simple fiddle with the problem?

                – bennos
                Jan 31 '18 at 14:01

















              I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

              – Sebastiano
              Jan 31 '18 at 13:35





              I'm still having the same issue, even with a timeout (your version and my version) it load a lot of http request when you stop moving the mouse, and it seems it remember all the coordinates from the last time the mouse enter till it stops, it creates a couple of popups.

              – Sebastiano
              Jan 31 '18 at 13:35













              And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

              – Sebastiano
              Jan 31 '18 at 13:40







              And as you can see from the example, pretty different from mine but same concept, they don't use delay. openlayers.org/en/latest/examples/kml-earthquakes.html

              – Sebastiano
              Jan 31 '18 at 13:40















              In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

              – bennos
              Jan 31 '18 at 13:53





              In the example you are referreing to they use a vector which means they do not have to send all those requests, because the data is already in the client (loaded with the vector source KML). With the code I added all requests while moving should be filtered except the last one, which will then fire and show the popup.

              – bennos
              Jan 31 '18 at 13:53













              I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

              – Sebastiano
              Jan 31 '18 at 13:58







              I wrapped from var info to //end if (feature && url) and inserted in your else where you call loadPopup(), but it doesn't work properly, I have more popup that just the last one. And I change the call of your function with anonimus and IIFE

              – Sebastiano
              Jan 31 '18 at 13:58















              Can you create a simple fiddle with the problem?

              – bennos
              Jan 31 '18 at 14:01





              Can you create a simple fiddle with the problem?

              – bennos
              Jan 31 '18 at 14:01













              0














              I am doing something similar and found a way to delay based on mouse position:



                  $.pixelDistance = 0.01;
              $.pastPixel = undefined;
              map.on('pointermove', function(evt) {
              if (evt.dragging) {
              return;
              }
              var pixel = map.getEventPixel(evt.originalEvent);
              $.pastPixel = pixel;
              setTimeout(function(){
              console.log((pixel=== $.pastPixel));
              if(pixel===$.pastPixel)
              {
              var feature1 = map.forEachLayerAtPixel( $.pastPixel, function(feature1) { return true; }, null, function(layer) { return layer === vector; });
              console.log(feature1); // end if (feature && url)
              console.log( $.pastPixel); // end if (feature && url)
              }
              }, 1000);

              }); // end pointermove





              share|improve this answer




























                0














                I am doing something similar and found a way to delay based on mouse position:



                    $.pixelDistance = 0.01;
                $.pastPixel = undefined;
                map.on('pointermove', function(evt) {
                if (evt.dragging) {
                return;
                }
                var pixel = map.getEventPixel(evt.originalEvent);
                $.pastPixel = pixel;
                setTimeout(function(){
                console.log((pixel=== $.pastPixel));
                if(pixel===$.pastPixel)
                {
                var feature1 = map.forEachLayerAtPixel( $.pastPixel, function(feature1) { return true; }, null, function(layer) { return layer === vector; });
                console.log(feature1); // end if (feature && url)
                console.log( $.pastPixel); // end if (feature && url)
                }
                }, 1000);

                }); // end pointermove





                share|improve this answer


























                  0












                  0








                  0







                  I am doing something similar and found a way to delay based on mouse position:



                      $.pixelDistance = 0.01;
                  $.pastPixel = undefined;
                  map.on('pointermove', function(evt) {
                  if (evt.dragging) {
                  return;
                  }
                  var pixel = map.getEventPixel(evt.originalEvent);
                  $.pastPixel = pixel;
                  setTimeout(function(){
                  console.log((pixel=== $.pastPixel));
                  if(pixel===$.pastPixel)
                  {
                  var feature1 = map.forEachLayerAtPixel( $.pastPixel, function(feature1) { return true; }, null, function(layer) { return layer === vector; });
                  console.log(feature1); // end if (feature && url)
                  console.log( $.pastPixel); // end if (feature && url)
                  }
                  }, 1000);

                  }); // end pointermove





                  share|improve this answer













                  I am doing something similar and found a way to delay based on mouse position:



                      $.pixelDistance = 0.01;
                  $.pastPixel = undefined;
                  map.on('pointermove', function(evt) {
                  if (evt.dragging) {
                  return;
                  }
                  var pixel = map.getEventPixel(evt.originalEvent);
                  $.pastPixel = pixel;
                  setTimeout(function(){
                  console.log((pixel=== $.pastPixel));
                  if(pixel===$.pastPixel)
                  {
                  var feature1 = map.forEachLayerAtPixel( $.pastPixel, function(feature1) { return true; }, null, function(layer) { return layer === vector; });
                  console.log(feature1); // end if (feature && url)
                  console.log( $.pastPixel); // end if (feature && url)
                  }
                  }, 1000);

                  }); // end pointermove






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 '18 at 8:24









                  Кальо КатеровКальо Катеров

                  1




                  1























                      0














                      There is a simpler method by canceling the delayed execution whenever the mouse is moved again.



                      var LastTimeoutRequest;
                      var LastLonLat;

                      function DisplayInfo(){
                      console.log('executed now');
                      document.getElementById("pointerposition").innerHTML = '<b>' + LastLonLat + '</b>';
                      }

                      map.on('pointermove', function(evt) {
                      if (evt.dragging) return;

                      if (typeof LastTimeoutRequest !== 'undefined') { // cancel timeout when the mouse moves
                      clearTimeout(LastTimeoutRequest);
                      }

                      LastLonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
                      document.getElementById("pointerposition").innerHTML = LastLonLat ;

                      LastTimeoutRequest = setTimeout(DisplayInfoAtPosition, 2000);
                      });


                      This example will display the mouse postition and turn it in bold it it does not move for 2000 ms.





                      share








                      New contributor




                      A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        There is a simpler method by canceling the delayed execution whenever the mouse is moved again.



                        var LastTimeoutRequest;
                        var LastLonLat;

                        function DisplayInfo(){
                        console.log('executed now');
                        document.getElementById("pointerposition").innerHTML = '<b>' + LastLonLat + '</b>';
                        }

                        map.on('pointermove', function(evt) {
                        if (evt.dragging) return;

                        if (typeof LastTimeoutRequest !== 'undefined') { // cancel timeout when the mouse moves
                        clearTimeout(LastTimeoutRequest);
                        }

                        LastLonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
                        document.getElementById("pointerposition").innerHTML = LastLonLat ;

                        LastTimeoutRequest = setTimeout(DisplayInfoAtPosition, 2000);
                        });


                        This example will display the mouse postition and turn it in bold it it does not move for 2000 ms.





                        share








                        New contributor




                        A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          There is a simpler method by canceling the delayed execution whenever the mouse is moved again.



                          var LastTimeoutRequest;
                          var LastLonLat;

                          function DisplayInfo(){
                          console.log('executed now');
                          document.getElementById("pointerposition").innerHTML = '<b>' + LastLonLat + '</b>';
                          }

                          map.on('pointermove', function(evt) {
                          if (evt.dragging) return;

                          if (typeof LastTimeoutRequest !== 'undefined') { // cancel timeout when the mouse moves
                          clearTimeout(LastTimeoutRequest);
                          }

                          LastLonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
                          document.getElementById("pointerposition").innerHTML = LastLonLat ;

                          LastTimeoutRequest = setTimeout(DisplayInfoAtPosition, 2000);
                          });


                          This example will display the mouse postition and turn it in bold it it does not move for 2000 ms.





                          share








                          New contributor




                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          There is a simpler method by canceling the delayed execution whenever the mouse is moved again.



                          var LastTimeoutRequest;
                          var LastLonLat;

                          function DisplayInfo(){
                          console.log('executed now');
                          document.getElementById("pointerposition").innerHTML = '<b>' + LastLonLat + '</b>';
                          }

                          map.on('pointermove', function(evt) {
                          if (evt.dragging) return;

                          if (typeof LastTimeoutRequest !== 'undefined') { // cancel timeout when the mouse moves
                          clearTimeout(LastTimeoutRequest);
                          }

                          LastLonLat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
                          document.getElementById("pointerposition").innerHTML = LastLonLat ;

                          LastTimeoutRequest = setTimeout(DisplayInfoAtPosition, 2000);
                          });


                          This example will display the mouse postition and turn it in bold it it does not move for 2000 ms.






                          share








                          New contributor




                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.








                          share


                          share






                          New contributor




                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 9 mins ago









                          A. PaceA. Pace

                          1




                          1




                          New contributor




                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          A. Pace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f269858%2fopenlayers-4-hover-popup-delay%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                              is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                              Meter-Bus Содержание Параметры шины | Стандартизация |...