drupal und googlemap api funktionen
am 12.02.2008 - 19:50 Uhr in
Hallo, ich experementiere gerade mit Drupal etwas herum und versuche ein eigenes gmap Modul zu schreiben. Leider hänge ich schon am Anfang probleme:
Ich möchte eine einfache Karte innerhalb von Drupal darstellen. Folgende 2 Scripte ermöglichen eine Kartendarstellung:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- src attribute points to the location of the API on Google's server, key is passed as a parameter -->
<script src="http://maps.google.com/maps?file=api&v=2&key= ..." type="text/javascript"></script>
<script src="map_functions.js" type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>javascript file:
var centerLatitude = 37.818361;
var centerLongitude = -122.478032;
var startZoom = 13;
var map;
function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
var location = new GLatLng(centerLatitude, centerLongitude);
map.setCenter(location, startZoom);
}
}
window.onload = init;
window.onunload = GUnload;Das ganze müsste doch ungefähr in einem Drupal modul so aussehen:
...
function xgmap_menu($may_cache) {
$items = array();
if($may_cache) {
$items[] = array('path' => 'xgmap', 'title' => t('XGMAP'),
'callback' => 'xgmap_loadmap',
'access' => user_access('access xgmap'));
}
return $items;
}
function xgmap_loadmap() {
include("index.php");
...
}Ich bin leider kein eingefleischter Drupal Programmierer und bräuchte hier ne starthilfe! Vorallem wie ich den den javacode im header einbinden kann! Bin dankbar für jeden Tipp!
Hab mir inzwischen auch drupal_add_js und drupal_set_head angeschaut, aber noch nicht 100% dahintergekommen wie ich das nutzen kann.
- Anmelden oder Registrieren um Kommentare zu schreiben

function
am 12.02.2008 - 21:00 Uhr
function xgmap_menu($may_cache) {
$items = array();
if($may_cache) {
$items[] = array(
'path' => 'xgmap',
'title' => t('XGMAP'),
'callback' => 'xgmap_loadmap',
'access' => user_access('access xgmap')
//'type' => MENU_NORMAL_ITEM,
);
}
else {
if (user_access('access xgmap')) {
xgmap_add_html_head();
xgmap_add_js();
}
}
return $items;
}
function xgmap_add_html_head() {
drupal_add_js(drupal_get_path('module','xgmap').'/map_functions.js');
}
----------------------------------------
Alle Angaben ohne Gewähr!!:D
http://www.tobiasbaehr.de/
marker hinzufügen - googlemap
am 19.02.2008 - 17:08 Uhr
Vielen Dank. Bekomme inzwischen eine Karte angezeigt! Habe nun mein js-file mit der Funktion 'GEvent.addListener' erweitert, das Benutzern erlaubt Marker einzufügen. Das bekomme ich leider nicht zum laufen innerhalb von drupal! Ist das überhaupt so möglich? Auf was muss ich den hierbei achten? Wäre für jede Hilfe dankbar! Hier ist mein Code:
xgmap.modul:
<?php
function xgmap_menu($may_cache) {
$items = array();
if($may_cache) {
$items[] = array(
'path' => 'xgmap',
'title' => t('XGMAP'),
'callback' => 'xgmap_loadmap',
'access' => user_access('access xgmap'));
//type' => MENU_NORMAL_ITEM,
}
return $items;
}
function xgmap_loadmap() {
drupal_set_html_head('<script src="http://maps.google.com/maps?file=api&v=2&key=..." type="text/javascript"></script>');
drupal_add_js("sites/all/modules/xgmap/map_functions.js");
$output = '<div id="map" style="width: 500px; height: 300px"></div>';
return $output;
}
?>
java-file
var centerLatitude = 37.4419;
var centerLongitude = -122.1419;
var startZoom = 12;
var map;
function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
//map.addControl(new GMap2TypeControl());
var location = new GLatLng(centerLatitude, centerLongitude);
map.setCenter(location, startZoom);
GEvent.addListener(map, "click", function(overlay, latlng) {
var marker = new GMarker(latlng)
map.addOverlay(marker);
});
}
}
window.onload = init;
window.onunload = GUnload;