%PDF- %PDF-
| Direktori : /home/bitrix/www/local/components/UB/main.profile.map/templates/.default/ |
| Current File : //home/bitrix/www/local/components/UB/main.profile.map/templates/.default/script.js |
if (typeof(BX.OrgMap) === "undefined")
{
BX.OrgMap = function()
{
this._orgMap;
this._placemark = false;
}
BX.OrgMap.prototype =
{
initialize: function()
{
this._orgMap = new ymaps.Map('map', {
center: [55.753994, 37.622093],
zoom: 9,
controls: ['smallMapDefaultSet']
});
mapConfigSrc = $('input#orgPlacemark').val();
if (mapConfigSrc.length>0) {
mapConfig = $.parseJSON(decodeURIComponent(mapConfigSrc));
this._placemark = this.createPlacemark(mapConfig['placemark']);
this._orgMap.geoObjects.add(this._placemark);
this._orgMap.panTo(this._placemark.geometry.getCoordinates());
this._orgMap.setBounds(mapConfig['bounds'], {
checkZoomRange: true
});
}
else this.findBuildingByAddress();
$('button#btnFindByAddress').click($.proxy(function(){
this.findBuildingByAddress();
},this));
this._orgMap.events.add('click', $.proxy(function (e) {
var coords = e.get('coords');
if (this._placemark) {
this._placemark.geometry.setCoordinates(coords);
}
else {
this._placemark = this.createPlacemark(coords);
this._orgMap.geoObjects.add(this._placemark);
this._placemark.events.add('dragend', $.proxy(function () {
this.saveMap();
},this));
}
this.saveMap();
},this));
$('form#form_main_profile_map').submit($.proxy(function(){
this.saveMap();
return true;
},this));
},
createPlacemark: function(coords)
{
return new ymaps.Placemark(coords, {
iconContent: ''
}, {
draggable: true
});
},
saveMap: function()
{
var mapConfig = {
'placemark': this._placemark.geometry.getCoordinates(),
'bounds' : this._orgMap.getBounds()
};
$('input#orgPlacemark').val(encodeURIComponent(JSON.stringify(mapConfig)));
},
getAddress: function ()
{
return $('input#orgRegion').val()+', '+$('input#orgAddress').val();
},
findBuildingByAddress: function(address)
{
ymaps.geocode(this.getAddress(), {
results: 1
}).then($.proxy(function (res) {
var firstGeoObject = res.geoObjects.get(0),
coords = firstGeoObject.geometry.getCoordinates(),
bounds = firstGeoObject.properties.get('boundedBy');
if (this._placemark)
this._placemark.geometry.setCoordinates(coords);
else {
this._placemark = this.createPlacemark(coords);
this._orgMap.geoObjects.add(this._placemark);
}
this._orgMap.setBounds(bounds, {
checkZoomRange: false
});
this.saveMap();
}, this));
},
}
BX.OrgMap.create = function (id, config)
{
var self = new BX.OrgMap();
self.initialize();
return self;
};
}
ymaps.ready(init);
function init() {
BX.OrgMap.create();
}