[SOLVED] How to access and interrogate web pages?

Hi all!

I’d like to access some online mapping data via a URL ( such as http://vector.mapzen.com/osm/all/17/38588/49287.json ) and am wondering how do go about doing this? I’m quite rusty with JavaScript and wondering if this is possible within PlayCanvas’s architecture?

Just to be clear, I’m not interested in how to parse this or other data, rather just wanting to know how and if I can access and interrogate webpages in general.

Any help would be really appreciated!!

Cheers! :smile:

PlayCanvas runs as a Javascript application inside the browser, so HTTP requests to websites are available.

I do that most of the time with jQuery (you can load 3rd party libraries from the menu tab on the top-left -> Script Priority).

$.getJSON( "http://vector.mapzen.com/osm/all/17/38588/49287.json", function( data ) {
   console.log(data);
});

Just be aware of CORS when requesting content from outside of your domain (google that).

1 Like

PlayCanvas also has an http library built into the engine

pc.http.get("http://vector.mapzen.com/osm/all/17/38588/49287.json", function (err, data) {
  if (!err) {
    // use data
  }
});
2 Likes

Really!? That’s great! Thanks for the info.