Commits

Anonymous committed 870b63c

Comments (0)

Files changed (3)

classes/class.wv15maps.php

 		print '<script type="text/javascript">
 		/* <![CDATA[ */
 			var data = '.json_encode($this->mapData).';
-			var wv15_map = new WV15_Map(data);
+			var wv15_map = new WV15_Maps(data);
 			wv15_map.run();
 		/* ]]> */
 		</script>

pages/index.inc.php

 
 print '
 <table class="rex-table wymtable" cellpadding="5" cellspacing="1">
-	<tr><th>Anleitung für WYM-Editor-Modul</th></tr>
+	<tr><th>Anleitung für WVMaps-Modul</th></tr>
 	<tr><th>Input</th></tr>
 	<tr><td>
 		<div class="mapsmodule"><code>Es ist keine Eingabe nötig.';
 			highlight_file(dirname(__FILE__).'/../templates/template.mapsmodule1.inc.php');
 print '</code></div>
 	</td></tr>
+	<tr><th>JavaScript-Einbindung</th></tr>
+	<tr><td><code>';
+	
+		highlight_file(dirname(__FILE__).'/../templates/template.maps.inc.js');
+		
+print '	</code>
+	
 </table>';
 
 include $REX['INCLUDE_PATH']."/layout/bottom.php";

templates/template.maps.inc.js

+/**
+ * @author Gregor Aisch
+ * @publisher webvariants GbR
+ * @website http://www.webvariants.de/
+ * @contact info - webvariants - de
+ * 
+ * This script uses the prototype library. It must be loaded before this file is loaded.
+ * You can find prototype from http://www.prototypejs.org/
+ * 
+ * not really tested yet..
+ */
+
+if (Prototype.Version) {
+	document.observe('dom:loaded', function() {
+		
+		// adress some elements
+		var status = $('element1'); 					// we'll print some feedback in here 
+		var routeDetails = $('element2'); 				// output-container for the map-details
+		var inputFromAdress = $('fromAdress'); 			// input-field for route start (can be <input>, <select> or <textarea>)
+		var inputToAdress = $('toAdress');  			// input-field for route end (can be <input>, <select> or <textarea>)
+		var inputGetRouteButton =  $('show_route'); 	// button to submit the form
+		var wv15mapsInstance = wv15_map;				// instance name of the WV15_Maps-JS-Class
+		
+		if (routeDetails) {
+			// hide element while no route
+			routeDetails.hide();
+			
+			if (inputFromAdress && inputToAdress && inputGetRouteButton && wv15mapsInstance) {
+				inputGetRouteButton.observe('click', function() {
+			
+					routeDetails.innerHTML = '<h2>Anfahrtsbeschreibung:</h2>';
+					status.update('<p>Die Route wird berechnet...</p>');
+					
+					// little helper function to get value from different form-elements
+					var extractValue = function(element) {
+						if (element.value) {
+							return element.value;
+						} else if (element.options) {
+							return element.options[element.selectedIndex].value;
+						} else if (element.innerHTML) {
+							return element.innerHTML;
+						}
+					}
+					
+					var fromAdress = extractValue(inputFromAdress);
+					var toAdress = extractValue(inputToAdress);
+	
+					if (fromAdress && toAdress) {
+						wv15mapsInstance.showRoute(
+							fromAdress, 
+							toAdress, 
+							routeDetails, 
+							function() {
+								// complete handler - do something with the route container
+								routeDetails.show();	
+							}.bind(this),
+							function(gdir) {
+								// error handler
+								switch (gdir.getStatus().code) {
+									case G_GEO_UNKNOWN_ADDRESS:
+										status.update("<p>Für die eingegebene Adresse wurde keine geografische Position gefunden. Die Ursache könnte darin liegen, dass die Adresse noch sehr neu ist oder einfach ein Tippfehler vorliegt. Sie könnten versuchen die Adresse genauer zu definieren (z.B. indem Sie die Postleitzahl hinzufügen o.ä.).</p>") ;
+										break;
+									case G_GEO_SERVER_ERROR:
+										status.update("<p>A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.</p>");
+										break;
+									case G_GEO_MISSING_QUERY:
+										status.update("<p>The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.</p>");
+										break;
+//									case G_UNAVAILABLE_ADDRESS:   <--- Doc bug... this is either not defined, or Doc is wrong
+//										status.update("<p>The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.</p>");
+//										break;
+									case G_GEO_BAD_KEY:
+										status.update("<p>The given key is either invalid or does not match the domain for which it was given.</p>");
+										break;
+									case G_GEO_BAD_REQUEST:
+										status.update("<p>A directions request could not be successfully parsed.</p>");
+										break;
+									default:
+										status.update("<p>Ein unbekannter Fehler ist aufgetreten.</p>");
+								}
+							}.bind(this)
+						);
+					}
+				}.bind(this));
+			}
+		}
+	});
+}