Support

Account

Home Forums Feature Requests Specify zoom in google map field Reply To: Specify zoom in google map field

  • For a project i need to save the zoom of a google map field.
    So i do this :

    In core/fields/google-map.php
    I added in create_field :

    $field['value'] = wp_parse_args($field['value'], array(
    	'address'	=> '',
    	'lat'		=> '',
    	'lng'		=> '',
    	'zoom'		=> ''
    	));

    and

    $keys = array( 
    	'data-id'	=> 'id', 
    	'data-lat'	=> 'center_lat',
    	'data-lng'	=> 'center_lng',
    	'data-zoom'	=> 'zoom'
    	);

    And in js/input.js

    // value exists?
    	var lat = this.$el.find('.input-lat').val(),
    	    lng = this.$el.find('.input-lng').val(),
    	    zoom = parseInt(this.$el.find('.input-zoom').val());
    
    if( zoom )
    {
        this.map.setZoom(zoom);
    }

    and

    google.maps.event.addListener( this.map, 'zoom_changed', function( e ) {
    	// reference
    	var $el = this.$el;
    
    	var zoom = this.getZoom();
    
    	// update input
    	$el.find('.input-zoom').val( zoom ).trigger('change');
    	});

    And it works.
    Hope this help.