[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  function mp_map(data)
   2  {
   3      this.map     = null;
   4  
   5      this.data    = data;
   6      this.settings     = data.settings;
   7      this.prefix     = this.settings.prefix;
   8  
   9      this.center_lng = jQuery('#' + this.prefix + '_center_lng');
  10      this.center_lat = jQuery('#' + this.prefix + '_center_lat');
  11  
  12      this.zoomlevel  = jQuery('#' + this.prefix + '_zoomlevel');
  13      this.maptype      = jQuery('#' + this.prefix + '_maptype');
  14  
  15      this.container     = document.getElementById(this.prefix + '_map');
  16          
  17      this.count = parseInt(this.settings.count);
  18      this.max   = 10;
  19  
  20  
  21  
  22      this.init = function() {
  23  
  24          // Initialize communication with the platform
  25          var ptOptions = {
  26              'app_id'  : mp_mapL10n.app_id,
  27              'app_code': mp_mapL10n.app_code
  28          }
  29          if (location.protocol == 'https:') ptOptions.useHTTPS = true;
  30  
  31          this.platform = new H.service.Platform(ptOptions);
  32  
  33          // Obtain the default map types from the platform object
  34          this.Layers = this.platform.createDefaultLayers();
  35  
  36          this.center = this.getLatLng(this.setLoLa(this.settings.center_lng, this.settings.center_lat));
  37  
  38          var myOptions = {
  39              center:     this.center,
  40              zoom:         parseInt(this.zoomlevel.val()),
  41          };
  42  
  43          this.map = new H.Map(    this.container,
  44                      this.get_maptype(this.maptype.val()),
  45                      myOptions
  46          );
  47  
  48          // Make the map interactive
  49          // MapEvents enables the event system
  50          // Behavior implements default interactions for pan/zoom
  51          var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(this.map));
  52  
  53          // Create the UI (bubbles, controls)
  54          this.ui = new H.ui.UI(this.map);
  55  
  56          if ( this.count )
  57          {
  58              if ( this.count < this.max ) {
  59                  // Create a group that can hold map objects:
  60                  this.group = new H.map.Group();
  61  
  62                  // Add the group to the map object:
  63                  this.map.addObject(this.group);
  64  
  65                  // add 'tap' event listener, that opens info bubble, to the group
  66                  this.group.addEventListener('tap', function (evt) {
  67                      if(typeof(_this.bubble) != "undefined") _this.ui.removeBubble(_this.bubble);        //_this.bubble.close();
  68                      // event target is the marker itself, group is a parent event target
  69                      // for all objects that it contains
  70                      _this.bubble =  new H.ui.InfoBubble(evt.target.getPosition(), {
  71                          // read custom data
  72                          content: evt.target.getData()
  73                      });
  74                      // show info bubble
  75                      _this.ui.addBubble(_this.bubble);
  76                      _this.bubble.getElement().addEventListener('click', function(e) {
  77                          _this.ui.removeBubble(_this.bubble);                        //_this.bubble.close();
  78                      });
  79                  }, false);
  80              
  81                  for (var i in this.data.markers) this.setMarker(this.data.markers[i]);
  82              }
  83              else {
  84                  this.setCluster();
  85              }
  86          }
  87  
  88          this.setEvents();
  89          this.setControls();
  90          this.scheduler();                        
  91      };
  92  
  93      this.sanitize = function(x) {
  94          x = parseFloat(x);
  95          return x.toFixed(8);
  96      };
  97  
  98      this.setLoLa = function(lng, lat) {
  99          return { lo: this.sanitize(lng), la: this.sanitize(lat) };
 100      };
 101  
 102      this.getLoLa = function(LatLng) {
 103          return { lo: this.sanitize(LatLng.lng), la: this.sanitize(LatLng.lat) };
 104      };
 105  
 106      this.getLatLng = function(LoLa) {
 107          return { lat: LoLa.la, lng: LoLa.lo };
 108      };
 109  
 110      this.setMarker = function(data) {
 111  
 112          var coords = this.getLatLng(this.setLoLa(data['lng'], data['lat']));
 113  
 114          var marker = new H.map.Marker(coords);
 115  
 116          if(typeof(data['info']) != "undefined")
 117          {
 118              marker.setData(data['info']);
 119          }
 120  
 121          this.group.addObject(marker);
 122  
 123          return marker;
 124      };
 125  
 126      this.setCluster = function() {
 127          var data = this.data.markers;
 128  
 129          // First we need to create an array of DataPoint objects,
 130          // for the ClusterProvider
 131          var dataPoints = new Array();
 132          for (var i in this.data.markers) {
 133              var item = this.data.markers[i];
 134              dataPoints[i] = (typeof(item.info) != "undefined" )
 135                                       ? new H.clustering.DataPoint(item.lat, item.lng, 1, item.info)
 136                                       : new H.clustering.DataPoint(item.lat, item.lng);
 137          }
 138  
 139          // Create a clustering provider with custom options for clusterizing the input
 140          var clusteredDataProvider = new H.clustering.Provider(dataPoints, {
 141              clusteringOptions: {
 142              // Maximum radius of the neighbourhood
 143              eps: 32,
 144              // minimum weight of points required to form a cluster
 145              minWeight: 2
 146              }
 147          });
 148  
 149          // Create a layer tha will consume objects from our clustering provider
 150          var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);
 151  
 152          // To make objects from clustering provider visible,
 153          // we need to add our layer to the map
 154          this.map.addLayer(clusteringLayer);
 155      };
 156  
 157      this.get_maptype = function(maptype) {
 158                  var s = v = null;
 159          switch(maptype)
 160          {
 161              case 'SATELLITE': s = this.Layers.satellite.xbase; break;
 162              case 'HYBRID'    : s = this.Layers.satellite.map;   break;
 163              case 'TERRAIN'    : s = this.Layers.terrain.map;     break;
 164              default         : s = this.Layers.normal.map;       break;
 165          }
 166                  return s;
 167      };
 168  
 169      this.setEvents = function() {
 170          // map
 171                  this.map.addEventListener('dragend', function(e){
 172              var LoLa = _this.getLoLa(_this.map.getCenter());
 173              _this.center_lat.val(LoLa.la);
 174              _this.center_lng.val(LoLa.lo);
 175                  }); 
 176  
 177                   this.map.addEventListener('mapviewchangeend', function(){
 178              _this.zoomlevel.val(parseInt(_this.map.getZoom()));
 179                  });
 180  
 181                   this.map.addEventListener('baselayerchange', function(){
 182              switch(_this.map.getBaseLayer())
 183              {
 184                  case _this.Layers.satellite.xbase: s = 'SATELLITE'; break;
 185                  case _this.Layers.satellite.map     : s = 'HYBRID';    break;
 186                  case _this.Layers.terrain.map     : s = 'TERRAIN';   break;
 187                  default                  : s = 'ROADMAP';   break;
 188              }
 189              _this.maptype.val(s);
 190                  }); 
 191      };
 192  
 193      this.setControls = function() {
 194  
 195          var container = new H.ui.Control();
 196                  container.addClass('here-ctrl here-ctrl-group');
 197  
 198          var button = new H.ui.base.Element('button', 'here-ctrl-icon map_control');
 199            container.addChild(button);
 200  
 201          var button = new H.ui.base.Element('button', 'here-ctrl-icon map_center');
 202            container.addChild(button);
 203  
 204          container.setAlignment('top-right');
 205  
 206          this.ui.addControl('mailpress', container );
 207          this.ui.addControl('ScaleBar', new H.ui.ScaleBar() );
 208  
 209          jQuery('#' + _this.prefix + '_map .map_control').attr({alt:mp_mapL10n.changemap,title:mp_mapL10n.changemap}).click(function(){
 210                     switch (_this.maptype.val())
 211                     {
 212                         case 'ROADMAP' : _this.maptype.val('SATELLITE'); break;
 213                         case 'SATELLITE': _this.maptype.val('HYBRID');  break;
 214                         case 'HYBRID' :  _this.maptype.val('TERRAIN');    break;
 215                         default:      _this.maptype.val('ROADMAP');    break;
 216                          }
 217              _this.map.setBaseLayer(_this.get_maptype(_this.maptype.val()));
 218              return false;
 219          });
 220  
 221          jQuery('#' + _this.prefix + '_map .map_center').attr({alt:mp_mapL10n.center,title:mp_mapL10n.center}).click(function(){
 222              var LoLa = _this.getLoLa(_this.center);
 223              _this.map.setCenter(_this.center);
 224              _this.center_lat.val(LoLa.la);
 225              _this.center_lng.val(LoLa.lo);
 226              return false;
 227          });
 228      };
 229  
 230      this.scheduler = function() {
 231          jQuery.schedule({    id: _this.prefix + '_schedule',
 232                      time: 60000, 
 233                      func: function() { _this.update_settings(); }, 
 234                      repeat: true, 
 235                      protect: true
 236          });
 237      };
 238  
 239      this.update_settings = function() {
 240          var data = {};
 241          data['action']        = 'mp_ajax';
 242          data['mp_action']     = 'map_settings';
 243          data['id']        = mp_mapL10n.id;
 244          data['type']        = mp_mapL10n.type;
 245          data['prefix']        = this.prefix;
 246          data['settings[center_lat]'] = this.center_lat.val();
 247          data['settings[center_lng]'] = this.center_lng.val();
 248          data['settings[zoomlevel]']  = this.zoomlevel.val();
 249          data['settings[maptype]']    = this.maptype.val();
 250  
 251          jQuery.ajax({
 252              data: data,
 253              beforeSend: null,
 254              type: "POST",
 255              url: ajaxurl,
 256              success: null
 257          });
 258      };
 259  
 260      var _this = this;
 261  
 262      this.init();
 263  }


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