Не работают функции из Ymaps
Добрый день. Моя задача состит в том, что бы вывести объекты из сервиса Wialon(предоставляет геоданные, где в данный момент находится объект) на яндекс карты.
Собственно вот код: var map, marker, unitID, unitEventID, polyline, mapWaypts = []; // global variables // Print message to log function msg(text) { $("#log").prepend(text + "<br/>"); } function init() { // Execute after login succeed var sess = wialon.core.Session.getInstance(); // get instance of current Session // specify what kind of data should be returned var flags = wialon.item.Item.dataFlag.base; sess.loadLibrary("itemIcon"); // load Icon Library sess.updateDataFlags( // load items to current session [{type: "type", data: "avl_unit", flags: flags, mode: 0}], // items specification function (code) { // updateDataFlags callback if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code var units = sess.getItems("avl_unit"); // get loaded 'avl_resource's items if (!units || !units.length){ msg("No units found"); return; } // check if units found for (var i = 0; i< units.length; i++) // construct Select list using found resources $("#units").append("<option value='"+ units[i].getId() +"'>"+ units[i].getName()+ "</option>"); // bind action to select change event $("#units").change( showUnit ); }); } function showUnit(){ // show selected unit on map var val = $("#units").val(); // get selected unit id if (!val) return; // exit if no unit selected var sess = wialon.core.Session.getInstance(); // get instance of current Session // specify what kind of data should be returned var flags = wialon.item.Unit.dataFlag.lastMessage; var unit = null; if (unitID) { // check if we already have previous unit unit = sess.getItem(unitID); sess.updateDataFlags( // remove previous item from current session [{type: "id", data: unitID, flags: flags, mode: 2}], // item specification function(code) { if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } if (unitEventID) unit.removeListenerById(unitEventID); // unbinding event from this unit }); } unitID = val; unitEventID = null; // empty event ID mapWaypts = []; // remove all old checkpoints if they were here sess.updateDataFlags( // load item with necessary flags to current session [{type: "id", data: unitID, flags: flags, mode: 1}], // item specification function(code) { if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } unit = wialon.core.Session.getInstance().getItem(val); // get unit by id if(!unit) return; // exit if no unit var position = unit.getPosition(); // get unit position if (!position) return; // exit if no position if (map) { // check if map created and we can detect position of unit /*var s = new ymaps.Style(); s.iconStyle = new ymaps.IconStyle(); s.iconStyle.href = unit.getIconUrl(32); s.iconStyle.size = new ymaps.Point(32, 32); s.iconStyle.offset = new ymaps.Point(0, 0); */ if (!marker) { marker = new ymaps.Placemark(new ymaps.GeoPoint([position.y, position.x])); //marker = new ymaps.Placemark([position.y, position.x], {style: s}); } else { marker.setCoordPoint(new YMaps.GeoPoint([position.y, position.x])); } console.log(marker); map.setCenter([position.y, position.x], 10); map.addOverlay(marker); //if (polyline) polyline.setMap(null); // if there is alreday path of map - remove it //mapWaypts.push(latlon); // adding point to path array } msg("You chose unit: " + unit.getName()); unitEventID = unit.addListener("messageRegistered", showData); // register event when we will receive message }); } function showData(event) { var data = event.getData(); // get data from event if (!data.pos) return; // exit if no position var appended = ''; // here we will put all required information var position = { // get unit position x: data.pos.x, y: data.pos.y }; appended += "Position (x: " + data.pos.x + "; y: " + data.pos.y +")"; // printing position if (data.t) appended += ", time " + wialon.util.DateTime.formatTime(data.t, 1); // printing event time (return user time) msg(appended); // writing to log message about this event if (map) { // check if map created marker.setLatLng({lat: position.y, lng: position.x}); if (polyline) { polyline.addLatLng({lat: position.y, lng: position.x}); } map.setView({lat: position.y, lng: position.x}); } } function initMap() { // create a map in the "map" div, set the view to a given place and zoom map = new ymaps.Map("map", { center: [52.518593,13.388685], zoom: 13}); } // execute when DOM ready $(document).ready(function () { wialon.core.Session.getInstance().initSession("https://hst-api.wialon.com"); // init session wialon.core.Session.getInstance().login("b3test_en", "test", "", // try to login function (code) { // login callback // if error code - print error message if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } msg("Logged successfully"); ymaps.ready(initMap); //initMap(); init(); // when login suceed then run init() function }); }); Проблема в том, что почти ни одна функция ymaps не работает, конкретно пишется ошибка "Uncaught TypeError: undefined is not a function ". Если же я вызываю так Ymaps (с большой буквы), то выводит ошибку "Uncaught ReferenceError: Ymaps is not defined " Апи карт подключаю полную. Кто-нибудь, может мне подсказать как исправить данную проблему? |
ymaps == undefined (т.е. не объявлена)
Наверно нужна какая то магия для того что бы ymaps стала функцией например подключить какую нибудь библиотеку до того как начинаешь пользоваться это библиотекой |
Такая же проблема
Добрый день! Точно такая же проблема!!! Можете написать получилось ли у Вас решить данную проблему?
|
Часовой пояс GMT +3, время: 13:47. |