Plugin Directory

Changeset 1586515


Ignore:
Timestamp:
02/01/2017 01:34:24 PM (9 years ago)
Author:
ionutmorariu
Message:

ADD: google maps admin js init with center location

Location:
scale-lite-tools/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • scale-lite-tools/trunk/assets/js/admin.sl-maps.js

    r1577799 r1586515  
    1 console.log('it works');
     1function slt_gmaps_init() {
     2  var sl_preview_map = function() {
     3    var geocoder = new google.maps.Geocoder();
     4    // create map element
     5    var mapEl = document.getElementById("preview_map_container");
     6    var map = new google.maps.Map(mapEl, {
     7      zoom: 12,
     8      scrollwheel: false
     9    });
     10    function mapCreate(myLocation) {
     11      var marker = new google.maps.Marker({
     12        position: myLocation,
     13        map: map
     14      });
     15    }
     16    function codeAddress(callback) {
     17      var address = document.getElementById('center-map-location').value;
     18      (function(){
     19        geocoder.geocode( { 'address': address}, function(results, status) {
     20          if (status == 'OK') {
     21            map.setCenter(results[0].geometry.location);
     22            var marker = new google.maps.Marker({
     23                map: map,
     24                position: results[0].geometry.location
     25            });
     26            callback(results[0].geometry.location,map);
     27          } else {
     28            alert('Geocode was not successful for the following reason: ' + status);
     29          }
     30        });
     31      })();
     32    }
     33    codeAddress(function(myLocation) { mapCreate(myLocation, map);});
     34  };
     35  sl_preview_map();
     36  jQuery('#slt-preview').on('click', function() {
     37    sl_preview_map();
     38  });
     39}
  • scale-lite-tools/trunk/assets/js/frontend.sl-google-maps.js

    r1586045 r1586515  
    11// google maps render frontend map
    2 var sl_google_maps_frontend = function() {
     2var slt_gmaps_init = function() {
    33  "use strict";
    44
  • scale-lite-tools/trunk/inc/sl-google-maps/class-slt-gmap-meta-fields.php

    r1586471 r1586515  
    103103   */
    104104  public function add_meta_box_callback( $post ) {
    105     echo '<div class="preview_map_container"></div>';
     105    echo '<div id="preview_map_container" class="preview_map_container"></div>';
    106106    wp_nonce_field( 'slt_gmap_options_data', 'slt_gmap_options_nonce' );
    107107    $this->generate_fields( $post );
     
    137137          switch ( $field['id'] ) {
    138138            case 'center-map-location':
     139              if(empty($db_value)) {
     140                $db_value = '350 5th Ave, New York, NY 10118, USA';
     141              }
    139142              ($field['placeholder']) ? $field['placeholder']:'';
    140143              $input = sprintf(
    141144                '<div class="slt-map-address-container">
    142145                  <div class="slt-map-address">
    143                     <textarea placeholder="%s" class="large-text" id="%s" name="%s" rows="4">%s</textarea><p class="description">Paste here an address, then click preview map. If you only have one marker, map will be centered there. If you have multiple markers double click on preview map to update coordinates where your map will be centered.</p>
     146                    <textarea placeholder="%s" class="large-text" id="%s" name="%s" rows="4">%s</textarea><p class="description">Paste here your address, then click preview map. If you only have one marker, map will be centered there. If you have multiple markers double click on preview map to update coordinates where your map will be centered.</p>
    144147                  </div>
    145148                  <input name="slt-preview" type="button" class="button button-primary button-large" id="slt-preview" value="Preview map">
  • scale-lite-tools/trunk/inc/sl-google-maps/render-cpt.php

    r1586447 r1586515  
    164164add_action('wp_enqueue_scripts', 'scale_lite_load_gmaps_v3', 50 );
    165165
     166// Register Google maps JS v3 fro admin
     167function scale_lite_admin_load_gmaps_v3() {
     168  wp_enqueue_script(
     169    'scale-lite-admin-google-maps-js',
     170    "https://maps.googleapis.com/maps/api/js",
     171    array(),
     172    '',
     173    true
     174  );
     175}
     176add_action('admin_enqueue_scripts', 'scale_lite_admin_load_gmaps_v3', 50 );
     177
    166178// add async and defer attributs to google maps script google maps JS
    167179add_filter('clean_url','unclean_url',10,3);
     
    171183  if (false !== strpos($original_url, 'maps.googleapis.com/maps/api/js')){
    172184    remove_filter('clean_url','unclean_url',10,3);
    173     return wp_specialchars_decode($good_protocol_url).'?key='.$google_maps_api_key_0."&callback=slt_gmaps_frontend' async='async' defer='defer";
     185    return wp_specialchars_decode($good_protocol_url).'?key='.$google_maps_api_key_0."&callback=slt_gmaps_init' async='async' defer='defer";
    174186  }
    175187  return $good_protocol_url;
Note: See TracChangeset for help on using the changeset viewer.