[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/map/ -> mp_map_b_form_geotag.js (source)

   1  function mp_map_bing(settings)
   2  {
   3      this.map    = null;
   4  
   5      this.settings     = settings;
   6      this.prefix     = 'mp_' + this.settings.form + '_' + this.settings.field;
   7      this.suffix      = '_' + this.settings.form + '_' + this.settings.field;
   8  
   9      this.center_lat = jQuery('#' + this.prefix + '_center_lat');
  10      this.center_lng = jQuery('#' + this.prefix + '_center_lng');
  11          
  12      this.zoomlevel  = jQuery('#' + this.prefix + '_zoomlevel');
  13      this.maptype      = jQuery('#' + this.prefix + '_maptype');
  14  
  15      this.container     = '#' + this.prefix + '_map';
  16  
  17      this.lat     = jQuery('#' + this.prefix + '_lat,#' + this.prefix + '_lat_d');
  18      this.lng     = jQuery('#' + this.prefix + '_lng,#' + this.prefix + '_lng_d');
  19      this.rgeocode     = jQuery('#' + this.prefix + '_geocode');
  20  
  21      this.infobox = false;
  22  
  23  
  24      this.init = function() {
  25  
  26          this.center = this.getLatLng(this.setLoLa(this.settings.center_lng, this.settings.center_lat));
  27  
  28          var myOptions = {
  29              center:     this.center,
  30              zoom:         parseInt(this.zoomlevel.val()),
  31              mapTypeId:     this.get_maptype(this.maptype.val()),
  32  
  33              showDashboard:    false,
  34              showMapTypeSelector: false,
  35              showZoomButtons: false,
  36  
  37              credentials:     mp_mapL10n.bmapkey
  38          };
  39  
  40          this.map = new Microsoft.Maps.Map(this.container, myOptions);
  41  
  42              //Create an infobox at the center of the map but don't show it.
  43          this.infobox = new Microsoft.Maps.Infobox(this.center, {visible: false});
  44              //Assign the infobox to a map instance.
  45          this.infobox.setMap(this.map);
  46  
  47          this.setMarker();
  48          this.setEvents();
  49          this.setControls();
  50      };
  51  
  52      this.sanitize = function(x) {
  53          x = parseFloat(x);
  54          return x.toFixed(8);
  55      };
  56  
  57      this.setLoLa = function(lng, lat) {
  58          return { lo: this.sanitize(lng), la: this.sanitize(lat) };
  59      };
  60  
  61      this.getLoLa = function(LatLng) {
  62          return { lo: this.sanitize(LatLng.longitude), la: this.sanitize(LatLng.latitude) };
  63      };
  64  
  65      this.getLatLng = function(LoLa) {
  66          return new Microsoft.Maps.Location(LoLa.la, LoLa.lo);
  67      };
  68  
  69      this.setCenter = function() {
  70          var LoLa = this.getLoLa(this.pin.getLocation());
  71          
  72          this.map.setView({center: this.getLatLng(LoLa)});
  73          this.center_lat.val(LoLa.la);
  74          this.center_lng.val(LoLa.lo);
  75      };
  76  
  77      this.setMarker = function() {
  78  
  79          this.pin = new Microsoft.Maps.Pushpin(this.center, { draggable: true });
  80  
  81          this.map.entities.push(this.pin);
  82      };
  83  
  84      this.moveMarker = function(LoLa) {
  85                  this.hideMarkerInfo();
  86          this.pin.setLocation(this.getLatLng(LoLa));
  87          this.lat.val(LoLa.la);
  88          this.lng.val(LoLa.lo);
  89  
  90          this.setCenter();
  91      };
  92  
  93      this.showMarkerInfo = function(LatLng, data) {
  94          this.infobox.setOptions({
  95              location: LatLng,
  96              title: '',
  97              description: data,
  98              visible: true
  99          });
 100      };
 101  
 102      this.hideMarkerInfo = function() {
 103          this.infobox.setOptions({title: '',description: '', visible: false});
 104      };
 105  
 106      this.get_maptype = function(maptype) {
 107                  var s = v = null;
 108          switch(maptype)
 109          {
 110              case 'SATELLITE': s = Microsoft.Maps.MapTypeId.aerial;    break;
 111              case 'HYBRID'     : s = Microsoft.Maps.MapTypeId.aerial; break;
 112              case 'TERRAIN'    : s = Microsoft.Maps.MapTypeId.canvasLight; break;
 113              default         : s = Microsoft.Maps.MapTypeId.road;    break;
 114          }
 115          return s;
 116      };
 117  
 118      this.setEvents = function() {
 119          // map
 120          Microsoft.Maps.Events.addHandler(_this.map, 'viewchangeend', function (e) { if (e.targetType != 'map') return;
 121              var LoLa = _this.getLoLa(_this.map.getCenter());
 122              _this.center_lat.val(LoLa.la);
 123              _this.center_lng.val(LoLa.lo);
 124  
 125              _this.zoomlevel.val(parseInt(_this.map.getZoom()));
 126          });
 127  
 128          // pin
 129          Microsoft.Maps.Events.addHandler(_this.pin, 'drag', function (e) { if (e.targetType != 'pushpin') return;
 130              _this.hideMarkerInfo();
 131              var LoLa = _this.getLoLa(_this.pin.getLocation());
 132              _this.lat.val(LoLa.la);
 133              _this.lng.val(LoLa.lo);
 134          });
 135  
 136          Microsoft.Maps.Events.addHandler(_this.pin, 'dragend', function (e) { if (e.targetType != 'pushpin') return;
 137              var LoLa = _this.getLoLa(_this.pin.getLocation());
 138              _this.lat.val(LoLa.la);
 139              _this.lng.val(LoLa.lo);
 140          });
 141  
 142  
 143          // geocoder
 144          this.geocoder = null;
 145          Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
 146              _this.geocoder = new Microsoft.Maps.Search.SearchManager(_this.map);
 147          });
 148  
 149          jQuery('#' + this.prefix + '_geocode_button').click( function() {
 150              var address = jQuery('#' + _this.prefix + '_geocode').val();
 151  
 152              var request = {
 153                  where: address,
 154                  callback: function(r) {
 155                      if (r && r.results && r.results.length > 0) {
 156                          var LoLa = _this.getLoLa(r.results[0].location);
 157                          _this.moveMarker(LoLa);
 158                      }
 159                      else
 160                      {
 161                          alert("Geocoder failed!");
 162                      }
 163                  },
 164                  errorCallback: function (e) {
 165                      alert("Geocoder failed");
 166                  }
 167              };
 168              _this.geocoder.geocode(request);
 169          });
 170      };
 171  
 172      this.setControls = function() {
 173  
 174          if ( 0 == this.settings.changemap+this.settings.center+this.settings.rgeocode ) return;
 175  
 176          MyControls.prototype = new Microsoft.Maps.CustomOverlay({ beneathLabels : false });
 177  
 178  		function MyControls() {
 179  
 180              _this.div = document.createElement('div');
 181              _this.div.setAttribute('class', 'bing-ctrl bing-ctrl-group');
 182                          
 183              if ( 1 == _this.settings.changemap ) {
 184                  var button = document.createElement('button');
 185                   button.setAttribute('type', 'button');
 186                  button.setAttribute('class', 'bing-ctrl-icon map_control');
 187                  button.setAttribute('alt',   mp_mapL10n.changemap);
 188                  button.setAttribute('title', mp_mapL10n.changemap);
 189                    _this.div.appendChild(button);
 190  
 191                  button.onclick = function(){
 192                             switch (_this.maptype.val())
 193                             {
 194                                 case 'ROADMAP' : _this.maptype.val('HYBRID'); break;
 195  //                               case 'SATELLITE' : _this.maptype.val('HYBRID');  break;
 196                                 case 'HYBRID' : _this.maptype.val('TERRAIN');    break;
 197                                 default:     _this.maptype.val('ROADMAP');    break;
 198                                  }
 199                                  var s = _this.get_maptype(_this.maptype.val());
 200                      _this.map.setMapType(s);
 201                      return false;
 202                  };
 203              }
 204  
 205              if ( 1 == _this.settings.center ) {
 206                  button = document.createElement('button');
 207                  button.setAttribute('type', 'button');
 208                  button.setAttribute('class', 'bing-ctrl-icon map_center');
 209                  button.setAttribute('alt',   mp_mapL10n.center);
 210                  button.setAttribute('title', mp_mapL10n.center);
 211                   _this.div.appendChild(button);
 212  
 213                  button.onclick = function(){
 214                      _this.setCenter();
 215                      return false;
 216                  };
 217              };
 218  
 219  
 220              if ( 1 == _this.settings.rgeocode ) {
 221                  button = document.createElement('button');
 222                  button.setAttribute('type', 'button');
 223                  button.setAttribute('class', 'bing-ctrl-icon map_geocode');
 224                  button.setAttribute('alt',   mp_mapL10n.rgeocode);
 225                  button.setAttribute('title', mp_mapL10n.rgeocode);
 226                   _this.div.appendChild(button);
 227  
 228                  button.onclick = function(){
 229                      var request = {
 230                          location: _this.pin.getLocation(),
 231                          callback: function(r) {
 232                              _this.setCenter();
 233                              _this.showMarkerInfo(_this.pin.getLocation(), r.name)
 234                          },
 235                          errorCallback: function (e) {
 236                              alert("No result found");
 237                          }
 238                      };
 239                      _this.geocoder.reverseGeocode(request);
 240                      return false;
 241                  };
 242              }
 243          };
 244  
 245          MyControls.prototype.onAdd = function () {
 246              this.setHtmlElement(_this.div);
 247          };
 248  
 249              //Implement the new custom overlay class.
 250              var controls = new MyControls();
 251  
 252              //Add the custom overlay to the map.
 253              this.map.layers.insert(controls);
 254      };
 255  
 256      var _this = this;
 257  
 258      this.init();
 259  }
 260  
 261  var MAILPRESS_data = new Array();
 262  
 263  function mp_field_type_geotag(s){
 264      MAILPRESS_data.push(s);
 265  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1