0

I've implemented the getFeature function in my OL4 as in the example: https://openlayers.org/en/latest/examples/getfeatureinfo-tile.html

  map.on('singleclick', function(evt) {
    document.getElementById('info').innerHTML = '';
    var viewResolution = /** @type {number} */ (view.getResolution());
    var url = wmsSource.getGetFeatureInfoUrl(
        evt.coordinate, viewResolution, 'EPSG:3857',
        {'INFO_FORMAT': 'text/html'});
    if (url) {
      document.getElementById('info').innerHTML =
          '<iframe seamless src="' + url + '"></iframe>';
    }
  });

How can I handle the result in order to create a tooltip? I don't want to use the <iframe>

If I console.log the var URL, I have back the URL itself and not the XML page, how can I have back the XML page?

I also tried with var xmlDoc = parser.parseFromString(url,"text/xml"); but what I get back is not the XML.

  • 1
    You can use Overlay as an HTMLElement. and just check the comments on your past question. that's the answer how you do. – Chase Choi Nov 28 '17 at 13:17
  • I answer you in the other post, in this post we are talking about different stuff, if you click on the street line in this web traffwebdemo.co.uk/parking you have back data from mapserver, and it's manipulated to appear in the popup. – Sebastiano Nov 28 '17 at 15:04
  • the comment is for your first question about iframe. – Chase Choi Nov 29 '17 at 0:40
  • As I don't want the iframe and I don't know how to use the Overlay I found a way with XMLHttpRequest() you can see the solution below in my answer. It seems that OL4 doesn't create a real xml request, it gives you an URL and with iframe you can access that URL and import the content, but I want to manipulate the content before to show it on the screen. – Sebastiano Nov 29 '17 at 10:52
0

I found a way.

if (url) {

var xhttp = new XMLHttpRequest();
xhttp.open("GET", url, true);
xhttp.send();
xhttp.onreadystatechange = function (aEvt) {
  if (xhttp.readyState == 4) {
    if (xhttp.status == 200)  {
      //console.log(xhttp.responseText);
      document.getElementById('popup-content').innerHTML = xhttp.responseText;
        }
      }
    };

} // end if url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.