Plugin Directory

Changeset 1586624


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

CHG: build map array with values and fix error when map container does not exists

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

Legend:

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

    r1586608 r1586624  
    11function 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
     2  if(document.getElementById("preview_map_container")){
     3    var sl_preview_map = function() {
     4      var geocoder = new google.maps.Geocoder();
     5      // create map element
     6      var mapEl = document.getElementById("preview_map_container");
     7      var map = new google.maps.Map(mapEl, {
     8        zoom: 12,
     9        scrollwheel: false
     10      });
     11      function mapCreate(myLocation) {
     12        var marker = new google.maps.Marker({
     13          position: myLocation,
     14          map: map
     15        });
     16      }
     17      function codeAddress(callback) {
     18        var address = document.getElementById('center-map-location').value;
     19        (function(){
     20          geocoder.geocode( { 'address': address}, function(results, status) {
     21            if (status == 'OK') {
     22              map.setCenter(results[0].geometry.location);
     23              var marker = new google.maps.Marker({
     24                  map: map,
     25                  position: results[0].geometry.location
     26              });
     27              document.getElementById("slt-gmap-latitude").value = results[0].geometry.location.lng();
     28              document.getElementById("slt-gmap-longitude").value = results[0].geometry.location.lat();
     29              callback(results[0].geometry.location,map);
     30            } else {
     31              alert('Geocode was not successful for the following reason: ' + status);
     32            }
     33          });
     34        })();
     35      }
     36      codeAddress(function(myLocation) { mapCreate(myLocation, map);});
     37    };
     38    sl_preview_map();
     39    jQuery('#slt-preview').on('click', function() {
     40      sl_preview_map();
    941    });
    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             document.getElementById("slt-gmap-latitude").value = results[0].geometry.location.lng();
    27             document.getElementById("slt-gmap-longitude").value = results[0].geometry.location.lat();
    28             callback(results[0].geometry.location,map);
    29           } else {
    30             alert('Geocode was not successful for the following reason: ' + status);
    31           }
    32         });
    33       })();
    34     }
    35     codeAddress(function(myLocation) { mapCreate(myLocation, map);});
    36   };
    37   sl_preview_map();
    38   jQuery('#slt-preview').on('click', function() {
    39     sl_preview_map();
    40   });
     42  }
    4143}
  • scale-lite-tools/trunk/inc/sl-google-maps/render-cpt.php

    r1586608 r1586624  
    109109  if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
    110110    // post meta
    111     $html_id = get_post_meta(get_the_ID(),'gmap_options_html-id',true);
    112     $map_markers = explode(',', get_post_meta(get_the_ID(),'gmap_options_map-markers',true));
    113111    $map_latitude = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-latitude',true);
    114112    $map_longitude = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-latitude',true);
     113    $map_markers = explode(',', get_post_meta(get_the_ID(),'gmap_options_slt-gmap-markers',true));
     114    $html_id = get_post_meta(get_the_ID(),'gmap_options_html-id',true);
    115115    $width = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-width',true);
    116116    $height = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-height',true);
    117117    $map_type = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-type',true);
    118118    $zoom = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-zoom',true);
     119    $show_info_titles = get_post_meta(get_the_ID(),'gmap_options_slt-gmap-show-marker-info-box',true);
    119120
    120121    global $mapsArray;
    121     $mapsArray += array(get_the_ID()=>array('map_markers'=>$map_markers,
    122       'html_id'=>$html_id,
    123       'map_latitude'=>$map_latitude,
    124       'map_longitude'=>$map_longitude,
    125       'html_id'=>$html_id,
    126       'width'=>$width,
    127       'height'=>$height,
    128       'map_type'=>$map_type,
    129       'zoom'=>$zoom
    130     ));
     122    $mapsArray += array(
     123        get_the_ID() => array(
     124        'map_latitude'=>$map_latitude,
     125        'map_longitude'=>$map_longitude,
     126        'map_markers'=>$map_markers,
     127        'html_id'=>$html_id,
     128        'width'=>$width,
     129        'height'=>$height,
     130        'map_type'=>$map_type,
     131        'zoom'=>$zoom,
     132        'show_info_titles'=>$show_info_titles
     133      )
     134    );
     135
    131136    // register javascript var scaleLiteMarkerVars that holds the markers
    132137    wp_localize_script('sl-google-maps-frontend', 'scaleLiteMapsBuffer',
Note: See TracChangeset for help on using the changeset viewer.