traffic_control.js
| 2.7 KB | Satir:
0
| js
Geri
ymaps.ready(init); function init () { var //geolocation = ymaps.geolocation, myMap = new ymaps.Map('map', { center: [$("#enlem").html(), $("#boylam").html()], zoom: 12, controls: ['smallMapDefaultSet'] }, { searchControlProvider: 'yandex#search' }); // Creating an instance of the ymaps.control.SearchControl class. mySearchControl = new ymaps.control.SearchControl({ options: { noPlacemark: true } }), // The search results will be placed in the collection. mySearchResults = new ymaps.GeoObjectCollection(null, { hintContentLayout: ymaps.templateLayoutFactory.createClass('$[properties.name]') }); myMap.controls.add(mySearchControl); myMap.geoObjects.add(mySearchResults); // When the found object is clicked, the placemark turns red. mySearchResults.events.add('click', function (e) { e.get('target').options.set('preset', 'islands#redIcon'); }); // Putting the selected result in the collection. mySearchControl.events.add('resultselect', function (e) { var index = e.get('index'); mySearchControl.getResult(index).then(function (res) { mySearchResults.add(res); }); }).add('submit', function () { mySearchResults.removeAll(); }) // Creating the "Traffic" control. var trafficControl = new ymaps.control.TrafficControl({ state: { // Displaying traffic "Now". providerKey: 'traffic#actual', // Begin immediately showing traffic on the map. trafficShown: true }}); // Adding the control to the map. myMap.controls.add(trafficControl); // Getting a reference to the "Now" traffic provider and enabling the display of information points. trafficControl.getProvider('traffic#actual').state.set('infoLayerShown', true); /*geolocation.get({ provider: 'yandex', mapStateAutoApply: true }).then(function (result) { // We'll mark the position calculated by IP in red. result.geoObjects.options.set('preset', 'islands#redCircleIcon'); result.geoObjects.get(0).properties.set({ balloonContentBody: 'Şu anki konumunuz' }); myMap.geoObjects.add(result.geoObjects); }); geolocation.get({ provider: 'browser', mapStateAutoApply: true }).then(function (result) { /!** * We'll mark the position obtained through the browser in blue. * If the browser does not support this functionality, the placemark will not be added to the map. *!/ result.geoObjects.options.set('preset', 'islands#blueCircleIcon'); myMap.geoObjects.add(result.geoObjects); });*/ }
Kaydet
Ctrl+S ile kaydet