Skip to content
Snippets Groups Projects
Commit 2d2eb237 authored by webgeer's avatar webgeer
Browse files

includes parsing rss feeds

parent 090be745
No related branches found
No related tags found
No related merge requests found
......@@ -43,3 +43,60 @@ function gmap_textchange(thismap) {
thismap.panTo(newpoint=new GLatLng($("gmap-latitude").value, $("gmap-longitude").value));
thismap.addOverlay(thispoint=new GMarker(newpoint));
}
function createMarkerFromRSS(item,icon) {
var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
// var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
// alert('Link: ' +link);
// namespaces are handled by spec in moz, not in ie -- Looking for a better more universal parsing routine.
if (navigator.userAgent.toLowerCase().indexOf("msie") < 0) {
// Is there a geo:lat defined?
if (item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat").length>0) {
item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].normalize();
// Is there a value for geo:lat
if (item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].hasChildNodes()) {
// Then there probably is a geo:long too
var lat = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].childNodes[0].nodeValue;
var lng = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","long")[0].childNodes[0].nodeValue;
}
}
} else {
var lat = item.getElementsByTagName("geo:lat")[0].childNodes[0].nodeValue;
if (lat == undefined) {
lat = item.getElementsByTagName("icbm:lat")[0].childNodes[0].nodeValue;
}
var lng = item.getElementsByTagName("geo:long")[0].childNodes[0].nodeValue;
if (lng == undefined) {
lng = item.getElementsByTagName("icbm:long")[0].childNodes[0].nodeValue;
}
}
//alert('Lat: '+lat);
var point = new GLatLng(parseFloat(lat), parseFloat(lng));
var html = "<a href=\"" + link + "\">" + title + "</a>";
var marker=createGMarker(point, html, icon);
return marker;
}
function parseGeoRSS(map, rssurl,icon) {
var request = GXmlHttp.create();
request.open("GET", rssurl, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var items = xmlDoc.documentElement.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var marker = createMarkerFromRSS(items[i], icon);
map.addOverlay(marker);
}
}
}
request.send(null);
}
......@@ -59,6 +59,7 @@ function gmap_perm() {
* shapes - an array of associative arrays for the overlays.
* track - a file containing a series of points in .plt format to be
* inserted into the node.
* feeds - an associative array of rss feeds
*
* Xmaps must be enabled for circle and polygon to work.
*
......@@ -73,6 +74,8 @@ function gmap_perm() {
function gmap_draw_map($gmap, $javascript='') {
global $base_url;
_gmap_doheader();
$clusterset=false;
(!isset($gmap['width'])) ? $gmap['width']=GMAP_WIDTH: NULL;
(!isset($gmap['height'])) ? $gmap['height']=GMAP_HEIGHT:NULL;
(!isset($gmap['zoom'])) ? $gmap['zoom']=GMAP_ZOOM:NULL;
......@@ -175,6 +178,7 @@ function gmap_draw_map($gmap, $javascript='') {
if (isset($gmap['markers'])) {
if (GMAP_CLUSTER) {
$outtext .="\n var clusterer = new Clusterer(".$gmap['id'].");\n";
$clusterset=true;
}
$lastmarker='';
foreach ($gmap['markers'] as $item) {
......@@ -200,6 +204,7 @@ function gmap_draw_map($gmap, $javascript='') {
}
if (GMAP_CLUSTER) {
$outtext .='clusterer.AddMarker(createGMarker(new GLatLng('.$item['point'].'),\''.$mytext.'\',\''.$mymarker."'));\n";
$clusterset=true;
}
else {
$outtext .=$gmap['id'].'.addOverlay(createGMarker(new GLatLng('.$item['point'].'),\''.$mytext.'\',\''.$mymarker."'));\n";
......@@ -298,6 +303,22 @@ function gmap_draw_map($gmap, $javascript='') {
}
}
}
if (isset($gmap['feeds'])) {
// if (GMAP_CLUSTER && !$clusterset) {
// $outtext .="\n var clusterer = new Clusterer(".$gmap['id'].");\n";
// }
foreach ($gmap['feeds'] as $item) {
$mymarker='';
if (isset($item['markername'])){
if (file_exists(variable_get('gmap_markerfiles','modules/gmap/markers').'/'.$item['markername'].'.png')) {
$mymarker=$base_url.'/'.variable_get('gmap_markerfiles','modules/gmap/markers').'/'.$item['markername'].'.png';
}
}
if (isset($item['url'])) {
$outtext.= "parseGeoRSS(".$gmap['id'].",'".$item['url']."','$mymarker');\n";
}
}
}
if (strlen($javascript)>0) {
$javascript=str_replace('{id}',$gmap['id'],$javascript);
$outtext .=$javascript;
......@@ -417,6 +438,12 @@ function gmap_parse_macro($instring,$ver=2) {
$tt['filename'] =$t[1];
$gmap['track'][] = $tt;
break;
case 'feed':
$tt['url'] =$t[1];
$gmap['feeds'][] = $tt;
break;
case 'line1':
$tt['color']=GMAP_LINECOLOR1;
......@@ -652,7 +679,7 @@ function gmap_menu($may_cache) {
if (variable_get('gmap_user',0)) {
$items[] = array('path' => 'map/users',
'type' => MENU_NORMAL_ITEM,
'title' => t('User locations'),
'title' => t('user locations'),
'access' => user_access('show user map'),
'callback' => 'gmap_users_page');
}
......@@ -873,7 +900,7 @@ function gmap_macro_form() {
'#default_value' => GMAP_CONTROL,
'#attributes' => array('onchange' => 'set_control_type(this.value);')
);
$form['macroform']['longlat'] = array(
$form['macroform']['latlong'] = array(
'#type' => 'textfield',
'#id' => 'gmap-latlong',
'#title' => t('The Latitude and Longitude of the centre of the map'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment