Esempio n. 1
0
 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the object
  *
  * @since   1.0
  */
 protected function __construct($options)
 {
     $keys = $this->getKeys();
     // Initialise object variables.
     self::$maxLoadSize = isset($options['size']) ? $options['size'] : ($keys->maxloadsize ? $keys->maxloadsize : 100);
     parent::__construct($options);
 }
Esempio n. 2
0
 public function checkLocation($value)
 {
     if (!isset($value) || empty($value)) {
         // no location -> no location id
         return '';
     }
     // check for locations
     $query = $this->_db->getQuery(true);
     $query->select(' jln.id ');
     $query->from(' #__joaktree_locations jln ');
     $query->where(' jln.value       = ' . $this->_db->quote($value) . ' ');
     $this->_db->setQuery($query);
     $result = $this->_db->loadResult();
     if (!$result) {
         // we are inserting the location
         $query->clear();
         $query->insert(' #__joaktree_locations ');
         $query->set(' value       = ' . $this->_db->quote($value) . ' ');
         $query->set(' indexLoc    = ' . $this->_db->quote(mb_strtoupper(mb_substr($value, 0, 1))) . ' ');
         // check for coordinates
         $settings = self::getSettings();
         if ($settings->indGeocode) {
             $data = new StdClass();
             $data->value = $value;
             $service = MBJServiceGeocode::getInstance();
             $status = $service->_('findLocation', $data);
             if ($status == 'found') {
                 $query->set(' latitude       	= ' . $data->latitude . ' ');
                 $query->set(' longitude       	= ' . $data->longitude . ' ');
                 $query->set(' indServerProcessed	= ' . $data->indServerProcessed . ' ');
                 $query->set(' results      		= ' . $data->results . ' ');
                 $query->set(' resultValue      	= ' . $this->_db->quote($data->result_address) . ' ');
             } else {
                 $query->set(' indServerProcessed	= ' . $data->indServerProcessed . ' ');
                 $query->set(' results      		= ' . $data->results . ' ');
             }
         }
         $this->_db->setQuery($query);
         $this->_db->query();
         // ... and retrieving the new id
         $query->clear();
         $query->select(' jln.id ');
         $query->from(' #__joaktree_locations jln ');
         $query->where(' jln.value       = ' . $this->_db->quote($value) . ' ');
         $this->_db->setQuery($query);
         $result = $this->_db->loadResult();
     }
     return $result;
 }
Esempio n. 3
0
 public function getGeocodeResultSet()
 {
     $settings = MBJServiceGeocode::getKeys();
     if (isset($settings->geocode)) {
         $geocodeAPIkey = $settings->geocode . 'APIkey';
         if (empty($settings->geocode) || !empty($settings->geocode) && isset($settings->{$geocodeAPIkey}) && empty($settings->{$geocodeAPIkey})) {
             // we cannot execute geocode search
             $resultSet = array();
         } else {
             $data = $this->loadFormData();
             $service = MBJServiceGeocode::getInstance();
             $status = $service->_('findLocation', $data);
             $resultSet = $service->_('getResultSet');
         }
     } else {
         $resultSet = array();
     }
     return $resultSet;
 }
Esempio n. 4
0
 public function fetch(&$data, $options = array())
 {
     $script = array();
     $indCenter = false;
     // center
     if (isset($options['longitude']) && !empty($options['longitude']) && isset($options['latitude']) && !empty($options['latitude'])) {
         $center = 'latLng:{lat:' . $options['latitude'] . ', lng:' . $options['longitude'] . '} ';
         $indCenter = true;
     } else {
         if (isset($options['center']) && !empty($options['center'])) {
             $centerdata = new stdClass();
             $centerdata->value = $options['center'];
             JLoader::register('MBJServiceGeocode', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joaktree' . DS . 'services' . DS . 'geocode.php');
             $geocode = MBJServiceGeocode::getInstance();
             $geocode->_('findLocation', $centerdata);
             $center = 'latLng:{lat:' . $centerdata->latitude . ', lng:' . $centerdata->longitude . '} ';
             $indCenter = true;
         } else {
             if (count($data)) {
                 // take the first marker as center
                 $center = 'latLng:{lat:' . $data[0]->latitude . ', lng:' . $data[0]->longitude . '} ';
                 $indCenter = true;
             }
         }
     }
     if (!$indCenter) {
         $this->log[] = JText::_('MBJ_MAP_ERROR_NO_CENTERZOOM');
         return false;
     }
     // zoom
     if (isset($options['zoomlevel']) && !empty($options['zoomlevel'])) {
         $zoom = 'zoom: ' . $options['zoomlevel'];
     } else {
         $zoom = 'zoom: 9';
     }
     // maptype //map, sat, hyb, osm
     if (isset($options['maptype']) && !empty($options['maptype'])) {
         switch ($options['maptype']) {
             case "sat":
                 $maptype = 'mtype:\'sat\'';
                 break;
             case "hyb":
                 $maptype = 'mtype:\'hyb\'';
                 break;
             case "ter":
                 // continue
             // continue
             case "road":
                 // continue
             // continue
             default:
                 // maptype is default roadmap
                 $maptype = 'mtype:\'map\'';
                 break;
         }
     } else {
         $maptype = 'mtype:\'map\'';
     }
     // generate script
     $script[] = 'function init_dyn_map() { ';
     $script[] = '   var Elb = document.getElementById("map_canvas").parentNode; ';
     $script[] = '   Elb.style.margin = "0"; ';
     $script[] = '   Elb.style.height = "100%"; ';
     $script[] = '   var myOptions = { ';
     $script[] = '      elt:document.getElementById("map_canvas"), ';
     /*ID of element on the page where you want the map added*/
     $script[] = '      ' . $zoom . ', ';
     /*initial zoom level of the map*/
     $script[] = '      ' . $center . ', ';
     /*center of map in latitude/longitude */
     $script[] = '      ' . $maptype . ' ';
     /*map type (osm)*/
     $script[] = '   } ';
     $script[] = '   var myMap = new MQA.TileMap(myOptions); ';
     $script[] = '   myMap.setSize (); ';
     // add controls --
     $script[] = '   MQA.withModule("smallzoom","viewoptions","mousewheel", function() { ';
     $script[] = '     myMap.addControl( ';
     $script[] = '       new MQA.SmallZoom(), ';
     $script[] = '       new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT, new MQA.Size(5,5)) ';
     $script[] = '     ); ';
     $script[] = '     myMap.addControl( ';
     $script[] = '       new MQA.ViewOptions(), ';
     $script[] = '       new MQA.MapCornerPlacement(MQA.MapCorner.TOP_RIGHT, new MQA.Size(5,5)) ';
     $script[] = '     ); ';
     $script[] = '     myMap.enableMouseWheelZoom(); ';
     $script[] = ' }); ';
     if ($options['selection'] == 'location' && isset($options['distance']) && !empty($options['distance']) && $options['distance'] > 0) {
         // we are adding a circle
         $script[] = '   MQA.withModule("shapes", function() { ';
         $script[] = '     var myCircle = new MQA.CircleOverlay(); ';
         $script[] = '     myCircle.radius="' . $options['distance'] / 1.6 . '"; ';
         $script[] = '     myCircle.shapePoints=[' . $options['latitude'] . ', ' . $options['longitude'] . ']; ';
         $script[] = '     myCircle.color="#2D36AD"; ';
         $script[] = '     myCircle.colorAlpha=0.7; ';
         $script[] = '     myCircle.borderWidth=2; ';
         $script[] = '     myCircle.fillColor="#2D36AD"; ';
         $script[] = '     myCircle.fillColorAlpha=.2; ';
         $script[] = '     myMap.addShape(myCircle); ';
         $script[] = '   }); ';
     }
     // setup possible images
     $iconset = isset($options['color']) && !empty($options['color']) ? (int) $options['color'] : 0;
     if (isset($options['icon_file']) && !empty($options['icon_file'])) {
         $iconDir = JURI::base() . $options['icon_file'] . '/' . $iconset . '/';
     } else {
         $iconDir = JURI::base() . 'administrator/components/com_joaktree/services/images/' . $iconset . '/';
     }
     for ($i = 1; $i < 22; $i++) {
         $script[] = '   var img' . $i . ' = new MQA.Icon("' . $iconDir . 'jt-icon-' . $i . '.png",24,32); ';
     }
     if (count($data)) {
         foreach ($data as $item) {
             $script[] = '   var cnt' . $item->id . ' = \'<div id="cnt' . $item->id . '">' . $item->information . '</div>\'; ';
             $script[] = '   var mrk' . $item->id . ' = new MQA.Poi( {lat:' . $item->latitude . ', lng:' . $item->longitude . '} ); ';
             $script[] = '   mrk' . $item->id . '.setIcon(img' . ((int) $item->label < 21 ? (int) $item->label : 21) . '); ';
             $script[] = '   mrk' . $item->id . '.setRolloverContent(\'' . $item->value . '\'); ';
             $script[] = '   mrk' . $item->id . '.setInfoTitleHTML(\'' . $item->value . '\'); ';
             $script[] = '   mrk' . $item->id . '.setInfoContentHTML(cnt' . $item->id . '); ';
             $script[] = '   myMap.addShape(mrk' . $item->id . '); ';
         }
     }
     $script[] = '} ';
     $script[] = '';
     $script[] = 'window.onload = init_dyn_map; ';
     return implode("\n", $script);
 }
Esempio n. 5
0
 public function geocode()
 {
     $service = MBJServiceGeocode::getInstance();
     $size = $service->getMaxLoadSize();
     // Fetch addresses
     $query = $this->_db->getQuery(true);
     $query->select(' jln.* ');
     $query->from(' #__joaktree_locations  jln ');
     $query->where('  indServerProcessed = 0 ');
     $query->where('  (  jln.latitude   IS NULL ' . '  OR jln.latitude   = 0 ' . '  OR jln.longitude  IS NULL ' . '  OR jln.longitude  = 0 ' . '  ) ');
     $this->_db->setQuery($query, 0, (int) $size);
     $locations = $this->_db->loadObjectList();
     $status = $service->_('findLocationBulk', $locations);
     // Iterate through the rows, geocoding each address
     foreach ($locations as $location) {
         $query->clear();
         $query->update(' #__joaktree_locations ');
         if (isset($location->longitude) && !empty($location->longitude) && isset($location->latitude) && !empty($location->latitude)) {
             $query->set(' longitude = ' . $this->_db->escape($location->longitude) . ' ');
             $query->set(' latitude  = ' . $this->_db->escape($location->latitude) . ' ');
         }
         $query->set(' results  = ' . (int) $location->results . ' ');
         $query->set(' resultValue  = ' . (!empty($location->result_address) ? $this->_db->quote($location->result_address) : 'NULL') . ' ');
         $query->set(' indServerProcessed = 1 ');
         $query->where(' id = ' . $location->id . ' ');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     return implode("<br />", $service->getLog());
 }
Esempio n. 6
0
 public function fetch(&$data, $options = array())
 {
     $indCenter = false;
     $indZoom = false;
     $mapview = $this->getBaseUrl();
     // size
     $width = isset($options['width']) && !empty($options['width']) ? $options['width'] : '650';
     $height = isset($options['height']) && !empty($options['height']) ? $options['height'] : '450';
     $mapview .= '&size=' . $width . 'x' . $height;
     if (isset($options['longitude']) && !empty($options['longitude']) && isset($options['latitude']) && !empty($options['latitude'])) {
         $mapview .= '&center=' . $options['latitude'] . ',' . $options['longitude'];
         $indCenter = true;
     } else {
         if (isset($options['center']) && !empty($options['center'])) {
             $centerdata = new stdClass();
             $centerdata->value = $options['center'];
             JLoader::register('MBJServiceGeocode', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joaktree' . DS . 'services' . DS . 'geocode.php');
             $geocode = MBJServiceGeocode::getInstance();
             $geocode->_('findLocation', $centerdata);
             $mapview .= '&center=' . $centerdata->latitude . ',' . $centerdata->longitude;
             $indCenter = true;
         }
     }
     if (isset($options['zoomlevel']) && !empty($options['zoomlevel'])) {
         $mapview .= '&zoom=' . $options['zoomlevel'];
         $indZoom = true;
     } else {
         if (count($data) == 1) {
             // just one locations
             $mapview .= '&zoom=10';
             $indZoom = true;
         }
     }
     // maptype
     if (isset($options['maptype']) && !empty($options['maptype'])) {
         switch ($options['maptype']) {
             case "sat":
                 $mapview .= '&maptype=satellite';
                 break;
             case "hyb":
                 $mapview .= '&maptype=hybrid';
                 break;
             case "ter":
                 $mapview .= '&maptype=terrain';
                 break;
             case "road":
                 // continue
             // continue
             default:
                 // continue
                 // maptype is default roadmap
                 break;
         }
     }
     // markers
     if (count($data)) {
         $indContinue = true;
         $tmpdata = $data;
         $item = array_shift($tmpdata);
         $color = isset($options['color']) && !empty($options['color']) ? 'color:0x' . $options['color'] . '|' : '';
         while ($indContinue) {
             if (is_object($item)) {
                 // save the current string in case we go over the max length
                 $tmpUrl = $mapview;
                 $mapview .= '&markers=' . $color;
                 // label
                 if (isset($item->label) && !empty($item->label)) {
                     $mapview .= is_numeric($item->label) ? 'label:' . (int) $item->label : '';
                     $mapview .= !is_numeric($item->label) ? 'label:' . strtoupper(substr($item->label, 0, 1)) : '';
                     $mapview .= '|';
                 }
                 $mapview .= $item->latitude . ',' . $item->longitude;
                 $indCenter = true;
                 $indZoom = true;
                 $item = array_shift($tmpdata);
                 if (!$item) {
                     // we are done
                     $indContinue = false;
                 }
                 if (strlen($mapview) > 2000) {
                     // This should be - according to Google - 2048
                     // we reached max url length
                     $indContinue = false;
                     $mapview = $tmpUrl;
                 }
             } else {
                 $indContinue = false;
             }
         }
     }
     if (!$indCenter || !$indZoom) {
         $this->log[] = JText::_('MBJ_MAP_ERROR_NO_CENTERZOOM');
         return false;
     }
     return $mapview;
 }
Esempio n. 7
0
 public function fetch(&$data, $options = array())
 {
     $script = array();
     $indCenter = false;
     // center
     if (isset($options['longitude']) && !empty($options['longitude']) && isset($options['latitude']) && !empty($options['latitude'])) {
         $center = 'center: new google.maps.LatLng(' . $options['latitude'] . ',' . $options['longitude'] . ')';
         $indCenter = true;
     } else {
         if (isset($options['center']) && !empty($options['center'])) {
             $centerdata = new stdClass();
             $centerdata->value = $options['center'];
             JLoader::register('MBJServiceGeocode', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joaktree' . DS . 'services' . DS . 'geocode.php');
             $geocode = MBJServiceGeocode::getInstance();
             $geocode->_('findLocation', $centerdata);
             $center = 'center: new google.maps.LatLng(' . $centerdata->latitude . ',' . $centerdata->longitude . ')';
             $indCenter = true;
         } else {
             if (count($data)) {
                 // take the first marker as center
                 $center = 'center: new google.maps.LatLng(' . $data[0]->latitude . ',' . $data[0]->longitude . ')';
                 $indCenter = true;
             }
         }
     }
     if (!$indCenter) {
         $this->log[] = JText::_('MBJ_MAP_ERROR_NO_CENTERZOOM');
         return false;
     }
     // zoom
     if (isset($options['zoomlevel']) && !empty($options['zoomlevel'])) {
         $zoom = 'zoom: ' . $options['zoomlevel'];
     } else {
         $zoom = 'zoom: 9';
     }
     // maptype
     $maptype = 'mapTypeId: google.maps.MapTypeId.';
     if (isset($options['maptype']) && !empty($options['maptype'])) {
         switch ($options['maptype']) {
             case "sat":
                 $maptype .= 'SATELLITE';
                 break;
             case "hyb":
                 $maptype .= 'HYBRID';
                 break;
             case "ter":
                 $maptype .= 'TERRAIN';
                 break;
             case "road":
                 // continue
             // continue
             default:
                 // maptype is default roadmap
                 $maptype .= 'ROADMAP';
                 break;
         }
     } else {
         $maptype .= 'ROADMAP';
     }
     // generate script
     $script[] = 'function init_dyn_map() { ';
     $script[] = '   var Elb = document.getElementById("map_canvas").parentNode; ';
     $script[] = '   Elb.style.margin = "0"; ';
     $script[] = '   Elb.style.height = "100%"; ';
     $script[] = '   var myOptions = { ';
     $script[] = '      ' . $zoom . ', ';
     $script[] = '      ' . $center . ', ';
     $script[] = '      ' . $maptype . ' ';
     $script[] = '   } ';
     $script[] = '   var myMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions); ';
     if ($options['selection'] == 'location' && isset($options['distance']) && !empty($options['distance']) && $options['distance'] > 0) {
         // we are adding a circle
         $script[] = '   var myCircle = new google.maps.Circle({ ';
         $script[] = '     map: myMap, ';
         $script[] = '     center: new google.maps.LatLng(' . $options['latitude'] . ',' . $options['longitude'] . '), ';
         $script[] = '     radius: ' . $options['distance'] * 1000 . ', ';
         $script[] = '     strokeColor: \'#2D36AD\', ';
         $script[] = '     strokeOpacity: 0.7, ';
         $script[] = '     strokeWeight: 2, ';
         $script[] = '     fillColor: \'#2D36AD\', ';
         $script[] = '     fillOpacity: 0.2 ';
         $script[] = '  }); ';
     }
     if (isset($options['icon_file']) && !empty($options['icon_file'])) {
         $iconFile = JURI::base() . $options['icon_file'];
     } else {
         $iconFile = JURI::base() . 'administrator/components/com_joaktree/services/images/jt_map_sprite.png';
     }
     // setup possible images
     $iconset = isset($options['color']) && !empty($options['color']) ? (int) $options['color'] : 0;
     $theme = $iconset * 34;
     for ($i = 0; $i < 21; $i++) {
         $pos = $i * 26;
         $script[] = '   var img' . ($i + 1) . ' = new google.maps.MarkerImage("' . $iconFile . '", ' . '      new google.maps.Size(24, 32), ' . '      new google.maps.Point(' . $pos . ', ' . $theme . ')); ';
         // The origin in the sprite for this image is 0,0.
     }
     if (count($data)) {
         foreach ($data as $item) {
             $script[] = '   var cnt' . $item->id . ' = \'<div id="cnt' . $item->id . '">' . $item->information . '</div>\'; ';
             $script[] = '   var inf' . $item->id . ' = new google.maps.InfoWindow({ ';
             $script[] = '      content: cnt' . $item->id . ' ';
             $script[] = '   }); ';
             $script[] = '   var mrk' . $item->id . ' = new google.maps.Marker({ ';
             $script[] = '      position: new google.maps.LatLng(' . $item->latitude . ',' . $item->longitude . '), ';
             $script[] = '      map: myMap, ';
             $script[] = '      icon: img' . ((int) $item->label < 21 ? (int) $item->label : 21) . ', ';
             $script[] = '      title: "' . $item->value . '" ';
             $script[] = '   }); ';
             $script[] = '  google.maps.event.addListener(mrk' . $item->id . ', \'click\', function() { ';
             $script[] = '      inf' . $item->id . '.open(myMap, mrk' . $item->id . '); ';
             $script[] = '  }); ';
         }
     }
     $script[] = '} ';
     $script[] = '';
     $script[] = 'function loadScript() { ';
     $script[] = '   var script  = document.createElement("script"); ';
     $script[] = '   script.type = "text/javascript"; ';
     $script[] = '   script.src  = "' . self::getScriptUrl() . '&callback=init_dyn_map"; ';
     $script[] = '   document.body.appendChild(script); ';
     $script[] = '} ';
     $script[] = '';
     $script[] = 'window.onload = loadScript; ';
     return implode("\n", $script);
 }
Esempio n. 8
0
 public function fetch(&$data, $options = array())
 {
     $indCenter = false;
     $indZoom = false;
     $mapview = $this->getBaseUrl();
     // size
     $width = isset($options['width']) && !empty($options['width']) ? $options['width'] : '650';
     $height = isset($options['height']) && !empty($options['height']) ? $options['height'] : '450';
     $mapview .= '&size=' . $width . ',' . $height;
     if (isset($options['longitude']) && !empty($options['longitude']) && isset($options['latitude']) && !empty($options['latitude'])) {
         $mapview .= '&center=' . $options['latitude'] . ',' . $options['longitude'];
         $indCenter = true;
     } else {
         if (isset($options['center']) && !empty($options['center'])) {
             $centerdata = new stdClass();
             $centerdata->value = $options['center'];
             JLoader::register('MBJServiceGeocode', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joaktree' . DS . 'services' . DS . 'geocode.php');
             $geocode = MBJServiceGeocode::getInstance();
             $geocode->_('findLocation', $centerdata);
             $mapview .= '&center=' . $centerdata->latitude . ',' . $centerdata->longitude;
             $indCenter = true;
         }
     }
     if (isset($options['zoomlevel']) && !empty($options['zoomlevel'])) {
         $mapview .= '&zoom=' . $options['zoomlevel'];
         $indZoom = true;
     }
     // maptype
     if (isset($options['maptype']) && !empty($options['maptype'])) {
         switch ($options['maptype']) {
             case "sat":
                 $maptype = 'sat';
                 break;
             case "hyb":
                 $maptype = 'hyb';
                 break;
             case "ter":
                 //continue
             //continue
             case "road":
                 //continue
             //continue
             default:
                 $maptype = 'map';
                 break;
         }
     } else {
         $maptype = 'map';
     }
     $mapview .= '&type=' . $maptype;
     // markers
     if (count($data)) {
         $indContinue = true;
         $tmpdata = $data;
         $item = array_shift($tmpdata);
         $mapview .= '&pois=';
         $color = isset($options['color']) && !empty($options['color']) ? $options['color'] : 'orange';
         while ($indContinue) {
             if (is_object($item)) {
                 // save the current string in case we go over the max length
                 $tmpUrl = $mapview;
                 // color + label
                 $mapview .= $color . (is_numeric($item->label) ? '-' . (int) $item->label : '');
                 $mapview .= ',' . $item->latitude . ',' . $item->longitude;
                 $mapview .= count($tmpdata) ? '|' : '';
                 $indCenter = true;
                 $indZoom = true;
                 $item = array_shift($tmpdata);
                 if (!$item) {
                     // we are done
                     $indContinue = false;
                 }
                 if (strlen($mapview) > 1024) {
                     // we reached max url length
                     $indContinue = false;
                     $mapview = $tmpUrl;
                 }
             } else {
                 $indContinue = false;
             }
         }
     }
     if (!$indCenter || !$indZoom) {
         $this->log[] = JText::_('MBJ_MAP_ERROR_NO_CENTERZOOM');
         return false;
     }
     return $mapview;
 }