[commits] [Wiki] changed: HordeMap

Michael Rubinsky mrubinsk at horde.org
Mon Aug 15 21:22:44 UTC 2011


mrubinsk  Mon, 15 Aug 2011 21:22:43 +0000

Modified page: http://wiki.horde.org/HordeMap
New Revision:  1.2
Change log:  Add basic php script to demonstrate/test HordeMap

@@ -28,10 +28,120 @@
  * Next we deal with the commercial mapping layers. Take the *full*  
contents of the //!OpenLayers/Layer/{mapprovider}.js// files that you  
want to support, and add append it to the  
//hordemap/{mapprovider}.js// file, replacing the existing openlayer  
code already in that file. For example - take the contents of  
//!OpenLayers/Layer/Google.js// and append it to the end of  
//hordemap/google.js// being sure to replace the exising openlayer  
code. This is all the code outside of the !HordeMap.Google and  
!HordeMap.Geocoder.Google classes.
  * Language files. This is probably the section with the most work.  
Since openlayers does not maintain any consistency in the style of  
locale naming, we have to edit almost every language file. !Openlayers  
sometimes names locales like EN_US, and sometimes like EN-US and  
sometimes just like EN. First, copy all the language files (except the  
en.js file - that should be built in the openlayers.js file) to the  
//hordemap/lang// directory. They should *all* be named in the  
de_DE.js format.  Next, you have to open each file and rename the key  
into the Lang array to match the filename.

  +++ How to use
+<code>
+<?php
+/**
+ * Example script for producing a HordeMap
+ *
+ * @author Michael J Rubinsky
+ */

-TODO
+// Init Horde
+define('HORDE_BASE', '/private/var/www/html/horde');
+require_once HORDE_BASE . '/lib/core.php';
+Horde_Registry::appInit(
+	'horde',
+	 array(
+		'authentication' => 'none',
+	    'session_control' => 'none'));
+
+// Hordemap parameters. Driver will always be "Horde" unless you are working
+// with a custom developed map driver.
+// providers is an array of available mapping layers.
+// geocoder is the desired geocoder to use, pass Null to use default  
null geocoder.
+// Typically these would come from the application's global
+// configuration array ($conf)
+$params = array(
+	'driver' => 'Horde',
+	'providers' => array('Yahoo', 'Google', 'Public', 'Mytopo'),
+	'geocoder' => 'Google'
+);
+$providerJson = json_encode($params['providers']);
+// Setup translations
+$language = str_replace('_', '-', $GLOBALS['language']);
+$language = $GLOBALS['language'];
+if (!file_exists($GLOBALS['registry']->get('jsfs', 'horde') . '/map/'  
. $language . '.js')) {
+    $language = 'en-US';
+}
+
+// Additional configurations.
+$params['conf'] = array(
+    // If using a marker image
+    'markerImage' => (string)Horde_Themes::img('map/marker.png'),
+    'markerBackgroun$d' =>  
(string)Horde_Themes::img('map/marker-shadow.png'),
+    'useMarkerLayer' => true,
+    // Use this language for translations if available.
+    'language' => $language,
+);
+
+// API keys for those layers that require them.
+foreach ($params['providers'] as $layer) {
+    switch ($layer) {
+    case 'Google':
+        // No longer required for v3.
+        //$params['conf']['apikeys']['google'] =  
$GLOBALS['conf']['api']['googlemaps'];
+        break;
+    case 'Yahoo':
+        $params['conf']['apikeys']['yahoo'] =  
$GLOBALS['conf']['api']['yahoomaps'];
+        break;
+    case 'Cloudmade':
+        $params['conf']['apikeys']['cloudmade'] =  
$GLOBALS['conf']['api']['cloudmade'];
+        break;
+    case 'Mytopo':
+        $params['conf']['apikeys']['mytopo'] =  
$GLOBALS['conf']['api']['mytopo'];
+        break;
+    }
+}
+
+// Geocoding
+if (!empty($params['geocoder'])) {
+    switch ($params['geocoder']) {
+    case 'Google':
+        //$params['conf']['apikeys']['google'] =  
$GLOBALS['conf']['api']['googlemaps'];
+        break;
+    case 'Yahoo':
+        $params['conf']['apikeys']['yahoo'] =  
$GLOBALS['conf']['api']['yahoomaps'];
+        break;
+    case 'Cloudmade':
+        $params['conf']['apikeys']['cloudmade'] =  
$GLOBALS['conf']['api']['cloudmade'];
+        break;
+    }
+}
+
+// Include the Hordemap bootstrap file, and initialize the Hordemap.
+$params['jsuri'] = $GLOBALS['registry']->get('jsuri', 'horde') . '/map/';
+Horde::addScriptFile('map/map.js', 'horde');
+$js = 'HordeMap.initialize(' . Horde_Serialize::serialize($params,  
HORDE_SERIALIZE::JSON) . ');';
+Horde::addinlineScript($js);
+
+// Start output
+require HORDE_BASE . '/templates/common-header.inc';
+?>
+<script type="text/javascript">
+// Basic initialization code to run on dom:loaded to init and display the map
+document.observe("dom:loaded", function() {
+    // These are the same as configured above
+    var providers = <?php echo $providerJson ?>;//['Google', 'Yahoo',  
'Public'];
+    layers = [];
+    providers.each(function(l) {
+       var p = new HordeMap[l]();
+       $H(p.getLayers()).values().each(function(e) {layers.push(e);});
+    });
+    map = new HordeMap.Map['Horde']({
+	elt: $('mapdiv'),
+        //delayed:true,
+        layers: layers,
+    	markerDragEnd: function(r) {alert('markerdragend');},
+	    mapClick: function(r) {alert('mapclick')}
+    });
+    //map.display();
+});
+</script>
+<h2>HordeMap Example</h2>
+<div id="mapdiv" style="height:300px;width:700px;"></div>
+</code>

  ++ Resources

  http://openlayers.org



More information about the commits mailing list