Вход Регистрация
Файл: plugins/google_map_location/static/js/location.js
Строк: 261
<?php
var PEEP_GoogleMapLocation = function ($, google)
{

    return function (
fieldNameaddressFieldIdmapElementId)
    {
        var 
self this;

        var 
geocoder;
        var 
map;
        var 
marker;
        var 
mapElement = $("#" mapElementId);
        var 
bounds;

        var 
fieldId addressFieldId;
        var 
mapElementId mapElementId;
        var 
zoom 9;

        var 
latitudeField;
        var 
longitudeField;
        var 
northEastLat;
        var 
northEastLng;
        var 
southWestLat;
        var 
southWestLng;
        var 
addressField;
        var 
jsonField;

        var 
countryRestriction '';
        var 
removeValue;
        var 
region;
        var 
customMarkerIcon;
        
        var 
mapOptions = {
                    
mapTypeIdgoogle.maps.MapTypeId.ROADMAP,
                    
disableDefaultUIfalse,
                    
draggablefalse,
                    
mapTypeControlfalse,
                    
overviewMapControlfalse,
                    
panControlfalse,
                    
rotateControlfalse,
                    
scaleControlfalse,
                    
scrollwheelfalse,
                    
streetViewControlfalse,
                    
zoomControlfalse
                
};

        
this.isValidValue false;

        
this.initialize = function (params)
        {
            var 
lat params['lat'];
            var 
lng params['lng'];
            var 
northEastLat params['northEastLat'];
            var 
northEastLng params['northEastLng'];
            var 
southWestLat params['southWestLat'];
            var 
southWestLng params['southWestLng'];
            
            if ( 
params['customMarkerIcon'] )
            {
                
customMarkerIcon params['customMarkerIcon'];
            }
            
            
region params['region'];

            
geocoder = new google.maps.Geocoder();

            if (
lat || lng)
            {
                
this.isValidValue true;

                var 
latlng = new google.maps.LatLng(latlng);

                
mapElement.show();

                
map = new window.PEEP_GoogleMap(mapElementId);
                
map.initialize(mapOptions);
                
map.setCenter(latlng);
                

                var 
northEast null;
                if (
northEastLat || northEastLng)
                {
                    
northEast = new google.maps.LatLng(northEastLatnorthEastLng);
                }

                var 
southWest null;
                if (
southWestLat || southWestLng)
                {
                    
southWest = new google.maps.LatLng(southWestLatsouthWestLng);
                }

                if (
northEast && southWest)
                {
                    var 
bounds = new google.maps.LatLngBounds(southWestnorthEast);
                    
map.fitBounds(bounds);
                }
                
                if (
latlng)
                {
                    
map.addPoint(latlngnullnullnullcustomMarkerIcon);
                    
map.createMarkerCluster();
                }
            }

            $(
"#" fieldId "_delete_icon").click(function () {
                
self.deleteValue();
            });

            
countryRestriction params['countryRestriction'];
        }

        $(function () {

            
latitudeField = $('input[name="' fieldName '[latitude]"]');
            
longitudeField = $('input[name="' fieldName '[longitude]"]');
            
northEastLat = $('input[name="' fieldName '[northEastLat]"]');
            
northEastLng = $('input[name="' fieldName '[northEastLng]"]');
            
southWestLat = $('input[name="' fieldName '[southWestLat]"]');
            
southWestLng = $('input[name="' fieldName '[southWestLng]"]');
            
addressField = $('input[name="' fieldName '[address]"]');
            
jsonField = $('input[name="' fieldName '[json]"]');
            
removeValue = $('input[name="' fieldName '[remove]"]');

            if (
jsonField.val())
            {
                
self.isValidValue true;
            }

            
PEEP_GoogleMapLocationAutocomplete(fieldId, {
                
delay250,
                
matchContainstrue,

                
source: function (requestresponse) {

                    var 
icon = $('#' fieldId '_icon');
                    
icon.removeClass('ic_googlemap_pin');
                    
icon.addClass('peep_inprogress');

                    var 
geocoderParams = {
                        
'address'request.term
                    
}

                    if (
countryRestriction)
                    {
                        
geocoderParams.componentRestrictions = {countrycountryRestriction};
                    }
                    
                    if (
region)
                    {
                        
geocoderParams.region region;
                    }

                    
geocoder.geocode(geocoderParams, function (resultsstatus) {

                        
icon.removeClass('peep_inprogress');
                        
icon.addClass('ic_googlemap_pin');
                        
                        
response($.map(results, function (item) {
                                    return {
                                        
labelitem.formatted_address,
                                        
valueitem.formatted_address,
                                        
latitudeitem.geometry.location.lat(),
                                        
longitudeitem.geometry.location.lng(),
                                        
resultitem
                                    
}
                        }));
                    })
                },
                
select: function (eventui) {

                    
mapElement.show();

                    
self.setValue(ui.item.result)
                    
self.isValidValue true;
                }
            });
        });


        
this.setValue = function (item)
        {
            var 
location item.geometry.location;

            
self.showDeleteIcon();
            
            if (!
map)
            {
                
map = new window.PEEP_GoogleMap(mapElementId);
                
map.initialize(mapOptions);
            }
            
            var 
sw = new google.maps.LatLng(item.geometry.viewport.getSouthWest().lat(),item.geometry.viewport.getSouthWest().lng());
            var 
ne = new google.maps.LatLng(item.geometry.viewport.getNorthEast().lat(),item.geometry.viewport.getNorthEast().lng());

            var 
bounds = new google.maps.LatLngBounds(swne);
            
            
map.removeAllPoints();
            
map.setCenter(item.geometry.location.lat(), item.geometry.location.lng());
            
map.addPoint(item.geometry.location.lat(), item.geometry.location.lng(), nullnullnullcustomMarkerIcon);
            
map.fitBounds(bounds);
            
map.createMarkerCluster();
            
            
addressField.val(item.formatted_address);
            
longitudeField.val(item.geometry.location.lng());
            
latitudeField.val(item.geometry.location.lat());
            
northEastLat.val(item.geometry.viewport.getNorthEast().lat())
            
northEastLng.val(item.geometry.viewport.getNorthEast().lng())
            
southWestLat.val(item.geometry.viewport.getSouthWest().lat())
            
southWestLng.val(item.geometry.viewport.getSouthWest().lng())
            
removeValue.val(false);

            
jsonField.val(JSON.stringify(item).replace('"''"'));
            
self.isValidValue true;
        }

        
this.showDeleteIcon = function (item)
        {
            $(
"#" mapElementId).show();
            $(
"#" fieldId "_icon").hide();
            $(
"#" fieldId "_delete_icon").css("display""inline");
        }

        
this.hideDeleteIcon = function (item)
        {
            $(
"#" mapElementId).hide();
            $(
"#" fieldId "_icon").show();
            $(
"#" fieldId "_delete_icon").hide();
        }

        
this.deleteValue = function (item)
        {
            
self.hideDeleteIcon();

            $(
'#' fieldId).val('');
            
addressField.val('');
            
longitudeField.val('');
            
latitudeField.val('');
            
northEastLat.val('');
            
northEastLng.val('');
            
southWestLat.val('');
            
southWestLng.val('');
            
removeValue.val(true);

            
jsonField.val('');
            
self.isValidValue false;
        }

        
//        google.maps.event.addListener(marker, 'drag', function() {
        //            geocoder.geocode({
        //                'latLng': marker.getPosition()
        //                }, function(results, status) {
        //                if (status == google.maps.GeocoderStatus.OK) {
        //                    if (results[0]) {
        //                        $(fieldId).val(results[0].formatted_address);
        //                        //$('#latitude').val(marker.getPosition().lat());
        //                        //$('#longitude').val(marker.getPosition().lng());
        //                    }
        //                }
        //            });
        //        });


    
}
}(
locationJqueygoogle)
?>
Онлайн: 0
Реклама