//файл var map = false; var geoResult; var mas_point_add_to_maps = new Array(); var drag_placemark = false; var go_function_begin_init_maps = false; var go_function_end_init_maps = false; var s_name_form_bind_maps = ""; var open_first_point_maps = false; var set_zoom_maps_point = false; var mas_point_maps = []; function init_google_maps() { set_longitude_google_maps=s_longitude_google_maps; set_latitude_google_maps=s_latitude_google_maps; set_zoom_google_maps=s_zoom_google_maps; if ( go_function_begin_init_maps ) { go_function_begin_init_maps(); } var latlng = new google.maps.LatLng(set_latitude_google_maps, set_longitude_google_maps); var myOptions = { zoom: set_zoom_google_maps, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, scrollwheel: false, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE } }; map = new google.maps.Map(document.getElementById("maps_canvas"), myOptions); if ( go_function_end_init_maps ) { go_function_end_init_maps(); } /* map = new YMaps.Map(document.getElementById("YMapsID")); set_longitude_yandex_maps=s_longitude_yandex_maps; set_latitude_yandex_maps=s_latitude_yandex_maps; set_zoom_yandex_maps=s_zoom_yandex_maps; if ( go_function_begin_init_maps ) { go_function_begin_init_maps(); } map.setCenter(new YMaps.GeoPoint(set_longitude_yandex_maps, set_latitude_yandex_maps), set_zoom_yandex_maps);// долгота, широта | longitude - долгота, latitude - широта map.setType(YMaps.MapType.MAP);//MAP , SATELLITE , HYBRID map.addControl(new YMaps.TypeControl()); //тип карты //map.addControl(new YMaps.ToolBar()); //панель инструментов map.addControl(new YMaps.Zoom()); //масштабирование //map.addControl(new YMaps.MiniMap()); //обзорная карта //map.addControl(new YMaps.ScaleLine()); //масштабная линейка if ( go_function_end_init_maps ) { go_function_end_init_maps(); } */ } function on_show_box_maps() { on_show_google_maps(); } function on_hide_box_maps() { on_hide_google_maps(); } function on_show_google_maps() { document.getElementById("box_maps_canvas").style.display = "block"; init_google_maps(); } function on_hide_google_maps() { document.getElementById("box_maps_canvas").style.display = "none"; drag_placemark = false; if ( map ) { //map.destructor(); //map = false; } } function set_init_maps_drag_point_maps() { obj_form_create = document.forms[s_name_form_bind_maps]; var form_lng_geo = parseFloat(obj_form_create.longitude.value); var form_lat_geo = parseFloat(obj_form_create.latitude.value); if ( form_lng_geo && form_lat_geo ) { set_longitude_google_maps=form_lng_geo; set_latitude_google_maps=form_lat_geo; //set_zoom_yandex_maps=zoom_yandex_maps; //alert(set_longitude_yandex_maps + " " + set_latitude_yandex_maps); } } function set_drag_point_maps() { var obj_form_create = document.forms[s_name_form_bind_maps]; var start_longitude_google_maps = s_longitude_google_maps; var start_latitude_google_maps = s_latitude_google_maps; var form_lng_geo = parseFloat(obj_form_create.longitude.value); var form_lat_geo = parseFloat(obj_form_create.latitude.value); /* YMaps.Events.observe(map,map.Events.Click, function (obj,mEvent) { //alert(mEvent.getGeoPoint()); create_drag_placemark(1,1,mEvent.getGeoPoint()); }); */ google.maps.event.addListener(map, "click", function (e){ create_drag_placemark( 1, 1, e.latLng) }); if ( form_lng_geo && form_lat_geo ) { start_longitude_google_maps = form_lng_geo; start_latitude_google_maps = form_lat_geo; //alert(form_lng_geo + " " + form_lat_geo); create_drag_placemark(start_longitude_google_maps,start_latitude_google_maps,false); } } function create_drag_placemark(longitude,latitude,geoPoint) { obj_form_create = document.forms[s_name_form_bind_maps]; var setPointPlacemark = false; if ( geoPoint ) { setPointPlacemark = geoPoint; longitude = geoPoint.lng();//alert(latlng.lat() + " " + latlng.lng()); latitude = geoPoint.lat(); } else { setPointPlacemark = new google.maps.LatLng(latitude, longitude); } if ( drag_placemark ) { //alert("уже есть метка!"); drag_placemark.setPosition(setPointPlacemark); } else { drag_placemark = new google.maps.Marker( { "position" : setPointPlacemark, "title" : "Перетащите эту метку в нужное место", draggable:true, "map" : map } ); } obj_form_create.longitude.value=longitude; obj_form_create.latitude.value=latitude; google.maps.event.addListener(drag_placemark, 'drag', function(e) { var GeoKoor = e.latLng; //alert(GeoKoor.lng()); //alert(GeoKoor.lat()); obj_form_create.longitude.value=GeoKoor.lng(); obj_form_create.latitude.value=GeoKoor.lat(); }); } function set_mas_point_to_maps() { //должен быть определен массив точек mas_point_maps var n,one_point, title, marker, infowindow; for (n=0;n < mas_point_maps.length; n++ ) { one_point = mas_point_maps[n]; if ( !one_point["lng"] || !one_point["lat"] ) continue; title = decodeURIComponent(one_point["name"]); marker = new google.maps.Marker( { "position" : new google.maps.LatLng( one_point["lat"], one_point["lng"]), "title" : title, "map" : map } ); //marker.setMap(map); infowindow = new google.maps.InfoWindow( { content: "
"+ title+"
" }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); //var short_description =decodeURIComponent(one_point["short_description"]); //placemark.description = ""; mas_point_add_to_maps[mas_point_add_to_maps.length] = { "marker" : marker, "infowindow" : infowindow }; } if ( typeof( open_first_point_maps ) != "undefined" && open_first_point_maps && mas_point_add_to_maps.length > 0 ) { //mas_point_add_to_maps[0].openBalloon(); /* mas_point_add_to_maps[0]["infowindow"].open(map,mas_point_add_to_maps[0]["marker"]); google.maps.event.addListener(map, 'zoom_changed', function() { var zoomLevel = map.getZoom(); //map.setCenter(myLatLng); infowindow.setContent('Zoom: ' + zoomLevel); }); */ //open_num_mas_point_to_maps( 0, false ); } } function set_init_maps_mas_point_maps() { if ( typeof( set_zoom_maps_point ) != "undefined" ) { set_zoom_google_maps=s_zoom_google_maps_point; } //должен быть определен массив точек mas_point_maps, центрирование карты будет по первой точке if ( mas_point_maps && mas_point_maps.length > 0 ) { var lng_geo = mas_point_maps[0]["lng"]; var lat_geo = mas_point_maps[0]["lat"]; if ( lng_geo && lat_geo ) { set_longitude_google_maps=lng_geo; set_latitude_google_maps=lat_geo; //set_zoom_yandex_maps=zoom_yandex_maps; //alert(set_longitude_yandex_maps + " " + set_latitude_yandex_maps); } } } function open_num_mas_point_to_maps( num_i, on_scrool_map ) { if ( typeof( on_scrool_map ) == "undefined" ) on_scrool_map = true; if ( mas_point_add_to_maps && typeof( mas_point_add_to_maps[num_i] ) != "undefined" ) { var marker = mas_point_add_to_maps[num_i]["marker"]; var infowindow = mas_point_add_to_maps[num_i]["infowindow"]; infowindow.open(map,marker); if ( on_scrool_map && document.getElementById("maps_canvas") ) { document.getElementById("maps_canvas").scrollIntoView(true); //document.getElementById("YMapsID").scrollBy(-5,0); window.scrollBy(0,-7); } } } function showAddress (address) { var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); create_drag_placemark(1,1, results[0].geometry.location); } else { alert("По запросу ничего не найдено!"); } }); }