{"action":"created","issue":{"url":"https://api.github.com/repos/openlayers/ol3/issues/5325","repository_url":"https://api.github.com/repos/openlayers/ol3","labels_url":"https://api.github.com/repos/openlayers/ol3/issues/5325/labels{/name}","comments_url":"https://api.github.com/repos/openlayers/ol3/issues/5325/comments","events_url":"https://api.github.com/repos/openlayers/ol3/issues/5325/events","html_url":"https://github.com/openlayers/ol3/issues/5325","id":153873330,"number":5325,"title":"New Feature: Triggering tile load events on ol.sourceVector when tile loading strategy is employed","user":{"login":"jan-tosovsky-cz","id":3907898,"avatar_url":"https://avatars.githubusercontent.com/u/3907898?v=3","gravatar_id":"","url":"https://api.github.com/users/jan-tosovsky-cz","html_url":"https://github.com/jan-tosovsky-cz","followers_url":"https://api.github.com/users/jan-tosovsky-cz/followers","following_url":"https://api.github.com/users/jan-tosovsky-cz/following{/other_user}","gists_url":"https://api.github.com/users/jan-tosovsky-cz/gists{/gist_id}","starred_url":"https://api.github.com/users/jan-tosovsky-cz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jan-tosovsky-cz/subscriptions","organizations_url":"https://api.github.com/users/jan-tosovsky-cz/orgs","repos_url":"https://api.github.com/users/jan-tosovsky-cz/repos","events_url":"https://api.github.com/users/jan-tosovsky-cz/events{/privacy}","received_events_url":"https://api.github.com/users/jan-tosovsky-cz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/openlayers/ol3/labels/pull%20request%20accepted","name":"pull request accepted","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-09T21:23:22Z","updated_at":"2016-05-10T21:25:39Z","closed_at":null,"body":"On tiled source it is possible to count tileloadstart/tileloadend/tileloaderror events to check if all tiles have been loaded:\r\nhttp://openlayers.org/en/master/examples/tile-load-events.html\r\nIt would be nice to do the same for ol.sourceVector if loading strategy is set to ol.loadingstrategy.tile\r\n\r\nThanks :-)"},"comment":{"url":"https://api.github.com/repos/openlayers/ol3/issues/comments/218296580","html_url":"https://github.com/openlayers/ol3/issues/5325#issuecomment-218296580","issue_url":"https://api.github.com/repos/openlayers/ol3/issues/5325","id":218296580,"user":{"login":"jan-tosovsky-cz","id":3907898,"avatar_url":"https://avatars.githubusercontent.com/u/3907898?v=3","gravatar_id":"","url":"https://api.github.com/users/jan-tosovsky-cz","html_url":"https://github.com/jan-tosovsky-cz","followers_url":"https://api.github.com/users/jan-tosovsky-cz/followers","following_url":"https://api.github.com/users/jan-tosovsky-cz/following{/other_user}","gists_url":"https://api.github.com/users/jan-tosovsky-cz/gists{/gist_id}","starred_url":"https://api.github.com/users/jan-tosovsky-cz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jan-tosovsky-cz/subscriptions","organizations_url":"https://api.github.com/users/jan-tosovsky-cz/orgs","repos_url":"https://api.github.com/users/jan-tosovsky-cz/repos","events_url":"https://api.github.com/users/jan-tosovsky-cz/events{/privacy}","received_events_url":"https://api.github.com/users/jan-tosovsky-cz/received_events","type":"User","site_admin":false},"created_at":"2016-05-10T21:25:39Z","updated_at":"2016-05-10T21:25:39Z","body":"Hmm, an ideal entry point seems to be customized `ol.featureloader.xhr` loader, especiallly that inner `loadFeaturesXhr()` method with success/failure function params. If those could be customized to increase my global counter (or trigger new `tileloadend`/`tileloaderror` events), it would be nice. \r\n```javascript\r\nol.featureloader.xhr = function(url, format) {\r\n  return ol.featureloader.loadFeaturesXhr(url, format,\r\n      /**\r\n       * @param {Array.<ol.Feature>} features The loaded features.\r\n       * @param {ol.proj.Projection} dataProjection Data projection.\r\n       * @this {ol.source.Vector}\r\n       */\r\n      function(features, dataProjection) {\r\n        this.addFeatures(features);\r\n      }, /* FIXME handle error */ ol.nullFunction);\r\n};\r\n```\r\nBut that `loadFeaturesXhr()` method seems to be private and cannot be used as intended, see the commented code:\r\n```javascript\r\nvar vectorSource = new ol.source.Vector({\r\n   loader: ol.featureloader.xhrX(url, format),\r\n   strategy: ol.loadingstrategy.tile(tileGrid)\r\n});\r\n\r\n// forked method, but the inner 'loadFeaturesXhr' method seems to be private and cannot be used \r\nol.featureloader.xhrX = function(url, format) {\r\n   /*\r\n      return ol.featureloader.loadFeaturesXhr(url, format,\r\n         function(features, dataProjection) {\r\n            this.addFeatures(features);\r\n            // when tile loading succeeds\r\n            tilesLoaded++;\r\n         },\r\n         function() {\r\n            // when tile loading fails\r\n            tilesLoaded++;\r\n         });\r\n   */\r\n   // just returning the original loader\r\n   return ol.featureloader.xhr(url, format);\r\n}\r\n```\r\nWould that loadFeaturesXhr() method become public? I'd like to avoid touching the original OL3 sources and I can't see any other place where to count loaded tiles.\r\n\r\nBtw, the total count of tiles to load can be determined in the custom url function:\r\n```javascript\r\nvar url = function(extent, resolution) {\r\n   tilesToLoad++; // when a new tile is needed, this counter is incremented\r\n   var tileCoord = tileGrid.getTileCoordForCoordAndResolution(ol.extent.getCenter(extent), resolution);\r\n   return 'tiles/' +\r\n      tileCoord[0] + '/' +\r\n      tileCoord[1] + '/' +\r\n      (Math.pow(2, tileCoord[0]) + tileCoord[2]) + '.json';\r\n}\r\n```"}}