📜 ⬆️ ⬇️

Yandeks.Probki: get the area covered with traffic jams + alternative cork gadget

Not so long ago, Yandex began to give data on traffic jams for a large number of other regions, except for Moscow, St. Petersburg, Kiev and Yekaterinburg. How to place a layer with traffic jams on my map I wrote earlier. Today we will understand how you can get a list of regions in which traffic jams are processed.

Yandex.Prob, along with trf.maps.yandex.net/trf/stat.js , also has trf.maps.yandex.net/trf/coverage.js . This script tells us which regions are covered with traffic data (or at least this information is supported).


YMaps.TrafficLoader.onLoad(
"coverage" ,
{
regions: ( function (){
function p(x,y){
return new YMaps.GeoPoint(x,y);
}
function b(l,b,r,t){
return new YMaps.GeoBounds(p(l,b),p(r,t));
}
return [
{
name: " " ,
regionId: "1" ,
view:{
point:p(37.620070,55.753630),
boundedBy:b(36.61977492,55.3105725984,38.35467432,56.4313303008)
},
boundedBy:b(35.14318524,54.2560801359,40.20433848,56.9613240948)
}
];
})()
}
);


* This source code was highlighted with Source Code Highlighter .

')
If you do all the transformations that are performed, the following object is obtained at the input:

return {
regions: [
{
name: " " ,
regionId: "1" ,
view:{
point: YMaps.GeoPoint(37.620070,55.753630),
boundedBy: YMaps.GeoBounds(36.61977492,55.3105725984,38.35467432,56.4313303008)
},
boundedBy: YMaps.GeoBounds(35.14318524,54.2560801359,40.20433848,56.9613240948)
}
];
}


* This source code was highlighted with Source Code Highlighter .


YMaps.TrafficLoader is used again. The data comes in the form of an object with a regions field that contains an array of objects. Each object has the same set of fields:

According to the results of "research", I made Windows Sidebar Widgets with traffic jams in any city that is now supported by Yandex. Not as cool as the original, but it allows you to view the map directly in the widget without opening the site itself.
Download the widget for Windows Sidebar "Other Yandex.Probki"

Source: https://habr.com/ru/post/87294/


All Articles