Материал из SamaraTrans.
| Версия 12:22, 10 августа 2009 (править) Buslov Anton (Обсуждение | вклад) ← К предыдущему изменению |
Версия 12:23, 10 августа 2009 (править) (отменить) Buslov Anton (Обсуждение | вклад) К следующему изменению → |
||
| Строка 7: | Строка 7: | ||
| - | + | <script type="text/javascript"> | |
| - | + | function TextualZoomControl () { | |
| - | + | this.element = document.createElement("DIV"); | |
| - | + | this.element.style.position = 'absolute'; | |
| - | + | this.element.style.zIndex = '1000'; | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | this. | + | |
| - | + | ||
| - | this. | + | |
| - | + | ||
| - | + | ||
| } | } | ||
| - | }); | ||
| - | + | TextualZoomControl.prototype = { | |
| - | + | onAddToMap: function (map, position) { | |
| - | + | this.map = map; | |
| - | } | + | this.position = position || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT, new YMaps.Size(5, 30)); |
| - | </script> | + | this._init(); |
| + | }, | ||
| + | |||
| + | onRemoveFromMap: function () { | ||
| + | if (this.element.parentNode) { | ||
| + | this.map.getContainer().removeChild(this.element); | ||
| + | } | ||
| + | this.map = null; | ||
| + | }, | ||
| + | |||
| + | _init: function (map) { | ||
| + | var zoomInDiv = document.createElement("div"), | ||
| + | zoomOutDiv = document.createElement("div"), | ||
| + | _this = this; | ||
| + | |||
| + | this._setButtonStyle(zoomInDiv); | ||
| + | this.element.appendChild(zoomInDiv); | ||
| + | zoomInDiv.appendChild(document.createTextNode("zoom in")); | ||
| + | |||
| + | zoomInDiv.onclick = function () { | ||
| + | _this.map.setZoom(_this.map.getZoom() + 1); | ||
| + | }; | ||
| + | |||
| + | this._setButtonStyle(zoomOutDiv); | ||
| + | this.element.appendChild(zoomOutDiv); | ||
| + | zoomOutDiv.appendChild(document.createTextNode("zoom out")); | ||
| + | |||
| + | zoomOutDiv.onclick = function () { | ||
| + | _this.map.setZoom(_this.map.getZoom() - 1); | ||
| + | }; | ||
| + | |||
| + | this.position.apply(this.element); | ||
| + | this.map.getContainer().appendChild(this.element); | ||
| + | }, | ||
| + | |||
| + | _setButtonStyle: function (button) { | ||
| + | style = {textDecoration: 'underline', | ||
| + | color: '#000000', | ||
| + | backgroundColor: 'white', | ||
| + | font: 'small Arial', | ||
| + | border: '1px solid green', | ||
| + | padding: '2px', | ||
| + | marginBottom: '3px', | ||
| + | textAlign: 'center', | ||
| + | width: '6em', | ||
| + | cursor: 'pointer'}; | ||
| + | for (var k in style) { | ||
| + | button.style[k] = style[k]; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | var map, geoResult; | ||
| + | |||
| + | window.onload = function () { | ||
| + | map = new YMaps.Map(document.getElementById("YMapsID")); | ||
| + | // map.setCenter(new YMaps.GeoPoint(50.222095,53.262299), 10); | ||
| + | map.setCenter(new YMaps.GeoPoint(50.222095,53.262299), 11); | ||
| + | map.addControl(new YMaps.TypeControl()); | ||
| + | map.addControl(new YMaps.Zoom()); | ||
| + | map.enableHotKeys(); | ||
| + | map.enableScrollZoom(); | ||
| + | showAddress(document.getElementById('address').value); | ||
| + | } | ||
| + | |||
| + | function showAddress (value) { | ||
| + | map.removeOverlay(geoResult); | ||
| + | // alert(value); | ||
| + | if (!value) value='Самара '+value; | ||
| + | // value={$address}{literal}; | ||
| + | |||
| + | |||
| + | |||
| + | var geocoder = new YMaps.Geocoder(value, {results: 1, boundedBy: map.getBounds()}); | ||
| + | |||
| + | YMaps.Events.observe(geocoder, geocoder.Events.Load, function () { | ||
| + | if (this.length()) { | ||
| + | geoResult = this.get(0); | ||
| + | map.addOverlay(geoResult); | ||
| + | map.setBounds(geoResult.getBounds()); | ||
| + | }else { | ||
| + | alert("Ничего не найдено") | ||
| + | } | ||
| + | }); | ||
| + | // address.value=value; | ||
| + | } | ||
| + | </script> | ||
| + | |||
| + | |||
| </head> | </head> | ||
| <body> | <body> | ||
Версия 12:23, 10 августа 2009
