// --------------------------------------------------------- // VSearchWidget class // Плагин для реализации поиска. // --------------------------------------------------------- VSearchWidget.prototype._width = null; VSearchWidget.prototype._height = null; VSearchWidget.prototype._visible = false; /** HTMLelement. */ VSearchWidget.prototype._div; VSearchWidget.prototype._box_fields; VSearchWidget.prototype._hint; VSearchWidget.prototype._address; VSearchWidget.prototype._submit_button; VSearchWidget.prototype._results; VSearchWidget.prototype._layer; VSearchWidget.prototype._marker; /** * @category = Plugins * @class * Плагин для реализации поиска. Отображает поисковую форму. * @params {HTMElement} div html элемент div, в котором будет отображаться поисковая форма. * @constructor */ function VSearchWidget(div) { this._div = div; this.init(); _VISICOM_SearchWidget_layer = new VLayer(); mapEngine.addLayer(_VISICOM_SearchWidget_layer); } /** * Инициализация. */ VSearchWidget.prototype.init = function() { this._width = this._div.offsetWidth; this._height = this._div.offsetHeight; if (this._width < 200) this._width = 200; if (this._height < 80) this._height = 80; var me = this; this._div.style.margin = '0px'; this._div.style.padding = '0px'; this._div.style.position = 'relative'; this._div.style.zIndex = '102'; this._div.style.width = this._width + 'px'; this._div.style.height = this._height + 'px'; //this._div.style.border = '1px solid #acbedf'; // Подсказка this._hint = document.createElement('div'); this._hint.style.fontSize = '12px'; this._hint.style.fontFamily = 'Verdana'; this._hint.style.fontWeight = 'bold'; //this._hint.style.color = '#34547C'; this._hint.style.padding = '0px'; this._hint.style.position = 'relative'; this._hint.style.width = this._width + 'px'; this._hint.style.height = '20px'; this._hint.innerHTML = MSG_SEARCH_ADDRESS; //this._hint.style.border = '1px dashed #acbedf'; // Область для контролов this._box_fields = document.createElement('div'); //this._box_fields.style.margin = '10px 0px 0px 21px'; this._box_fields.style.padding = '0px'; this._box_fields.style.width = this._width + 'px'; this._box_fields.style.height = '50px'; //this._box_fields.style.border = '1px dashed #acbedf'; // Адрес this._address = document.createElement('input'); this._address.id = 'address'; this._address.onkeypress = function(e) { var keynum; if (window.event) { keynum = window.event.keyCode; } else if(e.which) { keynum = e.which; } // Проверка на нажатие клавиши "Enter" if (keynum != 13) return; me._goSearch(); } //this._address.style.border = '1px solid #acbedf'; this._address.style.background = 'url(http://maps.visicom.ua/images/background_field.gif) repeat-x left top'; this._address.style.fontSize = '12px'; this._address.style.fontFamily = 'Verdana'; this._address.style.marginRight = '3px'; //this._address.style.color = 'gray'; this._address.style.width = (this._width - 75) + 'px'; this._address.style.height = '19px'; //this._address.style.verticalAlign = 'top'; // Кнопка "Поиск" this._submit_button = document.createElement('input'); this._submit_button.type = 'button'; this._submit_button.style.width = '70px'; this._submit_button.style.height = '21px'; this._submit_button.value = 'Найти'; this._submit_button.onclick = function(e) { me._goSearch(); } // Результаты this._results = document.createElement('div'); this._results.id = 'results'; this._results.style.fontSize = '12px'; this._results.style.fontFamily = 'Verdana'; //this._results.style.lineHeight = '140%'; this._results.style.overflow = 'auto'; //this._results.style.color = 'black'; //this._results.style.margin = '20px 0px 0px 21px'; this._results.style.padding = '0px'; this._results.style.width = this._width + 'px'; this._results.style.height = (this._height - 60) + 'px'; this._box_fields.appendChild(this._hint); this._box_fields.appendChild(this._address); this._box_fields.appendChild(this._submit_button); } /** * Поиск */ VSearchWidget.prototype._goSearch = function() { _VISICOM_search_moment_id = Math.random(); _VISICOM_findSemantic(); } /** * @public * Отображает форму. */ VSearchWidget.prototype.show = function() { if (this._visible) return; this._div.appendChild(this._box_fields); this._div.appendChild(this._results); mapEngine.resizeViewport(); } /** * @public * Скрывает форму. */ VSearchWidget.prototype.hide = function() { if (!this._visible) return; this._div.removeChild(this._box_fields); this._div.removeChild(this._results); mapEngine.resizeViewport(); } var _VISICOM_search_moment_id = null; var _VISICOM_SearchWidget_layer = null; var _VISICOM_SearchWidget_marker = null; /** * Поиск по адресной строке. */ function _VISICOM_findSemantic() { var _search_moment_id = _VISICOM_search_moment_id; var address = document.getElementById("address").value; var resultDiv = document.getElementById('results'); if (address.length < 3) { // Сообщение "Введите более 2-х символов..." resultDiv.innerHTML = '
' + MSG_MORE_2 + '
'; return; } // Разбор адресной строки var words = address.split(" "); var settlement = undefined; var street = undefined; var building = undefined; var regexNumber = /^\d+\/?\d*[А|а|Б|б|В|в|Г|г|Д|д|Е|е]?$/i; if (words[2] == undefined) { if (regexNumber.exec(words[1]) == null) { settlement = words[0]; street = words[1]; } else { street = words[0]; building = words[1]; } } else { settlement = words[0]; street = words[1]; if (regexNumber.exec(words[2]) != null) building = words[2]; } // Сообщение "Подождите..." resultDiv.innerHTML = '
' + MSG_PLEASE_WAIT + '
'; var remoteRequest = new VRemoteRequest(); remoteRequest.request(VISICOM_API_URL + 'RemoteSemantic?' + ((settlement != undefined) ? 'settlement=' + encodeURI(settlement) : '') + ((street != undefined) ? '&street=' + encodeURI(street) : '') + ((building != undefined) ? '&building=' + encodeURI(building) : ''), function(data) { if (_search_moment_id != _VISICOM_search_moment_id) return; if (data != null) resultDiv.innerHTML = data; else resultDiv.innerHTML = MSG_NOT_FOUND; } ); } /** * Отображение объекта по его ID. */ function _VISICOM_showObject(object_id) { // Получение прямоугольника видимости var remoteRequest = new VRemoteRequest(); remoteRequest.request(VISICOM_API_URL + 'RemoteMBR?function=getMBR&objectID=' + object_id, function(data) { var myObject = eval('(' + data + ')'); if (myObject == null) return; var bounds = new VBounds(new VPoint(myObject.min_x, myObject.min_y), new VPoint(myObject.max_x, myObject.max_y)); var array = myObject.points; if (array == null) return; if (array[0] == null) return; var point = new VPoint(array[0].x_center, array[0].y_center); if (_VISICOM_SearchWidget_marker == null) { _VISICOM_SearchWidget_marker = new VMarker(point); _VISICOM_SearchWidget_layer.addMarker(_VISICOM_SearchWidget_marker); } else _VISICOM_SearchWidget_marker.setPoint(point); var currentBounds = mapEngine.getClientRect(); var zoomIndex = mapEngine.getMinimalZoomForBounds(bounds); if (currentBounds.containsPoint(point) && mapEngine.getZoomIndex() == zoomIndex) { mapEngine.panTo(point); } else { mapEngine.setCenter(point, zoomIndex); } mapEngine.repaintMap(); } ); } /** * Загрузка перечня домов. */ function _VISICOM_loadBuildings(settlement_id, street_id) { var remoteRequest = new VRemoteRequest(); remoteRequest.request(VISICOM_API_URL + 'RemoteBuilding?stl_id=' + settlement_id + '&str_id=' + street_id, function(data) { var resultDiv = document.getElementById('s' + settlement_id + street_id); eval(data); resultDiv.innerHTML = '
' + buildings + '
'; } ); }