From c4b84794978ed5e9c15e65c89390807a455ab122 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 6 Nov 2012 15:33:41 -0500 Subject: [PATCH] Added map tab (functionality from 1.x that was accidentally omitted from 2.0 up to this point). --- module/VuFind/config/module.config.php | 7 +- .../src/VuFind/RecordDriver/SolrDefault.php | 11 ++ module/VuFind/src/VuFind/RecordTab/Map.php | 131 ++++++++++++++++++ .../blueprint/templates/RecordTab/map.phtml | 65 +++++++++ .../templates/RecordTab/map.phtml | 1 + 5 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 module/VuFind/src/VuFind/RecordTab/Map.php create mode 100644 themes/blueprint/templates/RecordTab/map.phtml create mode 100644 themes/jquerymobile/templates/RecordTab/map.phtml diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 39ea5c2c216..6d166c61561 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -284,13 +284,15 @@ $config = array( 'Holdings' => 'HoldingsILS', 'Description' => 'Description', 'TOC' => 'TOC', 'UserComments' => 'UserComments', 'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt', - 'HierarchyTree' => 'HierarchyTree', 'Details' => 'StaffViewArray', + 'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map', + 'Details' => 'StaffViewArray', ), 'VuFind\RecordDriver\SolrMarc' => array( 'Holdings' => 'HoldingsILS', 'Description' => 'Description', 'TOC' => 'TOC', 'UserComments' => 'UserComments', 'Reviews' => 'Reviews', 'Excerpt' => 'Excerpt', - 'HierarchyTree' => 'HierarchyTree', 'Details' => 'StaffViewMARC', + 'HierarchyTree' => 'HierarchyTree', 'Map' => 'Map', + 'Details' => 'StaffViewMARC', ), 'VuFind\RecordDriver\Summon' => array( 'Description' => 'Description', @@ -313,6 +315,7 @@ $config = array( 'hierarchytree' => 'VuFind\RecordTab\HierarchyTree', 'holdingsils' => 'VuFind\RecordTab\HoldingsILS', 'holdingsworldcat' => 'VuFind\RecordTab\HoldingsWorldCat', + 'map' => 'VuFind\RecordTab\Map', 'reviews' => 'VuFind\RecordTab\Reviews', 'staffviewarray' => 'VuFind\RecordTab\StaffViewArray', 'staffviewmarc' => 'VuFind\RecordTab\StaffViewMARC', diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php index 1b74ae5cbc0..61e91f3e1f5 100644 --- a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php +++ b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php @@ -1320,4 +1320,15 @@ class SolrDefault extends AbstractBase return isset($this->fields['title_sort']) ? $this->fields['title_sort'] : parent::getSortTitle(); } + + /** + * Get longitude/latitude text (or false if not available). + * + * @return string|bool + */ + public function getLongLat() + { + return isset($this->fields['long_lat']) + ? $this->fields['long_lat'] : false; + } } diff --git a/module/VuFind/src/VuFind/RecordTab/Map.php b/module/VuFind/src/VuFind/RecordTab/Map.php new file mode 100644 index 00000000000..dea58038ab2 --- /dev/null +++ b/module/VuFind/src/VuFind/RecordTab/Map.php @@ -0,0 +1,131 @@ +<?php +/** + * Map tab + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package RecordTabs + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +namespace VuFind\RecordTab; +use VuFind\Config\Reader as ConfigReader; + +/** + * Map tab + * + * @category VuFind2 + * @package RecordTabs + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +class Map extends AbstractBase + implements \VuFind\I18n\Translator\TranslatorAwareInterface +{ + /** + * Translator (or null if unavailable) + * + * @var \Zend\I18n\Translator\Translator + */ + protected $translator = null; + + /** + * Get the on-screen description for this tab. + * + * @return string + */ + public function getDescription() + { + return 'Map View'; + } + + /** + * getGoogleMapMarker - gets the JSON needed to display the record on a Google + * map. + * + * @return string + */ + public function getGoogleMapMarker() + { + $longLat = $this->getRecordDriver()->tryMethod('getLongLat'); + if (empty($longLat)) { + return json_encode(array()); + } + $longLat = explode(',', $longLat); + $markers = array( + array( + 'title' => (string) $this->getRecordDriver()->getBreadcrumb(), + 'lon' => $longLat[0], + 'lat' => $longLat[1] + ) + ); + return json_encode($markers); + } + + /** + * Set a translator + * + * @param \Zend\I18n\Translator\Translator $translator Translator + * + * @return ResultGoogleMapAjax + */ + public function setTranslator(\Zend\I18n\Translator\Translator $translator) + { + $this->translator = $translator; + return $this; + } + + /** + * Get translator object. + * + * @return \Zend\I18n\Translator\Translator + */ + public function getTranslator() + { + return $this->translator; + } + + /** + * getUserLang + * + * @return string of lang + */ + public function userLang() + { + $translator = $this->getTranslator(); + return is_object($translator) ? $translator->getLocale() : 'en'; + } + + /** + * Is this tab active? + * + * @return bool + */ + public function isActive() + { + $config = ConfigReader::getConfig(); + if (!isset($config->Content->recordMap)) { + return false; + } + $longLat = $this->getRecordDriver()->tryMethod('getLongLat'); + return !empty($longLat); + } +} \ No newline at end of file diff --git a/themes/blueprint/templates/RecordTab/map.phtml b/themes/blueprint/templates/RecordTab/map.phtml new file mode 100644 index 00000000000..1cefe10b1e7 --- /dev/null +++ b/themes/blueprint/templates/RecordTab/map.phtml @@ -0,0 +1,65 @@ +<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.5&sensor=false&language=<?=$this->tab->userLang()?>"></script> + +<script type="text/javascript"> + +var markers; +var markersData; +var latlng; +var myOptions; +var map; +var infowindow = new google.maps.InfoWindow({maxWidth: 480, minWidth: 480}); + function initialize() { + markersData = <?=$this->tab->getGoogleMapMarker()?>; + latlng = new google.maps.LatLng(0, 0); + myOptions = { + zoom: 1, + center: latlng, + mapTypeControl: true, + mapTypeControlOptions: { + style: google.maps.MapTypeControlStyle.DROPDOWN_MENU + }, + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + map = new google.maps.Map(document.getElementById("map_canvas"), + myOptions); + showMarkers(); + } + function showMarkers(){ + deleteOverlays(); + markers = []; + + for (var i = 0; i<markersData.length; i++){ + var disTitle = markersData[i].title; + var iconTitle = disTitle; + if (disTitle.length>25){ + iconTitle = disTitle.substring(0,25) + "..."; + } + var markerImg = "https://chart.googleapis.com/chart?chst=d_bubble_text_small&chld=edge_bc|" + iconTitle +"|EEEAE3|"; + var labelXoffset = 1 + disTitle.length * 4; + var latLng = new google.maps.LatLng(markersData[i].lat , markersData[i].lon) + var marker = new google.maps.Marker({ + position: latLng, + map: map, + title: disTitle, + icon: markerImg + }); + markers.push(marker); + } + } + function deleteOverlays() { + if (markers) { + for (i in markers) { + markers[i].setMap(null); + } + markers.length = 0; + } + } + function refreshMap() { + showMarkers(); + } + google.maps.event.addDomListener(window, 'load', initialize); +</script> + +<div id="wrap" onload="initialize()" style="width: 674px; height: 479px"> + <div id="map_canvas" style="width: 100%; height: 100%"></div> +</div> diff --git a/themes/jquerymobile/templates/RecordTab/map.phtml b/themes/jquerymobile/templates/RecordTab/map.phtml new file mode 100644 index 00000000000..1d088d2ec8b --- /dev/null +++ b/themes/jquerymobile/templates/RecordTab/map.phtml @@ -0,0 +1 @@ +<!-- not supported in mobile interface --> \ No newline at end of file -- GitLab