]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
first pass at Mapstraction plugin
authorEvan Prodromou <evan@status.net>
Wed, 18 Nov 2009 04:23:13 +0000 (23:23 -0500)
committerEvan Prodromou <evan@status.net>
Wed, 18 Nov 2009 04:23:13 +0000 (23:23 -0500)
12 files changed:
plugins/Mapstraction/MapstractionPlugin.php [new file with mode: 0644]
plugins/Mapstraction/js/mxn.(provider).core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.cloudmade.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.geocommons.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.google.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.google.geocoder.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.googlev3.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.microsoft.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.openlayers.core.js [new file with mode: 0644]
plugins/Mapstraction/js/mxn.yahoo.core.js [new file with mode: 0644]

diff --git a/plugins/Mapstraction/MapstractionPlugin.php b/plugins/Mapstraction/MapstractionPlugin.php
new file mode 100644 (file)
index 0000000..9a99d67
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Plugin to provide map visualization of location data
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Action
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Plugin to provide map visualization of location data
+ *
+ * This plugin uses the Mapstraction JavaScript library to
+ *
+ * @category Plugin
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ *
+ * @seeAlso  Location
+ */
+
+class MapstractionPlugin extends Plugin
+{
+    /** provider name, one of:
+     'cloudmade', 'google', 'microsoft', 'openlayers', 'yahoo' */
+    public $provider = 'openlayers';
+    /** provider API key (or 'appid'), if required ('google' and 'yahoo' only) */
+    public $apikey = null;
+
+    /**
+     * Hook for new URLs
+     *
+     * The way to register new actions from a plugin.
+     *
+     * @param Router &$m reference to router
+     *
+     * @return boolean event handler return
+     */
+
+    function onRouterInitialized(&$m)
+    {
+        $m->connect(':nickname/all/map',
+                    array('action' => 'allmap'),
+                    array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
+        $m->connect(':nickname/map',
+                    array('action' => 'usermap'),
+                    array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
+        return true;
+    }
+
+    /**
+     * Hook for autoloading classes
+     *
+     * This makes sure our classes get autoloaded from our directory
+     *
+     * @param string $cls name of class being used
+     *
+     * @return boolean event handler return
+     */
+
+    function onAutoload($cls)
+    {
+        switch ($cls)
+        {
+        case 'AllmapAction':
+        case 'UsermapAction':
+            include_once INSTALLDIR.'/plugins/Mapstraction/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+            return false;
+        default:
+            return true;
+        }
+    }
+
+    /**
+     * Hook for adding extra JavaScript
+     *
+     * This makes sure our scripts get loaded for map-related pages
+     *
+     * @param Action $action Action object for the page
+     *
+     * @return boolean event handler return
+     */
+
+    function onEndShowScripts($action)
+    {
+        // These are the ones that have maps on 'em
+        if (!in_array($action->trimmed('action'),
+                      array('showstream', 'all', 'allmap', 'usermap'))) {
+            return true;
+        }
+
+        switch ($this->provider)
+        {
+        case 'cloudmade':
+            $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
+            break;
+        case 'google':
+            $action->script(sprintf('http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=%s',
+                                    $this->apikey));
+            break;
+        case 'microsoft':
+            $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
+            break;
+        case 'openlayers':
+            // XXX: is this not nice...?
+            $action->script('http://openlayers.org/api/OpenLayers.js');
+            break;
+        case 'yahoo':
+            $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s',
+                                    $this->apikey));
+            break;
+        case 'geocommons': // don't support this yet
+        default:
+            return true;
+        }
+
+        $action->script(sprintf('%s?(%s)',
+                                common_path('plugins/Mapstraction/js/mxn.js'),
+                                $this->provider));
+
+        return true;
+    }
+}
diff --git a/plugins/Mapstraction/js/mxn.(provider).core.js b/plugins/Mapstraction/js/mxn.(provider).core.js
new file mode 100644 (file)
index 0000000..cc9752f
--- /dev/null
@@ -0,0 +1,289 @@
+mxn.register('{{api_id}}', {   \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element, api) {          \r
+               var me = this;\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       applyOptions: function(){\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addControls: function( args ) {\r
+               var map = this.maps[this.api];\r
+       \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addSmallControls: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addLargeControls: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+               var map = this.maps[this.api];\r
+               var pin = marker.toProprietary(this.api);\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return pin;\r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               var pl = polyline.toProprietary(this.api);\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return pl;\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       getCenter: function() {\r
+               var point;\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return point;\r
+       },\r
+\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               if(options && options.pan) { \r
+                       // TODO: Add provider code\r
+               }\r
+               else { \r
+                       // TODO: Add provider code\r
+               }\r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+               \r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               var zoom;\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               var map = this.maps[this.api];\r
+               // NE and SW points from the bounding box.\r
+               var ne = bbox.getNorthEast();\r
+               var sw = bbox.getSouthWest();\r
+               var zoom;\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                               // TODO: Add provider code\r
+                               break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                               // TODO: Add provider code\r
+                               break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                               // TODO: Add provider code\r
+                               break;\r
+                       default:\r
+                               // TODO: Add provider code\r
+               }        \r
+       },\r
+\r
+       getMapType: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+\r
+               //return mxn.Mapstraction.ROAD;\r
+               //return mxn.Mapstraction.SATELLITE;\r
+               //return mxn.Mapstraction.HYBRID;\r
+\r
+       },\r
+\r
+       getBounds: function () {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               //return new mxn.BoundingBox( ,  ,  ,  );\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest();\r
+               var ne = bounds.getNorthEast();\r
+               \r
+               // TODO: Add provider code\r
+               \r
+       },\r
+\r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       setImagePosition: function(id, oContext) {\r
+               var map = this.maps[this.api];\r
+               var topLeftPoint; var bottomRightPoint;\r
+\r
+               // TODO: Add provider code\r
+\r
+               //oContext.pixels.top = ...;\r
+               //oContext.pixels.left = ...;\r
+               //oContext.pixels.bottom = ...;\r
+               //oContext.pixels.right = ...;\r
+       },\r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+               \r
+       },\r
+\r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       getPixelRatio: function() {\r
+               var map = this.maps[this.api];\r
+\r
+               // TODO: Add provider code      \r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               var map = this.maps[this.api];\r
+\r
+               // TODO: Add provider code      \r
+       }\r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       fromProprietary: function(googlePoint) {\r
+               // TODO: Add provider code\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       openBubble: function() {                \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       hide: function() {\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       show: function() {\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       update: function() {\r
+               // TODO: Add provider code\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {\r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       show: function() {\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       hide: function() {\r
+               // TODO: Add provider code\r
+       }\r
+       \r
+}\r
+\r
+});
\ No newline at end of file
diff --git a/plugins/Mapstraction/js/mxn.cloudmade.core.js b/plugins/Mapstraction/js/mxn.cloudmade.core.js
new file mode 100644 (file)
index 0000000..b6ee70b
--- /dev/null
@@ -0,0 +1,357 @@
+mxn.register('cloudmade', {    
+
+    Mapstraction: {
+
+        init: function(element, api) {         
+            var me = this;             
+            var cloudmade = new CM.Tiles.CloudMade.Web({key: cloudmade_key});
+            this.maps[api] = new CM.Map(element, cloudmade);
+            this.loaded[api] = true;
+
+            CM.Event.addListener(this.maps[api], 'click', function(location,marker) {
+                if ( marker && marker.mapstraction_marker ) {
+                    marker.mapstraction_marker.click.fire();
+                }
+                else if ( location ) {
+                    me.click.fire({'location': new mxn.LatLonPoint(location.lat(), location.lng())});
+                }
+
+                // If the user puts their own Google markers directly on the map
+                // then there is no location and this event should not fire.
+                if ( location ) {
+                    me.clickHandler(location.lat(),location.lng(),location,me);
+                }
+            });
+        },
+
+        applyOptions: function(){
+            var map = this.maps[this.api];
+            if(this.options.enableScrollWheelZoom){
+              map.enableScrollWheelZoom();
+            }
+        },
+
+        resizeTo: function(width, height){     
+            this.maps[this.api].checkResize();
+        },
+
+        addControls: function( args ) {
+            var map = this.maps[this.api];
+
+           var c = this.addControlsArgs;
+           switch (c.zoom) {
+             case 'large':
+               this.addLargeControls();
+             break;
+             case 'small':
+               this.addSmallControls();
+             break;
+           }
+
+           if (c.map_type) {
+             this.addMapTypeControls();
+           }
+           if (c.scale) {
+             map.addControl(new CM.ScaleControl());
+             this.addControlsArgs.scale = true;
+           }
+        },
+
+        addSmallControls: function() {
+            var map = this.maps[this.api];
+           map.addControl(new CM.SmallMapControl());
+           this.addControlsArgs.zoom = 'small';
+        },
+
+        addLargeControls: function() {
+            var map = this.maps[this.api];
+           map.addControl(new CM.LargeMapControl());
+           this.addControlsArgs.zoom = 'large';
+        },
+
+        addMapTypeControls: function() {
+            var map = this.maps[this.api];
+
+           map.addControl(new CM.TileLayerControl());
+           this.addControlsArgs.map_type = true;
+        },
+
+        dragging: function(on) {
+            var map = this.maps[this.api];
+
+            if (on) {
+              map.enableDragging();
+            } else {
+              map.disableDragging();
+            }
+        },
+
+        setCenterAndZoom: function(point, zoom) { 
+            var map = this.maps[this.api];
+            var pt = point.toProprietary(this.api);
+            map.setCenter(pt, zoom);
+
+        },
+
+        addMarker: function(marker, old) {
+            var map = this.maps[this.api];
+            var pin = marker.toProprietary(this.api);
+           map.addOverlay(pin);
+            return pin;
+        },
+
+        removeMarker: function(marker) {
+            var map = this.maps[this.api];
+            marker.proprietary_marker.closeInfoWindow();
+           map.removeOverlay(marker.proprietary_marker);
+        },
+
+        removeAllMarkers: function() {
+           // Done in mxn.core.js
+        },
+
+        declutterMarkers: function(opts) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        addPolyline: function(polyline, old) {
+            var map = this.maps[this.api];
+            var pl = polyline.toProprietary(this.api);
+           map.addOverlay(pl);
+            return pl;
+        },
+
+        removePolyline: function(polyline) {
+            var map = this.maps[this.api];
+            map.removeOverlay(polyline.proprietary_polyline);
+        },
+
+        getCenter: function() {
+            var map = this.maps[this.api];
+            var pt = map.getCenter();
+
+            return new mxn.LatLonPoint(pt.lat(), pt.lng());
+        },
+
+        setCenter: function(point, options) {
+            var map = this.maps[this.api];
+            var pt = point.toProprietary(this.api);
+            if(options !== null && options.pan) { map.panTo(pt); }
+            else { map.setCenter(pt); }
+        },
+
+        setZoom: function(zoom) {
+            var map = this.maps[this.api];
+           map.setZoom(zoom);
+        },
+
+        getZoom: function() {
+           var map = this.maps[this.api];
+           return map.getZoom();
+        },
+
+        getZoomLevelForBoundingBox: function( bbox ) {
+            var map = this.maps[this.api];
+            // NE and SW points from the bounding box.
+            var ne = bbox.getNorthEast();
+            var sw = bbox.getSouthWest();
+
+           var zoom = map.getBoundsZoomLevel(new CM.LatLngBounds(sw.toProprietary(this.api), ne.toProprietary(this.api)));
+            return zoom;
+        },
+
+        setMapType: function(type) {
+            var map = this.maps[this.api];
+
+            // TODO: Are there any MapTypes for Cloudmade?
+
+            switch(type) {
+                case mxn.Mapstraction.ROAD:
+                // TODO: Add provider code
+                break;
+                case mxn.Mapstraction.SATELLITE:
+                // TODO: Add provider code
+                break;
+                case mxn.Mapstraction.HYBRID:
+                // TODO: Add provider code
+                break;
+                default:
+                // TODO: Add provider code
+            }   
+        },
+
+        getMapType: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Are there any MapTypes for Cloudmade?
+
+            return mxn.Mapstraction.ROAD;
+            //return mxn.Mapstraction.SATELLITE;
+            //return mxn.Mapstraction.HYBRID;
+
+        },
+
+        getBounds: function () {
+            var map = this.maps[this.api];
+
+            var box = map.getBounds();
+            var sw = box.getSouthWest();
+            var ne = box.getNorthEast();
+
+            return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());
+        },
+
+        setBounds: function(bounds){
+            var map = this.maps[this.api];
+            var sw = bounds.getSouthWest();
+            var ne = bounds.getNorthEast();
+
+           map.zoomToBounds(new CM.LatLngBounds(sw.toProprietary(this.api), ne.toProprietary(this.api)));
+        },
+
+        addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        setImagePosition: function(id, oContext) {
+            var map = this.maps[this.api];
+            var topLeftPoint; var bottomRightPoint;
+
+            // TODO: Add provider code
+
+        },
+
+        addOverlay: function(url, autoCenterAndZoom) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+
+        },
+
+        addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        toggleTileLayer: function(tile_url) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        getPixelRatio: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        },
+
+        mousePosition: function(element) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        }
+    },
+
+    LatLonPoint: {
+
+        toProprietary: function() {
+           var cll = new CM.LatLng(this.lat,this.lon);
+           return cll;
+        },
+
+        fromProprietary: function(point) {
+           return new mxn.LatLonPoint(point.lat(),point.lng());
+        }
+
+    },
+
+    Marker: {
+
+        toProprietary: function() {
+           var pt = this.location.toProprietary(this.api);
+           var options = {};
+
+           if (this.iconUrl) {
+             var cicon = new CM.Icon();
+             cicon.image = this.iconUrl;
+             if (this.iconSize) {
+               cicon.iconSize = new CM.Size(this.iconSize[0], this.iconSize[1]);
+               if (this.iconAnchor) {
+                 cicon.iconAnchor = new CM.Point(this.iconAnchor[0], this.iconAnchor[1]);
+               }
+             }
+             if (this.iconShadowUrl) {
+               cicon.shadow = this.iconShadowUrl;
+               if (this.iconShadowSize) {
+                 cicon.shadowSize = new CM.Size(this.iconShadowSize[0], this.iconShadowSize[1]);
+               }
+             }
+             options.icon = cicon;
+           }
+           if (this.labelText) {
+             options.title = this.labelText;
+           }
+           var cmarker = new CM.Marker(pt, options);
+
+           if (this.infoBubble) {
+             cmarker.bindInfoWindow(this.infoBubble);
+           }
+
+
+           return cmarker;
+        },
+
+        openBubble: function() {               
+            var pin = this.proprietary_marker;
+            pin.openInfoWindow(this.infoBubble);
+        },
+
+        hide: function() {
+            var pin = this.proprietary_marker;
+            pin.hide();
+        },
+
+        show: function() {
+            var pin = this.proprietary_marker;
+            pin.show();
+        },
+
+        update: function() {
+            // TODO: Add provider code
+        }
+
+    },
+
+    Polyline: {
+
+        toProprietary: function() {
+            var pts = [];
+            var poly;
+
+            for (var i = 0,  length = this.points.length ; i< length; i++){
+              pts.push(this.points[i].toProprietary(this.api));
+            }
+            if (this.closed || pts[0].equals(pts[pts.length-1])) {
+              poly = new CM.Polygon(pts, this.color, this.width, this.opacity, this.fillColor || "#5462E3", this.opacity || "0.3");
+            } else {
+              poly = new CM.Polyline(pts, this.color, this.width, this.opacity);
+            }
+            return poly;
+        },
+
+        show: function() {
+           this.proprietary_polyline.show();
+        },
+
+        hide: function() {
+           this.proprietary_polyline.hide();
+        }
+
+    }
+
+});
diff --git a/plugins/Mapstraction/js/mxn.core.js b/plugins/Mapstraction/js/mxn.core.js
new file mode 100644 (file)
index 0000000..c75d096
--- /dev/null
@@ -0,0 +1,1758 @@
+(function(){
+
+/**
+ * @exports mxn.util.$m as $m
+ */
+var $m = mxn.util.$m;
+
+/**
+ * Initialise our provider. This function should only be called 
+ * from within mapstraction code, not exposed as part of the API.
+ * @private
+ */
+var init = function() {
+       this.invoker.go('init', [ this.currentElement, this.api ]);
+       this.applyOptions();
+};
+
+/**
+ * Mapstraction instantiates a map with some API choice into the HTML element given
+ * @name mxn.Mapstraction
+ * @constructor
+ * @param {String} element The HTML element to replace with a map
+ * @param {String} api The API to use, one of 'google', 'googlev3', 'yahoo', 'microsoft', 'openstreetmap', 'multimap', 'map24', 'openlayers', 'mapquest'. If omitted, first loaded provider implementation is used.
+ * @param {Bool} debug optional parameter to turn on debug support - this uses alert panels for unsupported actions
+ * @exports Mapstraction as mxn.Mapstraction
+ */
+var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
+    if (!api){
+               api = mxn.util.getAvailableProviders()[0];
+       }
+       this.api = api;
+       this.maps = {};
+       this.currentElement = $m(element);
+       this.eventListeners = [];
+       this.markers = [];
+       this.layers = [];
+       this.polylines = [];
+       this.images = [];
+        this.controls = [];    
+       this.loaded = {};
+       this.onload = {};
+       this.element = element;
+       
+       // option defaults
+       this.options = {
+               enableScrollWheelZoom: false,
+               enableDragging: true
+       };
+       
+       this.addControlsArgs = {};
+       
+       // set up our invoker for calling API methods
+       this.invoker = new mxn.Invoker(this, 'Mapstraction', function(){ return this.api; });
+       
+       // Adding our events
+       mxn.addEvents(this, [
+               
+               /**
+                * Map has loaded
+                * @name mxn.Mapstraction#load
+                * @event
+                */
+               'load',
+               
+               /**
+                * Map is clicked {location: LatLonPoint}
+                * @name mxn.Mapstraction#click
+                * @event
+                */
+               'click',
+               
+               /**
+                * Map is panned
+                * @name mxn.Mapstraction#endPan
+                * @event
+                */
+               'endPan',
+               
+               /**
+                * Zoom is changed
+                * @name mxn.Mapstraction#changeZoom
+                * @event
+                */
+               'changeZoom',
+               
+               /**
+                * Marker is removed {marker: Marker}
+                * @name mxn.Mapstraction#markerAdded
+                * @event
+                */
+               'markerAdded',
+               
+               /**
+                * Marker is removed {marker: Marker}
+                * @name mxn.Mapstraction#markerRemoved
+                * @event
+                */
+               'markerRemoved',
+               
+               /**
+                * Polyline is added {polyline: Polyline}
+                * @name mxn.Mapstraction#polylineAdded
+                * @event
+                */
+               'polylineAdded',
+               
+               /**
+                * Polyline is removed {polyline: Polyline}
+                * @name mxn.Mapstraction#polylineRemoved
+                * @event
+                */
+               'polylineRemoved'
+       ]);
+       
+       // finally initialize our proper API map
+       init.apply(this);
+};
+
+// Map type constants
+Mapstraction.ROAD = 1;
+Mapstraction.SATELLITE = 2;
+Mapstraction.HYBRID = 3;
+
+// methods that have no implementation in mapstraction core
+mxn.addProxyMethods(Mapstraction, [ 
+       /**
+        * Adds a large map panning control and zoom buttons to the map
+        * @name mxn.Mapstraction#addLargeControls
+        * @function
+        */
+       'addLargeControls',
+               
+       /**
+        * Adds a map type control to the map (streets, aerial imagery etc)
+        * @name mxn.Mapstraction#addMapTypeControls
+        * @function
+        */
+       'addMapTypeControls', 
+       
+       /**
+        * Adds a GeoRSS or KML overlay to the map
+        *  some flavors of GeoRSS and KML are not supported by some of the Map providers
+        * @name mxn.Mapstraction#addOverlay
+        * @function
+        * @param {String} url GeoRSS or KML feed URL
+        * @param {Boolean} autoCenterAndZoom Set true to auto center and zoom after the feed is loaded
+        */
+       'addOverlay', 
+       
+       /**
+        * Adds a small map panning control and zoom buttons to the map
+        * @name mxn.Mapstraction#addSmallControls
+        * @function
+        */
+       'addSmallControls', 
+       
+       /**
+        * Applies the current option settings
+        * @name mxn.Mapstraction#applyOptions
+        * @function
+        */
+       'applyOptions',
+       
+       /**
+        * Gets the BoundingBox of the map
+        * @name mxn.Mapstraction#getBounds
+        * @function
+        * @returns {BoundingBox} The bounding box for the current map state
+        */
+       'getBounds', 
+       
+       /**
+        * Gets the central point of the map
+        * @name mxn.Mapstraction#getCenter
+        * @function
+        * @returns {LatLonPoint} The center point of the map
+        */
+       'getCenter', 
+       
+       /**
+        * Gets the imagery type for the map.
+        * The type can be one of:
+        *  mxn.Mapstraction.ROAD
+        *  mxn.Mapstraction.SATELLITE
+        *  mxn.Mapstraction.HYBRID
+        * @name mxn.Mapstraction#getMapType
+        * @function
+        * @returns {Number} 
+        */
+       'getMapType', 
+
+       /**
+        * Returns a ratio to turn distance into pixels based on current projection
+        * @name mxn.Mapstraction#getPixelRatio
+        * @function
+        * @returns {Float} ratio
+        */
+       'getPixelRatio', 
+       
+       /**
+        * Returns the zoom level of the map
+        * @name mxn.Mapstraction#getZoom
+        * @function
+        * @returns {Integer} The zoom level of the map
+        */
+       'getZoom', 
+       
+       /**
+        * Returns the best zoom level for bounds given
+        * @name mxn.Mapstraction#getZoomLevelForBoundingBox
+        * @function
+        * @param {BoundingBox} bbox The bounds to fit
+        * @returns {Integer} The closest zoom level that contains the bounding box
+        */
+       'getZoomLevelForBoundingBox', 
+       
+       /**
+        * Displays the coordinates of the cursor in the HTML element
+        * @name mxn.Mapstraction#mousePosition
+        * @function
+        * @param {String} element ID of the HTML element to display the coordinates in
+        */
+       'mousePosition',
+       
+       /**
+        * Resize the current map to the specified width and height
+        * (since it is actually on a child div of the mapElement passed
+        * as argument to the Mapstraction constructor, the resizing of this
+        * mapElement may have no effect on the size of the actual map)
+        * @name mxn.Mapstraction#resizeTo
+        * @function
+        * @param {Integer} width The width the map should be.
+        * @param {Integer} height The width the map should be.
+        */
+       'resizeTo', 
+       
+       /**
+        * Sets the map to the appropriate location and zoom for a given BoundingBox
+        * @name mxn.Mapstraction#setBounds
+        * @function
+        * @param {BoundingBox} bounds The bounding box you want the map to show
+        */
+       'setBounds', 
+       
+       /**
+        * setCenter sets the central point of the map
+        * @name mxn.Mapstraction#setCenter
+        * @function
+        * @param {LatLonPoint} point The point at which to center the map
+        * @param {Object} options Optional parameters
+        * @param {Boolean} options.pan Whether the map should move to the locations using a pan or just jump straight there
+        */
+       'setCenter', 
+       
+       /**
+        * Centers the map to some place and zoom level
+        * @name mxn.Mapstraction#setCenterAndZoom
+        * @function
+        * @param {LatLonPoint} point Where the center of the map should be
+        * @param {Integer} zoom The zoom level where 0 is all the way out.
+        */
+       'setCenterAndZoom', 
+       
+       /**
+        * Sets the imagery type for the map
+        * The type can be one of:
+        *  mxn.Mapstraction.ROAD
+        *  mxn.Mapstraction.SATELLITE
+        *  mxn.Mapstraction.HYBRID
+        * @name mxn.Mapstraction#setMapType
+        * @function
+        * @param {Number} type 
+        */
+       'setMapType', 
+       
+       /**
+        * Sets the zoom level for the map
+        * MS doesn't seem to do zoom=0, and Gg's sat goes closer than it's maps, and MS's sat goes closer than Y!'s
+        * TODO: Mapstraction.prototype.getZoomLevels or something.
+        * @name mxn.Mapstraction#setZoom
+        * @function
+        * @param {Number} zoom The (native to the map) level zoom the map to.
+        */
+       'setZoom',
+       
+       /**
+        * Turns a Tile Layer on or off
+        * @name mxn.Mapstraction#toggleTileLayer
+        * @function
+        * @param {tile_url} url of the tile layer that was created.
+        */
+       'toggleTileLayer'
+]);
+
+/**
+ * Sets the current options to those specified in oOpts and applies them
+ * @param {Object} oOpts Hash of options to set
+ */
+Mapstraction.prototype.setOptions = function(oOpts){
+       mxn.util.merge(this.options, oOpts);
+       this.applyOptions();
+};
+
+/**
+ * Sets an option and applies it.
+ * @param {String} sOptName Option name
+ * @param vVal Option value
+ */
+Mapstraction.prototype.setOption = function(sOptName, vVal){
+       this.options[sOptName] = vVal;
+       this.applyOptions();
+};
+
+/**
+ * Enable scroll wheel zooming
+ * @deprecated Use setOption instead.
+ */
+Mapstraction.prototype.enableScrollWheelZoom = function() {
+       this.setOption('enableScrollWheelZoom', true);
+};
+
+/**
+ * Enable/disable dragging of the map
+ * @param {Boolean} on
+ * @deprecated Use setOption instead.
+ */
+Mapstraction.prototype.dragging = function(on) {
+       this.setOption('enableDragging', on);
+};
+
+/**
+ * Change the current api on the fly
+ * @param {String} api The API to swap to
+ * @param element
+ */
+Mapstraction.prototype.swap = function(element,api) {
+       if (this.api === api) {
+               return;
+       }
+
+       var center = this.getCenter();
+       var zoom = this.getZoom();
+
+       this.currentElement.style.visibility = 'hidden';
+       this.currentElement.style.display = 'none';
+
+       this.currentElement = $m(element);
+       this.currentElement.style.visibility = 'visible';
+       this.currentElement.style.display = 'block';
+
+       this.api = api;
+
+       if (this.maps[this.api] === undefined) {
+               init.apply(this);
+
+               this.setCenterAndZoom(center,zoom);
+
+               for (var i = 0; i < this.markers.length; i++) {
+                       this.addMarker(this.markers[i], true);
+               }
+
+               for (var j = 0; j < this.polylines.length; j++) {
+                       this.addPolyline( this.polylines[j], true);
+               }
+       }
+       else {
+
+               //sync the view
+               this.setCenterAndZoom(center,zoom);
+
+               //TODO synchronize the markers and polylines too
+               // (any overlays created after api instantiation are not sync'd)
+       }
+
+       this.addControls(this.addControlsArgs);
+
+};
+
+/**
+ * Returns the loaded state of a Map Provider
+ * @param {String} api Optional API to query for. If not specified, returns state of the originally created API
+ */
+Mapstraction.prototype.isLoaded = function(api){
+       if (api === null) {
+               api = this.api;
+       }
+       return this.loaded[api];
+};
+
+/**
+ * Set the debugging on or off - shows alert panels for functions that don't exist in Mapstraction
+ * @param {Boolean} debug true to turn on debugging, false to turn it off
+ */
+Mapstraction.prototype.setDebug = function(debug){
+       if(debug !== null) {
+               this.debug = debug;
+       }
+       return this.debug;
+};
+
+
+/////////////////////////
+//
+// Event Handling
+//
+// FIXME need to consolidate some of these handlers...
+//
+///////////////////////////
+
+// Click handler attached to native API
+Mapstraction.prototype.clickHandler = function(lat, lon, me) {
+       this.callEventListeners('click', {
+               location: new LatLonPoint(lat, lon)
+       });
+};
+
+// Move and zoom handler attached to native API
+Mapstraction.prototype.moveendHandler = function(me) {
+       this.callEventListeners('moveend', {});
+};
+
+/**
+ * Add a listener for an event.
+ * @param {String} type Event type to attach listener to
+ * @param {Function} func Callback function
+ * @param {Object} caller Callback object
+ */
+Mapstraction.prototype.addEventListener = function() {
+       var listener = {};
+       listener.event_type = arguments[0];
+       listener.callback_function = arguments[1];
+
+       // added the calling object so we can retain scope of callback function
+       if(arguments.length == 3) {
+               listener.back_compat_mode = false;
+               listener.callback_object = arguments[2];
+       }
+       else {
+               listener.back_compat_mode = true;
+               listener.callback_object = null;
+       }
+       this.eventListeners.push(listener);
+};
+
+/**
+ * Call listeners for a particular event.
+ * @param {String} sEventType Call listeners of this event type
+ * @param {Object} oEventArgs Event args object to pass back to the callback
+ */
+Mapstraction.prototype.callEventListeners = function(sEventType, oEventArgs) {
+       oEventArgs.source = this;
+       for(var i = 0; i < this.eventListeners.length; i++) {
+               var evLi = this.eventListeners[i];
+               if(evLi.event_type == sEventType) {
+                       // only two cases for this, click and move
+                       if(evLi.back_compat_mode) {
+                               if(evLi.event_type == 'click') {
+                                       evLi.callback_function(oEventArgs.location);
+                               }
+                               else {
+                                       evLi.callback_function();
+                               }
+                       }
+                       else {
+                               var scope = evLi.callback_object || this;
+                               evLi.callback_function.call(scope, oEventArgs);
+                       }
+               }
+       }
+};
+
+
+////////////////////
+//
+// map manipulation
+//
+/////////////////////
+
+
+/**
+ * addControls adds controls to the map. You specify which controls to add in
+ * the associative array that is the only argument.
+ * addControls can be called multiple time, with different args, to dynamically change controls.
+ *
+ * args = {
+ *      pan:     true,
+ *      zoom:   'large' || 'small',
+ *      overview: true,
+ *      scale: true,
+ *      map_type: true,
+ * }
+ * @param {array} args Which controls to switch on
+ */
+Mapstraction.prototype.addControls = function( args ) {
+       this.addControlsArgs = args;
+       this.invoker.go('addControls', arguments);
+};
+
+/**
+ * Adds a marker pin to the map
+ * @param {Marker} marker The marker to add
+ * @param {Boolean} old If true, doesn't add this marker to the markers array. Used by the "swap" method
+ */
+Mapstraction.prototype.addMarker = function(marker, old) {
+       marker.mapstraction = this;
+       marker.api = this.api;
+       marker.location.api = this.api;
+       marker.map = this.maps[this.api]; 
+       var propMarker = this.invoker.go('addMarker', arguments);
+       marker.setChild(propMarker);
+       if (!old) {
+               this.markers.push(marker);
+       }
+       this.markerAdded.fire({'marker': marker});
+};
+
+/**
+ * addMarkerWithData will addData to the marker, then add it to the map
+ * @param {Marker} marker The marker to add
+ * @param {Object} data A data has to add
+ */
+Mapstraction.prototype.addMarkerWithData = function(marker, data) {
+       marker.addData(data);
+       this.addMarker(marker);
+};
+
+/**
+ * addPolylineWithData will addData to the polyline, then add it to the map
+ * @param {Polyline} polyline The polyline to add
+ * @param {Object} data A data has to add
+ */
+Mapstraction.prototype.addPolylineWithData = function(polyline, data) {
+       polyline.addData(data);
+       this.addPolyline(polyline);
+};
+
+/**
+ * removeMarker removes a Marker from the map
+ * @param {Marker} marker The marker to remove
+ */
+Mapstraction.prototype.removeMarker = function(marker) {       
+       var current_marker;
+       for(var i = 0; i < this.markers.length; i++){
+               current_marker = this.markers[i];
+               if(marker == current_marker) {
+                       this.invoker.go('removeMarker', arguments);
+                       marker.onmap = false;
+                       this.markers.splice(i, 1);
+                       this.markerRemoved.fire({'marker': marker});
+                       break;
+               }
+       }
+};
+
+/**
+ * removeAllMarkers removes all the Markers on a map
+ */
+Mapstraction.prototype.removeAllMarkers = function() {
+       var current_marker;
+       while(this.markers.length > 0) {
+               current_marker = this.markers.pop();
+               this.invoker.go('removeMarker', [current_marker]);
+       }
+};
+
+/**
+ * Declutter the markers on the map, group together overlapping markers.
+ * @param {Object} opts Declutter options
+ */
+Mapstraction.prototype.declutterMarkers = function(opts) {
+       if(this.loaded[this.api] === false) {
+               var me = this;
+               this.onload[this.api].push( function() {
+                       me.declutterMarkers(opts);
+               } );
+               return;
+       }
+
+       var map = this.maps[this.api];
+
+       switch(this.api)
+       {
+               //      case 'yahoo':
+               //
+               //        break;
+               //      case 'google':
+               //
+               //        break;
+               //      case 'openstreetmap':
+               //
+               //        break;
+               //      case 'microsoft':
+               //
+               //        break;
+               //      case 'openlayers':
+               //
+               //        break;
+               case 'multimap':
+                       /*
+                        * Multimap supports quite a lot of decluttering options such as whether
+                        * to use an accurate of fast declutter algorithm and what icon to use to
+                        * represent a cluster. Using all this would mean abstracting all the enums
+                        * etc so we're only implementing the group name function at the moment.
+                        */
+                       map.declutterGroup(opts.groupName);
+                       break;
+               //      case 'mapquest':
+               //
+               //        break;
+               //      case 'map24':
+               //
+               //        break;
+               case '  dummy':
+                       break;
+               default:
+                       if(this.debug) {
+                               alert(this.api + ' not supported by Mapstraction.declutterMarkers');
+                       }
+       }
+};
+
+/**
+ * Add a polyline to the map
+ * @param {Polyline} polyline The Polyline to add to the map
+ * @param {Boolean} old If true replaces an existing Polyline
+ */
+Mapstraction.prototype.addPolyline = function(polyline, old) {
+       polyline.api = this.api;
+       polyline.map = this.maps[this.api];
+       var propPoly = this.invoker.go('addPolyline', arguments);
+       polyline.setChild(propPoly);
+       if(!old) {
+               this.polylines.push(polyline);
+       }
+       this.polylineAdded.fire({'polyline': polyline});
+};
+
+// Private remove implementation
+var removePolylineImpl = function(polyline) {
+       this.invoker.go('removePolyline', arguments);
+       polyline.onmap = false;
+       this.polylineRemoved.fire({'polyline': polyline});
+};
+
+/**
+ * Remove the polyline from the map
+ * @param {Polyline} polyline The Polyline to remove from the map
+ */
+Mapstraction.prototype.removePolyline = function(polyline) {
+       var current_polyline;
+       for(var i = 0; i < this.polylines.length; i++){
+               current_polyline = this.polylines[i];
+               if(polyline == current_polyline) {
+                       this.polylines.splice(i, 1);
+                       removePolylineImpl.call(this, polyline);
+                       break;
+               }
+       }
+};
+
+/**
+ * Removes all polylines from the map
+ */
+Mapstraction.prototype.removeAllPolylines = function() {
+       var current_polyline;
+       while(this.polylines.length > 0) {
+               current_polyline = this.polylines.pop();
+               removePolylineImpl.call(this, current_polyline);
+       }
+};
+
+/**
+ * autoCenterAndZoom sets the center and zoom of the map to the smallest bounding box
+ * containing all markers
+ */
+Mapstraction.prototype.autoCenterAndZoom = function() {
+       var lat_max = -90;
+       var lat_min = 90;
+       var lon_max = -180;
+       var lon_min = 180;
+       var lat, lon;
+       var checkMinMax = function(){
+               if (lat > lat_max) {
+                       lat_max = lat;
+               }
+               if (lat < lat_min) {
+                       lat_min = lat;
+               }
+               if (lon > lon_max) {
+                       lon_max = lon;
+               }
+               if (lon < lon_min) {
+                       lon_min = lon;
+               }
+       };
+       for (var i = 0; i < this.markers.length; i++) {
+               lat = this.markers[i].location.lat;
+               lon = this.markers[i].location.lon;
+               checkMinMax();
+       }
+       for(i = 0; i < this.polylines.length; i++) {
+               for (var j = 0; j < this.polylines[i].points.length; j++) {
+                       lat = this.polylines[i].points[j].lat;
+                       lon = this.polylines[i].points[j].lon;
+                       checkMinMax();
+               }
+       }
+       this.setBounds( new BoundingBox(lat_min, lon_min, lat_max, lon_max) );
+};
+
+/**
+ * centerAndZoomOnPoints sets the center and zoom of the map from an array of points
+ *
+ * This is useful if you don't want to have to add markers to the map
+ */
+Mapstraction.prototype.centerAndZoomOnPoints = function(points) {
+       var bounds = new BoundingBox(points[0].lat,points[0].lon,points[0].lat,points[0].lon);
+
+       for (var i=1, len = points.length ; i<len; i++) {
+               bounds.extend(points[i]);
+       }
+
+       this.setBounds(bounds);
+};
+
+/**
+ * Sets the center and zoom of the map to the smallest bounding box
+ * containing all visible markers and polylines
+ * will only include markers and polylines with an attribute of "visible"
+ */
+Mapstraction.prototype.visibleCenterAndZoom = function() {
+       var lat_max = -90;
+       var lat_min = 90;
+       var lon_max = -180;
+       var lon_min = 180;
+       var lat, lon;
+       var checkMinMax = function(){
+               if (lat > lat_max) {
+                       lat_max = lat;
+               }
+               if (lat < lat_min) {
+                       lat_min = lat;
+               }
+               if (lon > lon_max) {
+                       lon_max = lon;
+               }
+               if (lon < lon_min) {
+                       lon_min = lon;
+               }
+       };
+       for (var i=0; i<this.markers.length; i++) {
+               if (this.markers[i].getAttribute("visible")) {
+                       lat = this.markers[i].location.lat;
+                       lon = this.markers[i].location.lon;
+                       checkMinMax();
+               }
+       }
+
+       for (i=0; i<this.polylines.length; i++){
+               if (this.polylines[i].getAttribute("visible")) {
+                       for (j=0; j<this.polylines[i].points.length; j++) {
+                               lat = this.polylines[i].points[j].lat;
+                               lon = this.polylines[i].points[j].lon;
+                               checkMinMax();
+                       }
+               }
+       }
+
+       this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+};
+
+/**
+ * Automatically sets center and zoom level to show all polylines
+ * Takes into account radious of polyline
+ * @param {Int} radius
+ */
+Mapstraction.prototype.polylineCenterAndZoom = function(radius) {
+       var lat_max = -90;
+       var lat_min = 90;
+       var lon_max = -180;
+       var lon_min = 180;
+
+       for (var i=0; i < mapstraction.polylines.length; i++)
+       {
+               for (var j=0; j<mapstraction.polylines[i].points.length; j++)
+               {
+                       lat = mapstraction.polylines[i].points[j].lat;
+                       lon = mapstraction.polylines[i].points[j].lon;
+
+                       latConv = lonConv = radius;
+
+                       if (radius > 0)
+                       {
+                               latConv = (radius / mapstraction.polylines[i].points[j].latConv());
+                               lonConv = (radius / mapstraction.polylines[i].points[j].lonConv());
+                       }
+
+                       if ((lat + latConv) > lat_max) {
+                               lat_max = (lat + latConv);
+                       }
+                       if ((lat - latConv) < lat_min) {
+                               lat_min = (lat - latConv);
+                       }
+                       if ((lon + lonConv) > lon_max) {
+                               lon_max = (lon + lonConv);
+                       }
+                       if ((lon - lonConv) < lon_min) {
+                               lon_min = (lon - lonConv);
+                       }
+               }
+       }
+
+       this.setBounds(new BoundingBox(lat_min, lon_min, lat_max, lon_max));
+};
+
+/**
+ * addImageOverlay layers an georeferenced image over the map
+ * @param {id} unique DOM identifier
+ * @param {src} url of image
+ * @param {opacity} opacity 0-100
+ * @param {west} west boundary
+ * @param {south} south boundary
+ * @param {east} east boundary
+ * @param {north} north boundary
+ */
+Mapstraction.prototype.addImageOverlay = function(id, src, opacity, west, south, east, north) {
+       
+       var b = document.createElement("img");
+       b.style.display = 'block';
+       b.setAttribute('id',id);
+       b.setAttribute('src',src);
+       b.style.position = 'absolute';
+       b.style.zIndex = 1;
+       b.setAttribute('west',west);
+       b.setAttribute('south',south);
+       b.setAttribute('east',east);
+       b.setAttribute('north',north);
+       
+       var oContext = {
+               imgElm: b
+       };
+       
+       this.invoker.go('addImageOverlay', arguments, { context: oContext });
+};
+
+Mapstraction.prototype.setImageOpacity = function(id, opacity) {
+       if (opacity < 0) {
+               opacity = 0;
+       }
+       if (opacity >= 100) {
+               opacity = 100;
+       }
+       var c = opacity / 100;
+       var d = document.getElementById(id);
+       if(typeof(d.style.filter)=='string'){
+               d.style.filter='alpha(opacity:'+opacity+')';
+       }
+       if(typeof(d.style.KHTMLOpacity)=='string'){
+               d.style.KHTMLOpacity=c;
+       }
+       if(typeof(d.style.MozOpacity)=='string'){
+               d.style.MozOpacity=c;
+       }
+       if(typeof(d.style.opacity)=='string'){
+               d.style.opacity=c;
+       }
+};
+
+Mapstraction.prototype.setImagePosition = function(id) {
+       var imgElement = document.getElementById(id);
+       var oContext = {
+               latLng: { 
+                       top: imgElement.getAttribute('north'),
+                       left: imgElement.getAttribute('west'),
+                       bottom: imgElement.getAttribute('south'),
+                       right: imgElement.getAttribute('east')
+               },
+               pixels: { top: 0, right: 0, bottom: 0, left: 0 }
+       };
+       
+       this.invoker.go('setImagePosition', arguments, { context: oContext });
+
+       imgElement.style.top = oContext.pixels.top.toString() + 'px';
+       imgElement.style.left = oContext.pixels.left.toString() + 'px';
+       imgElement.style.width = (oContext.pixels.right - oContext.pixels.left).toString() + 'px';
+       imgElement.style.height = (oContext.pixels.bottom - oContext.pixels.top).toString() + 'px';
+};
+
+Mapstraction.prototype.addJSON = function(json) {
+       var features;
+       if (typeof(json) == "string") {
+               features = eval('(' + json + ')');
+       } else {
+               features = json;
+       }
+       features = features.features;
+       var map = this.maps[this.api];
+       var html = "";
+       var item;
+       var polyline;
+       var marker;
+       var markers = [];
+
+       if(features.type == "FeatureCollection") {
+               this.addJSON(features.features);
+       }
+
+       for (var i = 0; i < features.length; i++) {
+               item = features[i];
+               switch(item.geometry.type) {
+                       case "Point":
+                               html = "<strong>" + item.title + "</strong><p>" + item.description + "</p>";
+                               marker = new Marker(new LatLonPoint(item.geometry.coordinates[1],item.geometry.coordinates[0]));
+                               markers.push(marker);
+                               this.addMarkerWithData(marker,{
+                                       infoBubble : html,
+                                       label : item.title,
+                                       date : "new Date(\""+item.date+"\")",
+                                       iconShadow : item.icon_shadow,
+                                       marker : item.id,
+                                       iconShadowSize : item.icon_shadow_size,
+                                       icon : "http://boston.openguides.org/markers/AQUA.png",
+                                       iconSize : item.icon_size,
+                                       category : item.source_id,
+                                       draggable : false,
+                                       hover : false
+                               });
+                               break;
+                       case "Polygon":
+                               var points = [];
+                               polyline = new Polyline(points);
+                               mapstraction.addPolylineWithData(polyline,{
+                                       fillColor : item.poly_color,
+                                       date : "new Date(\""+item.date+"\")",
+                                       category : item.source_id,
+                                       width : item.line_width,
+                                       opacity : item.line_opacity,
+                                       color : item.line_color,
+                                       polygon : true
+                               });
+                               markers.push(polyline);
+                               break;
+                       default:
+               // console.log("Geometry: " + features.items[i].geometry.type);
+               }
+       }
+       return markers;
+};
+
+/**
+ * Adds a Tile Layer to the map
+ *
+ * Requires providing a parameterized tile url. Use {Z}, {X}, and {Y} to specify where the parameters
+ *  should go in the URL.
+ *
+ * For example, the OpenStreetMap tiles are:
+ *  m.addTileLayer("http://tile.openstreetmap.org/{Z}/{X}/{Y}.png", 1.0, "OSM", 1, 19, true);
+ *
+ * @param {tile_url} template url of the tiles.
+ * @param {opacity} opacity of the tile layer - 0 is transparent, 1 is opaque. (default=0.6)
+ * @param {copyright_text} copyright text to use for the tile layer. (default=Mapstraction)
+ * @param {min_zoom} Minimum (furtherest out) zoom level that tiles are available (default=1)
+ * @param {max_zoom} Maximum (closest) zoom level that the tiles are available (default=18)
+ * @param {map_type} Should the tile layer be a selectable map type in the layers palette (default=false)
+ */
+Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {
+       if(!tile_url) {
+               return;
+       }
+       
+       this.tileLayers = this.tileLayers || [];        
+       opacity = opacity || 0.6;
+       copyright_text = copyright_text || "Mapstraction";
+       min_zoom = min_zoom || 1;
+       max_zoom = max_zoom || 18;
+       map_type = map_type || false;
+
+       return this.invoker.go('addTileLayer', [ tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type] );
+};
+
+/**
+ * addFilter adds a marker filter
+ * @param {field} name of attribute to filter on
+ * @param {operator} presently only "ge" or "le"
+ * @param {value} the value to compare against
+ */
+Mapstraction.prototype.addFilter = function(field, operator, value) {
+       if (!this.filters) {
+               this.filters = [];
+       }
+       this.filters.push( [field, operator, value] );
+};
+
+/**
+ * Remove the specified filter
+ * @param {Object} field
+ * @param {Object} operator
+ * @param {Object} value
+ */
+Mapstraction.prototype.removeFilter = function(field, operator, value) {
+       if (!this.filters) {
+               return;
+       }
+
+       var del;
+       for (var f=0; f<this.filters.length; f++) {
+               if (this.filters[f][0] == field &&
+                       (! operator || (this.filters[f][1] == operator && this.filters[f][2] == value))) {
+                       this.filters.splice(f,1);
+                       f--; //array size decreased
+               }
+       }
+};
+
+/**
+ * Delete the current filter if present; otherwise add it
+ * @param {Object} field
+ * @param {Object} operator
+ * @param {Object} value
+ */
+Mapstraction.prototype.toggleFilter = function(field, operator, value) {
+       if (!this.filters) {
+               this.filters = [];
+       }
+
+       var found = false;
+       for (var f = 0; f < this.filters.length; f++) {
+               if (this.filters[f][0] == field && this.filters[f][1] == operator && this.filters[f][2] == value) {
+                       this.filters.splice(f,1);
+                       f--; //array size decreased
+                       found = true;
+               }
+       }
+
+       if (! found) {
+               this.addFilter(field, operator, value);
+       }
+};
+
+/**
+ * removeAllFilters
+ */
+Mapstraction.prototype.removeAllFilters = function() {
+       this.filters = [];
+};
+
+/**
+ * doFilter executes all filters added since last call
+ * Now supports a callback function for when a marker is shown or hidden
+ * @param {Function} showCallback
+ * @param {Function} hideCallback
+ * @returns {Int} count of visible markers
+ */
+Mapstraction.prototype.doFilter = function(showCallback, hideCallback) {
+       var map = this.maps[this.api];
+       var visibleCount = 0;
+       var f;
+       if (this.filters) {
+               switch (this.api) {
+                       case 'multimap':
+                               /* TODO polylines aren't filtered in multimap */
+                               var mmfilters = [];
+                               for (f=0; f<this.filters.length; f++) {
+                                       mmfilters.push( new MMSearchFilter( this.filters[f][0], this.filters[f][1], this.filters[f][2] ));
+                               }
+                               map.setMarkerFilters( mmfilters );
+                               map.redrawMap();
+                               break;
+                       case '  dummy':
+                               break;
+                       default:
+                               var vis;
+                               for (var m=0; m<this.markers.length; m++) {
+                                       vis = true;
+                                       for (f = 0; f < this.filters.length; f++) {
+                                               if (! this.applyFilter(this.markers[m], this.filters[f])) {
+                                                       vis = false;
+                                               }
+                                       }
+                                       if (vis) {
+                                               visibleCount ++;
+                                               if (showCallback){
+                                                       showCallback(this.markers[m]);
+                                               }
+                                               else {
+                                                       this.markers[m].show();
+                                               }
+                                       } 
+                                       else { 
+                                               if (hideCallback){
+                                                       hideCallback(this.markers[m]);
+                                               }
+                                               else {
+                                                       this.markers[m].hide();
+                                               }
+                                       }
+
+                                       this.markers[m].setAttribute("visible", vis);
+                               }
+                               break;
+               }
+       }
+       return visibleCount;
+};
+
+Mapstraction.prototype.applyFilter = function(o, f) {
+       var vis = true;
+       switch (f[1]) {
+               case 'ge':
+                       if (o.getAttribute( f[0] ) < f[2]) {
+                               vis = false;
+                       }
+                       break;
+               case 'le':
+                       if (o.getAttribute( f[0] ) > f[2]) {
+                               vis = false;
+                       }
+                       break;
+               case 'eq':
+                       if (o.getAttribute( f[0] ) == f[2]) {
+                               vis = false;
+                       }
+                       break;
+       }
+
+       return vis;
+};
+
+/**
+ * getAttributeExtremes returns the minimum/maximum of "field" from all markers
+ * @param {field} name of "field" to query
+ * @returns {array} of minimum/maximum
+ */
+Mapstraction.prototype.getAttributeExtremes = function(field) {
+       var min;
+       var max;
+       for (var m=0; m<this.markers.length; m++) {
+               if (! min || min > this.markers[m].getAttribute(field)) {
+                       min = this.markers[m].getAttribute(field);
+               }
+               if (! max || max < this.markers[m].getAttribute(field)) {
+                       max = this.markers[m].getAttribute(field);
+               }
+       }
+       for (var p=0; m<this.polylines.length; m++) {
+               if (! min || min > this.polylines[p].getAttribute(field)) {
+                       min = this.polylines[p].getAttribute(field);
+               }
+               if (! max || max < this.polylines[p].getAttribute(field)) {
+                       max = this.polylines[p].getAttribute(field);
+               }
+       }
+
+       return [min, max];
+};
+
+/**
+ * getMap returns the native map object that mapstraction is talking to
+ * @returns the native map object mapstraction is using
+ */
+Mapstraction.prototype.getMap = function() {
+       // FIXME in an ideal world this shouldn't exist right?
+       return this.maps[this.api];
+};
+
+
+//////////////////////////////
+//
+//   LatLonPoint
+//
+/////////////////////////////
+
+/**
+ * LatLonPoint is a point containing a latitude and longitude with helper methods
+ * @name mxn.LatLonPoint
+ * @constructor
+ * @param {double} lat is the latitude
+ * @param {double} lon is the longitude
+ * @exports LatLonPoint as mxn.LatLonPoint
+ */
+var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
+       // TODO error if undefined?
+       //  if (lat == undefined) alert('undefined lat');
+       //  if (lon == undefined) alert('undefined lon');
+       this.lat = lat;
+       this.lon = lon;
+       this.lng = lon; // lets be lon/lng agnostic
+       
+       this.invoker = new mxn.Invoker(this, 'LatLonPoint');            
+};
+
+mxn.addProxyMethods(LatLonPoint, [ 
+       'fromProprietary', 'toProprietary'
+], true);
+
+/**
+ * toString returns a string represntation of a point
+ * @returns a string like '51.23, -0.123'
+ * @type String
+ */
+LatLonPoint.prototype.toString = function() {
+       return this.lat + ', ' + this.lon;
+};
+
+/**
+ * distance returns the distance in kilometers between two points
+ * @param {LatLonPoint} otherPoint The other point to measure the distance from to this one
+ * @returns the distance between the points in kilometers
+ * @type double
+ */
+LatLonPoint.prototype.distance = function(otherPoint) {
+       // Uses Haversine formula from http://www.movable-type.co.uk
+       var rads = Math.PI / 180;
+       var diffLat = (this.lat-otherPoint.lat) * rads;
+       var diffLon = (this.lon-otherPoint.lon) * rads; 
+       var a = Math.sin(diffLat / 2) * Math.sin(diffLat / 2) +
+               Math.cos(this.lat*rads) * Math.cos(otherPoint.lat*rads) * 
+               Math.sin(diffLon/2) * Math.sin(diffLon/2); 
+       return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) * 6371; // Earth's mean radius in km
+};
+
+/**
+ * equals tests if this point is the same as some other one
+ * @param {LatLonPoint} otherPoint The other point to test with
+ * @returns true or false
+ * @type boolean
+ */
+LatLonPoint.prototype.equals = function(otherPoint) {
+       return this.lat == otherPoint.lat && this.lon == otherPoint.lon;
+};
+
+/**
+ * Returns latitude conversion based on current projection
+ * @returns {Float} conversion
+ */
+LatLonPoint.prototype.latConv = function() {
+       return this.distance(new LatLonPoint(this.lat + 0.1, this.lon))*10;
+};
+
+/**
+ * Returns longitude conversion based on current projection
+ * @returns {Float} conversion
+ */
+LatLonPoint.prototype.lonConv = function() {
+       return this.distance(new LatLonPoint(this.lat, this.lon + 0.1))*10;
+};
+
+
+//////////////////////////
+//
+//  BoundingBox
+//
+//////////////////////////
+
+/**
+ * BoundingBox creates a new bounding box object
+ * @name mxn.BoundingBox
+ * @constructor
+ * @param {double} swlat the latitude of the south-west point
+ * @param {double} swlon the longitude of the south-west point
+ * @param {double} nelat the latitude of the north-east point
+ * @param {double} nelon the longitude of the north-east point
+ * @exports BoundingBox as mxn.BoundingBox
+ */
+var BoundingBox = mxn.BoundingBox = function(swlat, swlon, nelat, nelon) {
+       //FIXME throw error if box bigger than world
+       //alert('new bbox ' + swlat + ',' +  swlon + ',' +  nelat + ',' + nelon);
+       this.sw = new LatLonPoint(swlat, swlon);
+       this.ne = new LatLonPoint(nelat, nelon);
+};
+
+/**
+ * getSouthWest returns a LatLonPoint of the south-west point of the bounding box
+ * @returns the south-west point of the bounding box
+ * @type LatLonPoint
+ */
+BoundingBox.prototype.getSouthWest = function() {
+       return this.sw;
+};
+
+/**
+ * getNorthEast returns a LatLonPoint of the north-east point of the bounding box
+ * @returns the north-east point of the bounding box
+ * @type LatLonPoint
+ */
+BoundingBox.prototype.getNorthEast = function() {
+       return this.ne;
+};
+
+/**
+ * isEmpty finds if this bounding box has zero area
+ * @returns whether the north-east and south-west points of the bounding box are the same point
+ * @type boolean
+ */
+BoundingBox.prototype.isEmpty = function() {
+       return this.ne == this.sw; // is this right? FIXME
+};
+
+/**
+ * contains finds whether a given point is within a bounding box
+ * @param {LatLonPoint} point the point to test with
+ * @returns whether point is within this bounding box
+ * @type boolean
+ */
+BoundingBox.prototype.contains = function(point){
+       return point.lat >= this.sw.lat && point.lat <= this.ne.lat && point.lon >= this.sw.lon && point.lon <= this.ne.lon;
+};
+
+/**
+ * toSpan returns a LatLonPoint with the lat and lon as the height and width of the bounding box
+ * @returns a LatLonPoint containing the height and width of this bounding box
+ * @type LatLonPoint
+ */
+BoundingBox.prototype.toSpan = function() {
+       return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );
+};
+
+/**
+ * extend extends the bounding box to include the new point
+ */
+BoundingBox.prototype.extend = function(point) {
+       if(this.sw.lat > point.lat) {
+               this.sw.lat = point.lat;
+       }
+       if(this.sw.lon > point.lon) {
+               this.sw.lon = point.lon;
+       }
+       if(this.ne.lat < point.lat) {
+               this.ne.lat = point.lat;
+       }
+       if(this.ne.lon < point.lon) {
+               this.ne.lon = point.lon;
+       }
+       return;
+};
+
+//////////////////////////////
+//
+//  Marker
+//
+///////////////////////////////
+
+/**
+ * Marker create's a new marker pin
+ * @name mxn.Marker
+ * @constructor
+ * @param {LatLonPoint} point the point on the map where the marker should go
+ * @exports Marker as mxn.Marker
+ */
+var Marker = mxn.Marker = function(point) {
+       this.api = null;
+       this.location = point;
+       this.onmap = false;
+       this.proprietary_marker = false;
+       this.attributes = [];
+       this.invoker = new mxn.Invoker(this, 'Marker', function(){return this.api;});
+       mxn.addEvents(this, [ 
+               'openInfoBubble',       // Info bubble opened
+               'closeInfoBubble',      // Info bubble closed
+               'click'                         // Marker clicked
+       ]);
+};
+
+mxn.addProxyMethods(Marker, [ 
+       'fromProprietary',
+       'hide',
+       'openBubble',
+       'show',
+       'toProprietary',
+       'update'
+]);
+
+Marker.prototype.setChild = function(some_proprietary_marker) {
+       this.proprietary_marker = some_proprietary_marker;
+       some_proprietary_marker.mapstraction_marker = this;
+       this.onmap = true;
+};
+
+Marker.prototype.setLabel = function(labelText) {
+       this.labelText = labelText;
+};
+
+/**
+ * addData conviniently set a hash of options on a marker
+ */
+Marker.prototype.addData = function(options){
+       for(var sOptKey in options) {
+               if(options.hasOwnProperty(sOptKey)){
+                       switch(sOptKey) {
+                               case 'label':
+                                       this.setLabel(options.label);
+                                       break;
+                               case 'infoBubble':
+                                       this.setInfoBubble(options.infoBubble);
+                                       break;
+                               case 'icon':
+                                       if(options.iconSize && options.iconAnchor) {
+                                               this.setIcon(options.icon, options.iconSize, options.iconAnchor);
+                                       }
+                                       else if(options.iconSize) {
+                                               this.setIcon(options.icon, options.iconSize);
+                                       }
+                                       else {
+                                               this.setIcon(options.icon);
+                                       }
+                                       break;
+                               case 'iconShadow':
+                                       if(options.iconShadowSize) {
+                                               this.setShadowIcon(options.iconShadow, [ options.iconShadowSize[0], options.iconShadowSize[1] ]);
+                                       }
+                                       else {
+                                               this.setIcon(options.iconShadow);
+                                       }
+                                       break;
+                               case 'infoDiv':
+                                       this.setInfoDiv(options.infoDiv[0],options.infoDiv[1]);
+                                       break;
+                               case 'draggable':
+                                       this.setDraggable(options.draggable);
+                                       break;
+                               case 'hover':
+                                       this.setHover(options.hover);
+                                       this.setHoverIcon(options.hoverIcon);
+                                       break;
+                               case 'hoverIcon':
+                                       this.setHoverIcon(options.hoverIcon);
+                                       break;
+                               case 'openBubble':
+                                       this.openBubble();
+                                       break;
+                               case 'groupName':
+                                       this.setGroupName(options.groupName);
+                                       break;
+                               default:
+                                       // don't have a specific action for this bit of
+                                       // data so set a named attribute
+                                       this.setAttribute(sOptKey, options[sOptKey]);
+                                       break;
+                       }
+               }
+       }
+};
+
+/**
+ * setInfoBubble sets the html/text content for a bubble popup for a marker
+ * @param {String} infoBubble the html/text you want displayed
+ */
+Marker.prototype.setInfoBubble = function(infoBubble) {
+       this.infoBubble = infoBubble;
+};
+
+/**
+ * setInfoDiv sets the text and the id of the div element where to the information
+ *  useful for putting information in a div outside of the map
+ * @param {String} infoDiv the html/text you want displayed
+ * @param {String} div the element id to use for displaying the text/html
+ */
+Marker.prototype.setInfoDiv = function(infoDiv,div){
+       this.infoDiv = infoDiv;
+       this.div = div;
+};
+
+/**
+ * setIcon sets the icon for a marker
+ * @param {String} iconUrl The URL of the image you want to be the icon
+ */
+Marker.prototype.setIcon = function(iconUrl, iconSize, iconAnchor) {
+       this.iconUrl = iconUrl;
+       if(iconSize) {
+               this.iconSize = iconSize;
+       }
+       if(iconAnchor) {
+               this.iconAnchor = iconAnchor;
+       }
+};
+
+/**
+ * setIconSize sets the size of the icon for a marker
+ * @param {String} iconSize The array size in pixels of the marker image
+ */
+Marker.prototype.setIconSize = function(iconSize){
+       if(iconSize) {
+               this.iconSize = iconSize;
+       }
+};
+
+/**
+ * setIconAnchor sets the anchor point for a marker
+ * @param {String} iconAnchor The array offset of the anchor point
+ */
+Marker.prototype.setIconAnchor = function(iconAnchor){
+       if(iconAnchor) {
+               this.iconAnchor = iconAnchor;
+       }
+};
+
+/**
+ * setShadowIcon sets the icon for a marker
+ * @param {String} iconUrl The URL of the image you want to be the icon
+ */
+Marker.prototype.setShadowIcon = function(iconShadowUrl, iconShadowSize){
+       this.iconShadowUrl = iconShadowUrl;
+       if(iconShadowSize) {
+               this.iconShadowSize = iconShadowSize;
+       }
+};
+
+Marker.prototype.setHoverIcon = function(hoverIconUrl){
+       this.hoverIconUrl = hoverIconUrl;
+};
+
+/**
+ * setDraggable sets the draggable state of the marker
+ * @param {Bool} draggable set to true if marker should be draggable by the user
+ */
+Marker.prototype.setDraggable = function(draggable) {
+       this.draggable = draggable;
+};
+
+/**
+ * setHover sets that the marker info is displayed on hover
+ * @param {Bool} hover set to true if marker should display info on hover
+ */
+Marker.prototype.setHover = function(hover) {
+       this.hover = hover;
+};
+
+/**
+ * Markers are grouped up by this name. declutterGroup makes use of this.
+ */
+Marker.prototype.setGroupName = function(sGrpName) {
+       this.groupName = sGrpName;
+};
+
+/**
+ * setAttribute: set an arbitrary key/value pair on a marker
+ * @arg(String) key
+ * @arg value
+ */
+Marker.prototype.setAttribute = function(key,value) {
+       this.attributes[key] = value;
+};
+
+/**
+ * getAttribute: gets the value of "key"
+ * @arg(String) key
+ * @returns value
+ */
+Marker.prototype.getAttribute = function(key) {
+       return this.attributes[key];
+};
+
+
+///////////////
+// Polyline ///
+///////////////
+
+/**
+ * Instantiates a new Polyline.
+ * @name mxn.Polyline
+ * @constructor
+ * @param {Point[]} points Points that make up the Polyline.
+ * @exports Polyline as mxn.Polyline
+ */
+var Polyline = mxn.Polyline = function(points) {
+       this.api = null;
+       this.points = points;
+       this.attributes = [];
+       this.onmap = false;
+       this.proprietary_polyline = false;
+       this.pllID = "mspll-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));
+       this.invoker = new mxn.Invoker(this, 'Polyline', function(){return this.api;});
+};
+
+mxn.addProxyMethods(Polyline, [ 
+       'fromProprietary', 
+       'hide',
+       'show',
+       'toProprietary',
+       'update'
+]);
+
+/**
+ * addData conviniently set a hash of options on a polyline
+ */
+Polyline.prototype.addData = function(options){
+       for(var sOpt in options) {
+               if(options.hasOwnProperty(sOpt)){
+                       switch(sOpt) {
+                               case 'color':
+                                       this.setColor(options.color);
+                                       break;
+                               case 'width':
+                                       this.setWidth(options.width);
+                                       break;
+                               case 'opacity':
+                                       this.setOpacity(options.opacity);
+                                       break;
+                               case 'closed':
+                                       this.setClosed(options.closed);
+                                       break;
+                               case 'fillColor':
+                                       this.setFillColor(options.fillColor);
+                                       break;
+                               default:
+                                       this.setAttribute(sOpt, options[sOpt]);
+                                       break;
+                       }
+               }
+       }
+};
+
+Polyline.prototype.setChild = function(some_proprietary_polyline) {
+       this.proprietary_polyline = some_proprietary_polyline;
+       this.onmap = true;
+};
+
+/**
+ * in the form: #RRGGBB
+ * Note map24 insists on upper case, so we convert it.
+ */
+Polyline.prototype.setColor = function(color){
+       this.color = (color.length==7 && color[0]=="#") ? color.toUpperCase() : color;
+};
+
+/**
+ * Stroke width of the polyline
+ * @param {Integer} width
+ */
+Polyline.prototype.setWidth = function(width){
+       this.width = width;
+};
+
+/**
+ * A float between 0.0 and 1.0
+ * @param {Float} opacity
+ */
+Polyline.prototype.setOpacity = function(opacity){
+       this.opacity = opacity;
+};
+
+/**
+ * Marks the polyline as a closed polygon
+ * @param {Boolean} bClosed
+ */
+Polyline.prototype.setClosed = function(bClosed){
+       this.closed = bClosed;
+};
+
+/**
+ * Fill color for a closed polyline as HTML color value e.g. #RRGGBB
+ * @param {String} sFillColor HTML color value #RRGGBB
+ */
+Polyline.prototype.setFillColor = function(sFillColor) {
+       this.fillColor = sFillColor;
+};
+
+
+/**
+ * setAttribute: set an arbitrary key/value pair on a polyline
+ * @arg(String) key
+ * @arg value
+ */
+Polyline.prototype.setAttribute = function(key,value) {
+       this.attributes[key] = value;
+};
+
+/**
+ * getAttribute: gets the value of "key"
+ * @arg(String) key
+ * @returns value
+ */
+Polyline.prototype.getAttribute = function(key) {
+       return this.attributes[key];
+};
+
+/**
+ * Simplifies a polyline, averaging and reducing the points
+ * @param {Integer} tolerance (1.0 is a good starting point)
+ */
+Polyline.prototype.simplify = function(tolerance) {
+       var reduced = [];
+
+       // First point
+       reduced[0] = this.points[0];
+
+       var markerPoint = 0;
+
+       for (var i = 1; i < this.points.length-1; i++){
+               if (this.points[i].distance(this.points[markerPoint]) >= tolerance)
+               {
+                       reduced[reduced.length] = this.points[i];
+                       markerPoint = i;
+               }
+       }
+
+       // Last point
+       reduced[reduced.length] = this.points[this.points.length-1];
+
+       // Revert
+       this.points = reduced;
+};
+
+///////////////
+// Radius    //
+///////////////
+
+/**
+ * Creates a new radius object for drawing circles around a point, does a lot of initial calculation to increase load time
+ * @returns a new Radius
+ * @type Radius
+ * @constructor
+ * @classDescription Radius
+ * @param {Object} Center LatLonPoint of the radius
+ * @param {quality} Number of points that comprise the approximated circle (20 is a good starting point)
+ */
+var Radius = mxn.Radius = function(center, quality) {
+       this.center = center;
+       var latConv = center.latConv();
+       var lonConv = center.lonConv();
+
+       // Create Radian conversion constant
+       var rad = Math.PI / 180;
+       this.calcs = [];
+
+       for(var i = 0; i < 360; i += quality){
+           this.calcs.push([Math.cos(i * rad) / latConv, Math.sin(i * rad) / lonConv]);
+        }
+};
+
+/**
+ * Returns polyline of a circle around the point based on new radius
+ * @param {Radius} radius
+ * @param {Colour} colour
+ * @returns {Polyline} Polyline
+ */
+Radius.prototype.getPolyline = function(radius, colour) {
+        var points = [];
+
+       for(var i = 0; i < this.calcs.length; i++){
+               var point = new LatLonPoint(
+                       this.center.lat + (radius * this.calcs[i][0]),
+                       this.center.lon + (radius * this.calcs[i][1])
+               );
+               points.push(point);
+       }
+
+       // Add first point
+       points.push(points[0]);
+
+       var line = new Polyline(points);
+       line.setColor(colour);
+
+       return line;
+};
+
+
+})();
\ No newline at end of file
diff --git a/plugins/Mapstraction/js/mxn.geocommons.core.js b/plugins/Mapstraction/js/mxn.geocommons.core.js
new file mode 100644 (file)
index 0000000..08be811
--- /dev/null
@@ -0,0 +1,233 @@
+mxn.register('geocommons', {   
+
+    Mapstraction: {
+
+        init: function(element, api) {         
+            var me = this;
+            this.element = element;
+            Maker.maker_host='http://maker.geocommons.com';
+            Maker.finder_host='http://finder.geocommons.com';
+            Maker.core_host='http://geocommons.com';
+          },
+
+        applyOptions: function(){
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        resizeTo: function(width, height){     
+            var map = this.maps[this.api];
+            map.setSize(width,height);
+        },
+
+        addControls: function( args ) {
+            var map = this.maps[this.api];
+            map.showControl("Zoom", args.zoom || false);
+            map.showControl("Layers", args.layers || false);
+            map.showControl("Styles", args.styles || false); 
+            map.showControl("Basemap", args.map_type || false);
+            map.showControl("Legend", args.legend || false, "open"); 
+            // showControl("Legend", true, "close"); 
+        },
+
+        addSmallControls: function() {
+            var map = this.maps[this.api];
+            showControl("Zoom", args.zoom);
+            showControl("Legend", args.legend, "open"); 
+        },
+
+        addLargeControls: function() {
+            var map = this.maps[this.api];
+            showControl("Zoom", args.zoom);
+            showControl("Layers", args.layers);
+            showControl("Legend", args.legend, "open"); 
+        },
+
+        addMapTypeControls: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        dragging: function(on) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        setCenterAndZoom: function(point, zoom) { 
+            var map = this.maps[this.api];
+            map.setCenterZoom(point.lat, point.lon,zoom);
+        },
+
+        getCenter: function() {
+            var map = this.maps[this.api];
+            var point = map.getCenterZoom()[0];
+            return mxn.LatLonPoint(point.lat,point.lon);
+        },
+
+        setCenter: function(point, options) {
+            var map = this.maps[this.api];
+            map.setCenter(point.lat, point.lon);            
+        },
+
+        setZoom: function(zoom) {
+            var map = this.maps[this.api];
+            map.setZoom(zoom);
+        },
+
+        getZoom: function() {
+            var map = this.maps[this.api];
+            return map.getZoom();
+        },
+
+        getZoomLevelForBoundingBox: function( bbox ) {
+            var map = this.maps[this.api];
+            // NE and SW points from the bounding box.
+            var ne = bbox.getNorthEast();
+            var sw = bbox.getSouthWest();
+            var zoom;
+
+            // TODO: Add provider code
+
+            return zoom;
+        },
+
+        setMapType: function(type) {
+            var map = this.maps[this.api];
+            switch(type) {
+                case mxn.Mapstraction.ROAD:
+                map.setMapProvider("OpenStreetMap (road)");
+                break;
+                case mxn.Mapstraction.SATELLITE:
+                map.setMapProvider("BlueMarble");
+                break;
+                case mxn.Mapstraction.HYBRID:
+                map.setMapProvider("Google Hybrid");
+                break;
+                default:
+                map.setMapProvider(type);
+            }   
+        },
+
+        getMapType: function() {
+            var map = this.maps[this.api];
+            switch(map.getMapProvider) {
+                case "OpenStreetMap (Road)":
+                    retu
+                    
+            }
+            // TODO: Add provider code
+
+            //return mxn.Mapstraction.ROAD;
+            //return mxn.Mapstraction.SATELLITE;
+            //return mxn.Mapstraction.HYBRID;
+
+        },
+
+        getBounds: function () {
+            var map = this.maps[this.api];
+            var extent = map.getExtent();
+            return new mxn.BoundingBox( extent.northWest.lat, extent.southEast.lon, extent.southEast.lat, extent.northWest.lon);
+        },
+
+        setBounds: function(bounds){
+            var map = this.maps[this.api];
+            var sw = bounds.getSouthWest();
+            var ne = bounds.getNorthEast();
+            map.setExtent(ne.lat,sw.lat,ne.lon,sw.lon);
+
+        },
+
+        addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        addOverlay: function(url, autoCenterAndZoom) {
+            var map = this.maps[this.api];
+            var me = this;
+            Maker.load_map(this.element.id, url);
+            setTimeout(function() { me.maps[me.api] = swfobject.getObjectById(FlashMap.dom_id);}, 500);
+        },
+
+        addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        toggleTileLayer: function(tile_url) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        getPixelRatio: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        },
+
+        mousePosition: function(element) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        }
+    },
+
+    LatLonPoint: {
+
+        toProprietary: function() {
+            // TODO: Add provider code
+        },
+
+        fromProprietary: function(googlePoint) {
+            // TODO: Add provider code
+        }
+
+    },
+
+    Marker: {
+
+        toProprietary: function() {
+            // TODO: Add provider code
+        },
+
+        openBubble: function() {               
+            // TODO: Add provider code
+        },
+
+        hide: function() {
+            // TODO: Add provider code
+        },
+
+        show: function() {
+            // TODO: Add provider code
+        },
+
+        update: function() {
+            // TODO: Add provider code
+        }
+
+    },
+
+    Polyline: {
+
+        toProprietary: function() {
+            // TODO: Add provider code
+        },
+
+        show: function() {
+            // TODO: Add provider code
+        },
+
+        hide: function() {
+            // TODO: Add provider code
+        }
+
+    }
+
+});
\ No newline at end of file
diff --git a/plugins/Mapstraction/js/mxn.google.core.js b/plugins/Mapstraction/js/mxn.google.core.js
new file mode 100644 (file)
index 0000000..17e4415
--- /dev/null
@@ -0,0 +1,519 @@
+mxn.register('google', {       \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element,api) {           \r
+               var me = this;\r
+               if (GMap2) {\r
+                       if (GBrowserIsCompatible()) {\r
+                               this.maps[api] = new GMap2(element);\r
+\r
+                               GEvent.addListener(this.maps[api], 'click', function(marker,location) {\r
+                                       \r
+                                       if ( marker && marker.mapstraction_marker ) {\r
+                                               marker.mapstraction_marker.click.fire();\r
+                                       }\r
+                                       else if ( location ) {\r
+                                               me.click.fire({'location': new mxn.LatLonPoint(location.y, location.x)});\r
+                                       }\r
+                                       \r
+                                       // If the user puts their own Google markers directly on the map\r
+                                       // then there is no location and this event should not fire.\r
+                                       if ( location ) {\r
+                                               me.clickHandler(location.y,location.x,location,me);\r
+                                       }\r
+                               });\r
+\r
+                               GEvent.addListener(this.maps[api], 'moveend', function() {\r
+                                       me.moveendHandler(me);\r
+                                       me.endPan.fire();\r
+                               });\r
+                               \r
+                               GEvent.addListener(this.maps[api], 'zoomend', function() {\r
+                                       me.changeZoom.fire();\r
+                               });\r
+                               \r
+                               this.loaded[api] = true;\r
+                               me.load.fire();\r
+                       }\r
+                       else {\r
+                               alert('browser not compatible with Google Maps');\r
+                       }\r
+               }\r
+               else {\r
+                       alert(api + ' map script not imported');\r
+               }         \r
+       },\r
+       \r
+       applyOptions: function(){\r
+               var map = this.maps[this.api];\r
+               \r
+               if(this.options.enableScrollWheelZoom){\r
+                       map.enableContinuousZoom();\r
+                       map.enableScrollWheelZoom();\r
+               }\r
+               \r
+               if (this.options.enableDragging) {\r
+                       map.enableDragging();\r
+               } else {\r
+                       map.disableDragging();\r
+               }\r
+               \r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+               this.currentElement.style.width = width;\r
+               this.currentElement.style.height = height;\r
+               this.maps[this.api].checkResize(); \r
+       },\r
+\r
+       addControls: function( args ) {\r
+               var map = this.maps[this.api];\r
+       \r
+               // remove old controls\r
+               if (this.controls) {\r
+                       while ((ctl = this.controls.pop())) {\r
+                               // Google specific method\r
+                               map.removeControl(ctl);\r
+                       }\r
+               } else {\r
+                       this.controls = [];\r
+                }\r
+                c = this.controls;\r
\r
+               // Google has a combined zoom and pan control.\r
+               if (args.zoom || args.pan) {\r
+                   if (args.zoom == 'large'){ \r
+                        this.addLargeControls();\r
+                    } else {\r
+                        this.addSmallControls();\r
+                    }\r
+               }\r
+\r
+               if (args.scale) {\r
+                    this.controls.unshift(new GScaleControl());\r
+                   map.addControl(this.controls[0]);\r
+                   this.addControlsArgs.scale = true;\r
+               }\r
+               \r
+               if (args.overview) {\r
+                        c.unshift(new GOverviewMapControl()); \r
+                        map.addControl(c[0]);\r
+                       this.addControlsArgs.overview = true;\r
+               }\r
+               if (args.map_type) {\r
+                       this.addMapTypeControls();\r
+               } \r
+       },\r
+\r
+       addSmallControls: function() {\r
+               var map = this.maps[this.api];\r
+                this.controls.unshift(new GSmallMapControl());\r
+               map.addControl(this.controls[0]);\r
+               this.addControlsArgs.zoom = 'small';\r
+               this.addControlsArgs.pan = true;\r
+       },\r
+\r
+       addLargeControls: function() {\r
+               var map = this.maps[this.api];                \r
+                this.controls.unshift(new GLargeMapControl());\r
+               map.addControl(this.controls[0]);\r
+               this.addControlsArgs.zoom = 'large';\r
+               this.addControlsArgs.pan = true;\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+               var map = this.maps[this.api];\r
+                this.controls.unshift(new GMapTypeControl());\r
+               map.addControl(this.controls[0]);\r
+               this.addControlsArgs.map_type = true;\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               map.setCenter(pt, zoom); \r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+               var map = this.maps[this.api];\r
+               var gpin = marker.toProprietary(this.api);\r
+               map.addOverlay(gpin);\r
+               \r
+               GEvent.addListener(gpin, 'infowindowopen', function() {\r
+                       marker.openInfoBubble.fire();\r
+               });\r
+               GEvent.addListener(gpin, 'infowindowclose', function() {\r
+                       marker.closeInfoBubble.fire();\r
+               });             \r
+               return gpin;\r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+               var map = this.maps[this.api];\r
+               map.removeOverlay(marker.proprietary_marker);\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];\r
+               // FIXME: got a feeling this doesn't only delete markers\r
+               map.clearOverlays();\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               gpolyline = polyline.toProprietary(this.api);\r
+               map.addOverlay(gpolyline);\r
+               return gpolyline;\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];\r
+               map.removeOverlay(polyline.proprietary_polyline);\r
+       },\r
+\r
+       getCenter: function() {\r
+               var map = this.maps[this.api];\r
+               var pt = map.getCenter();\r
+               var point = new mxn.LatLonPoint(pt.lat(),pt.lng());\r
+               return point;\r
+       },\r
+\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               if(options && options.pan) { \r
+                       map.panTo(pt); \r
+               }\r
+               else { \r
+                       map.setCenter(pt);\r
+               }\r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               map.setZoom(zoom);                        \r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               return map.getZoom();\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               var map = this.maps[this.api];\r
+               // NE and SW points from the bounding box.\r
+               var ne = bbox.getNorthEast();\r
+               var sw = bbox.getSouthWest();\r
+               var gbox = new GLatLngBounds( sw.toProprietary(this.api), ne.toProprietary(this.api) );\r
+               var zoom = map.getBoundsZoomLevel( gbox );\r
+               return zoom;\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                               map.setMapType(G_NORMAL_MAP);\r
+                               break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                               map.setMapType(G_SATELLITE_MAP);\r
+                               break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                               map.setMapType(G_HYBRID_MAP);\r
+                               break;\r
+                       default:\r
+                               map.setMapType(type || G_NORMAL_MAP);\r
+               }        \r
+       },\r
+\r
+       getMapType: function() {\r
+               var map = this.maps[this.api];\r
+               var type = map.getCurrentMapType();\r
+               switch(type) {\r
+                       case G_NORMAL_MAP:\r
+                               return mxn.Mapstraction.ROAD;\r
+                       case G_SATELLITE_MAP:\r
+                               return mxn.Mapstraction.SATELLITE;\r
+                       case G_HYBRID_MAP:\r
+                               return mxn.Mapstraction.HYBRID;\r
+                       default:\r
+                               return null;\r
+               }\r
+       },\r
+\r
+       getBounds: function () {\r
+               var map = this.maps[this.api];\r
+               var ne, sw, nw, se;\r
+               var gbox = map.getBounds();\r
+               sw = gbox.getSouthWest();\r
+               ne = gbox.getNorthEast();\r
+               return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest();\r
+               var ne = bounds.getNorthEast();\r
+               var gbounds = new GLatLngBounds(new GLatLng(sw.lat,sw.lon),new GLatLng(ne.lat,ne.lon));\r
+               map.setCenter(gbounds.getCenter(), map.getBoundsZoomLevel(gbounds)); \r
+       },\r
+\r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               var map = this.maps[this.api];\r
+               map.getPane(G_MAP_MAP_PANE).appendChild(oContext.imgElm);\r
+               this.setImageOpacity(id, opacity);\r
+               this.setImagePosition(id);\r
+               GEvent.bind(map, "zoomend", this, function() {\r
+                       this.setImagePosition(id);\r
+               });\r
+               GEvent.bind(map, "moveend", this, function() {\r
+                       this.setImagePosition(id);\r
+               });\r
+       },\r
+\r
+       setImagePosition: function(id, oContext) {\r
+               var map = this.maps[this.api];\r
+               var topLeftPoint; var bottomRightPoint;\r
+\r
+               topLeftPoint = map.fromLatLngToDivPixel( new GLatLng(oContext.latLng.top, oContext.latLng.left) );\r
+               bottomRightPoint = map.fromLatLngToDivPixel( new GLatLng(oContext.latLng.bottom, oContext.latLng.right) );\r
+               \r
+               oContext.pixels.top = topLeftPoint.y;\r
+               oContext.pixels.left = topLeftPoint.x;\r
+               oContext.pixels.bottom = bottomRightPoint.y;\r
+               oContext.pixels.right = bottomRightPoint.x;\r
+       },\r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+               var geoXML = new GGeoXml(url);\r
+               map.addOverlay(geoXML, function() {\r
+                       if(autoCenterAndZoom) {\r
+                               geoXML.gotoDefaultViewport(map);\r
+                       }\r
+               });\r
+       },\r
+\r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {\r
+               var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)), 0, "copyleft");\r
+               var copyrightCollection = new GCopyrightCollection(copyright_text);\r
+               copyrightCollection.addCopyright(copyright);\r
+               var tilelayers = [];\r
+               tilelayers[0] = new GTileLayer(copyrightCollection, min_zoom, max_zoom);\r
+               tilelayers[0].isPng = function() {\r
+                       return true;\r
+               };\r
+               tilelayers[0].getOpacity = function() {\r
+                       return opacity;\r
+               };\r
+               tilelayers[0].getTileUrl = function (a, b) {\r
+                       url = tile_url;\r
+                       url = url.replace(/\{Z\}/g,b);\r
+                       url = url.replace(/\{X\}/g,a.x);\r
+                       url = url.replace(/\{Y\}/g,a.y);\r
+                       return url;\r
+               };\r
+               if(map_type) {\r
+            var tileLayerOverlay = new GMapType(tilelayers, new GMercatorProjection(19), copyright_text, {\r
+                errorMessage:"More "+copyright_text+" tiles coming soon"\r
+            });        \r
+            this.maps[this.api].addMapType(tileLayerOverlay);\r
+        } else {\r
+            tileLayerOverlay = new GTileLayerOverlay(tilelayers[0]);\r
+            this.maps[this.api].addOverlay(tileLayerOverlay);\r
+        }              \r
+               this.tileLayers.push( [tile_url, tileLayerOverlay, true] );\r
+               return tileLayerOverlay;\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               for (var f=0; f<this.tileLayers.length; f++) {\r
+                       if(this.tileLayers[f][0] == tile_url) {\r
+                               if(this.tileLayers[f][2]) {\r
+                                       this.maps[this.api].removeOverlay(this.tileLayers[f][1]);\r
+                                       this.tileLayers[f][2] = false;\r
+                               }\r
+                               else {\r
+                                       this.maps[this.api].addOverlay(this.tileLayers[f][1]);\r
+                                       this.tileLayers[f][2] = true;\r
+                               }\r
+                       }\r
+               }          \r
+       },\r
+\r
+       getPixelRatio: function() {\r
+               var map = this.maps[this.api];\r
+\r
+               var projection = G_NORMAL_MAP.getProjection();\r
+               var centerPoint = map.getCenter();\r
+               var zoom = map.getZoom();\r
+               var centerPixel = projection.fromLatLngToPixel(centerPoint, zoom);\r
+               // distance is the distance in metres for 5 pixels (3-4-5 triangle)\r
+               var distancePoint = projection.fromPixelToLatLng(new GPoint(centerPixel.x + 3, centerPixel.y + 4), zoom);\r
+               //*1000(km to m), /5 (pythag), *2 (radius to diameter)\r
+               return 10000/distancePoint.distanceFrom(centerPoint);\r
+       \r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               var locDisp = document.getElementById(element);\r
+               if (locDisp !== null) {\r
+                       var map = this.maps[this.api];\r
+                       GEvent.addListener(map, 'mousemove', function (point) {\r
+                               var loc = point.lat().toFixed(4) + ' / ' + point.lng().toFixed(4);\r
+                               locDisp.innerHTML = loc;\r
+                       });\r
+                       locDisp.innerHTML = '0.0000 / 0.0000';\r
+               }\r
+       }\r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+               return new GLatLng(this.lat,this.lon);\r
+       },\r
+\r
+       fromProprietary: function(googlePoint) {\r
+               this.lat = googlePoint.lat();\r
+               this.lon = googlePoint.lng();\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               var infoBubble, event_action, infoDiv, div;\r
+               var options = {};\r
+               if(this.labelText){\r
+                       options.title =  this.labelText;\r
+               }\r
+               if(this.iconUrl){\r
+                       var icon = new GIcon(G_DEFAULT_ICON, this.iconUrl);\r
+                       icon.printImage = icon.mozPrintImage = icon.image;\r
+                       if(this.iconSize) {\r
+                               icon.iconSize = new GSize(this.iconSize[0], this.iconSize[1]);\r
+                               var anchor;\r
+                               if(this.iconAnchor) {\r
+                                       anchor = new GPoint(this.iconAnchor[0], this.iconAnchor[1]);\r
+                               }\r
+                               else {\r
+                                       // FIXME: hard-coding the anchor point\r
+                                       anchor = new GPoint(this.iconSize[0]/2, this.iconSize[1]/2);\r
+                               }\r
+                               icon.iconAnchor = anchor;\r
+                       }\r
+                       if(typeof(this.iconShadowUrl) != 'undefined') {\r
+                               icon.shadow = this.iconShadowUrl;\r
+                               if(this.iconShadowSize) {\r
+                                       icon.shadowSize = new GSize(this.iconShadowSize[0], this.iconShadowSize[1]);\r
+                               }\r
+                       } else {  // turn off shadow\r
+                               icon.shadow = '';\r
+                                icon.shadowSize = '';\r
+                        }\r
+                       if(this.transparent) {\r
+                               icon.transparent = this.transparent;\r
+                        }\r
+                       if(this.imageMap) {\r
+                               icon.imageMap = this.imageMap;\r
+                        }\r
+                       options.icon = icon;\r
+               }\r
+               if(this.draggable){\r
+                       options.draggable = this.draggable;\r
+               }\r
+               var gmarker = new GMarker( this.location.toProprietary('google'),options);\r
+                               \r
+               if(this.infoBubble){\r
+                       infoBubble = this.infoBubble;\r
+                       if(this.hover) {\r
+                               event_action = "mouseover";\r
+                       }\r
+                       else {\r
+                               event_action = "click";\r
+                       }\r
+                       GEvent.addListener(gmarker, event_action, function() {\r
+                               gmarker.openInfoWindowHtml(infoBubble, {\r
+                                       maxWidth: 100\r
+                               });\r
+                       });\r
+               }\r
+\r
+               if(this.hoverIconUrl){\r
+                       GEvent.addListener(gmarker, "mouseover", function() {\r
+                               gmarker.setImage(this.hoverIconUrl);\r
+                       });\r
+                       GEvent.addListener(gmarker, "mouseout", function() {\r
+                               gmarker.setImage(this.iconUrl);\r
+                       });\r
+               }\r
+\r
+               if(this.infoDiv){\r
+                       infoDiv = this.infoDiv;\r
+                       div = this.div;\r
+                       if(this.hover) {\r
+                               event_action = "mouseover";\r
+                       }\r
+                       else {\r
+                               event_action = "click";\r
+                       }\r
+                       GEvent.addListener(gmarker, event_action, function() {\r
+                               document.getElementById(div).innerHTML = infoDiv;\r
+                       });\r
+               }\r
+\r
+               return gmarker;\r
+       },\r
+\r
+       openBubble: function() {\r
+               var gpin = this.proprietary_marker;\r
+               gpin.openInfoWindowHtml(this.infoBubble);\r
+       },\r
+\r
+       hide: function() {\r
+               this.proprietary_marker.hide();\r
+       },\r
+\r
+       show: function() {\r
+               this.proprietary_marker.show();\r
+       },\r
+\r
+       update: function() {\r
+               point = new mxn.LatLonPoint();\r
+               point.fromGoogle(this.proprietary_marker.getPoint());\r
+               this.location = point;\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {\r
+               var gpoints = [];\r
+               for (var i = 0,  length = this.points.length ; i< length; i++){\r
+                       gpoints.push(this.points[i].toProprietary('google'));\r
+               }\r
+               if (this.closed || gpoints[0].equals(gpoints[length-1])) {\r
+                       return new GPolygon(gpoints, this.color, this.width, this.opacity, this.fillColor || "#5462E3", this.opacity || "0.3");\r
+               } else {\r
+                       return new GPolyline(gpoints, this.color, this.width, this.opacity);\r
+               }\r
+       },\r
+       \r
+       show: function() {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       hide: function() {\r
+               throw 'Not implemented';\r
+       }\r
+}\r
+\r
+});\r
diff --git a/plugins/Mapstraction/js/mxn.google.geocoder.js b/plugins/Mapstraction/js/mxn.google.geocoder.js
new file mode 100644 (file)
index 0000000..5119c00
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+   Copyright (c) 2007, Andrew Turner
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the Mapstraction nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// Use http://jsdoc.sourceforge.net/ to generate documentation
+
+// TODO: add reverse geocoding support
+
+/**
+ * MapstractionGeocoder instantiates a geocoder with some API choice
+ * @param {Function} callback The function to call when a geocode request returns (function(waypoint))
+ * @param {String} api The API to use, currently only 'mapquest' is supported
+ * @param {Function} error_callback The optional function to call when a geocode request fails
+ * @constructor
+ */
+function MapstractionGeocoder(callback, api, error_callback) {
+  this.api = api;
+       this.callback = callback;
+       this.geocoders = new Object();
+       if(error_callback == null) {
+               this.error_callback = this.geocode_error
+       } else {
+               this.error_callback = error_callback;
+       }
+
+  // This is so that it is easy to tell which revision of this file 
+  // has been copied into other projects.
+  this.svn_revision_string = '$Revision: 107 $';
+
+  this.addAPI(api);
+
+}
+
+
+/**
+ * Internal function to actually set the router specific parameters
+ */
+MapstractionGeocoder.prototype.addAPI = function(api) { 
+
+  me = this;
+  switch (api) {
+               case 'google':
+                       this.geocoders[api] = new GClientGeocoder();
+                       break;
+    case 'mapquest':
+                       //set up the connection to the geocode server
+                       var proxyServerName = "";
+                       var proxyServerPort = "";
+                       var ProxyServerPath = "mapquest_proxy/JSReqHandler.php";
+
+                       var serverName = "geocode.access.mapquest.com";
+                       var serverPort = "80";
+                       var serverPath = "mq";
+                       this.geocoders[api] = new MQExec(serverName, serverPath, serverPort, proxyServerName,
+                               ProxyServerPath, proxyServerPort );
+                               
+      break;
+    default:
+      alert(api + ' not supported by mapstraction-geocoder');
+  }
+}
+/**
+ * Change the Routing API to use
+ * @param {String} api The API to swap to
+ */
+MapstractionGeocoder.prototype.swap = function(api) {
+  if (this.api == api) { return; }
+
+  this.api = api;
+  if (this.geocoders[this.api] == undefined) {
+    this.addAPI($(element),api);
+  }
+}
+
+/**
+ * Default Geocode error function
+ */
+MapstractionGeocoder.prototype.geocode_error = function(response) { 
+       alert("Sorry, we were unable to geocode that address");
+}
+
+/**
+ * Default handler for geocode request completion
+ */
+MapstractionGeocoder.prototype.geocode_callback = function(response, mapstraction_geocoder) { 
+  var return_location = new Object();
+       
+       // TODO: what if the api is switched during a geocode request?
+       // TODO: provide an option error callback
+       switch (mapstraction_geocoder.api) {
+               case 'google':
+               if (!response || response.Status.code != 200) {
+               mapstraction_geocoder.error_callback(response);
+                       } else {
+                               return_location.street = "";
+                               return_location.locality = "";
+                               return_location.region = "";
+                               return_location.country = "";
+
+                               var place = response.Placemark[0];
+                               if(place.AddressDetails.Country.AdministrativeArea != null) {
+                                       return_location.region = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
+                                       
+                                       if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null) {
+                                               if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null) {
+                                                       return_location.locality = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
+
+                                                       if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare != null)
+                                                               return_location.street = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
+                                               }
+                                               
+                                       }
+                                       
+                               }
+                               return_location.country = place.AddressDetails.Country.CountryNameCode;
+                        return_location.address = place.address;       
+
+                return_location.point = new mxn.LatLonPoint(place.Point.coordinates[1],
+                    place.Point.coordinates[0]);
+                    mapstraction_geocoder.callback(return_location);
+                }
+                       break;
+               case 'mapquest':
+                       break;
+       }
+}
+
+
+/**
+ * Performs a geocoding and then calls the specified callback function with the location
+ * @param {Object} address The address object to geocode
+ */
+ MapstractionGeocoder.prototype.geocode = function(address) { 
+     var return_location = new Object();
+
+     // temporary variable for later using in function closure
+     var mapstraction_geocoder = this;
+
+     switch (this.api) {
+         case 'google':
+         if (address.address == null || address.address == "")
+         address.address = address.street + ", " + address.locality + ", " + address.region + ", " + address.country
+         this.geocoders[this.api].getLocations(address.address, function(response) { mapstraction_geocoder.geocode_callback(response, mapstraction_geocoder); });
+         break;
+         case 'mapquest':
+         var mqaddress = new MQAddress();
+         var gaCollection = new MQLocationCollection("MQGeoAddress");
+         //populate the address object with the information from the form
+         mqaddress.setStreet(address.street);
+         mqaddress.setCity(address.locality);
+         mqaddress.setState(address.region);
+         mqaddress.setPostalCode(address.postalcode);
+         mqaddress.setCountry(address.country);
+
+         this.geocoders[this.api].geocode(mqaddress, gaCollection);
+         var geoAddr = gaCollection.get(0);
+         var mqpoint = geoAddr.getMQLatLng();
+         return_location.street = geoAddr.getStreet();
+         return_location.locality = geoAddr.getCity();
+         return_location.region = geoAddr.getState();
+         return_location.country = geoAddr.getCountry();
+         return_location.point = new mxn.LatLonPoint(mqpoint.getLatitude(), mqpoint.getLongitude());
+         this.callback(return_location, this);
+         break;
+         default:
+         alert(api + ' not supported by mapstraction-geocoder');
+         break;
+     }
+ }
diff --git a/plugins/Mapstraction/js/mxn.googlev3.core.js b/plugins/Mapstraction/js/mxn.googlev3.core.js
new file mode 100644 (file)
index 0000000..7ca07ec
--- /dev/null
@@ -0,0 +1,443 @@
+mxn.register('googlev3', {     \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element, api){           \r
+           var me = this;         \r
+            if ( google && google.maps ){\r
+                // by default no controls and road map\r
+                var myOptions = {\r
+                               disableDefaultUI: true,\r
+                    mapTypeId: google.maps.MapTypeId.ROADMAP\r
+                };\r
+                var map = new google.maps.Map(element, myOptions);\r
+                \r
+                // deal with click\r
+                google.maps.event.addListener(map, 'click', function(location){\r
+                               me.clickHandler(location.latLng.lat(),location.latLng.lng(),location,me);\r
+                });\r
+\r
+                // deal with zoom change\r
+                google.maps.event.addListener(map, 'zoom_changed', function(){\r
+                    me.changeZoom.fire();\r
+               });\r
+                // deal with map movement\r
+               google.maps.event.addListener(map, 'dragend', function(){\r
+                    me.moveendHandler(me);\r
+                    me.endPan.fire();\r
+               });\r
+                this.maps[api] = map;\r
+                this.loaded[api] = true;\r
+                me.load.fire();\r
+           }\r
+            else {\r
+                alert(api + ' map script not imported');\r
+            }\r
+       },\r
+       \r
+       applyOptions: function(){\r
+           var map = this.maps[this.api];\r
+           var myOptions = [];\r
+            if (this.options.enableDragging) {\r
+               myOptions.draggable = true;\r
+            } \r
+            if (this.options.enableScrollWheelZoom){\r
+               myOptions.scrollwheel = true;\r
+            } \r
+           map.setOptions(myOptions);\r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+            this.currentElement.style.width = width;\r
+            this.currentElement.style.height = height;\r
+            var map = this.maps[this.api];\r
+            google.maps.event.trigger(map,'resize');\r
+       },\r
+\r
+       addControls: function( args ) {\r
+           var map = this.maps[this.api];      \r
+            // remove old controls\r
+\r
+            // Google has a combined zoom and pan control.\r
+            if (args.zoom || args.pan) {\r
+                if (args.zoom == 'large'){ \r
+                    this.addLargeControls();\r
+                } else { \r
+                    this.addSmallControls();\r
+                }\r
+            }\r
+            if (args.scale){\r
+                var myOptions = {\r
+                    scaleControl:true,\r
+                   scaleControlOptions: {style:google.maps.ScaleControlStyle.DEFAULT}                \r
+                };\r
+                map.setOptions(myOptions);\r
+                this.addControlsArgs.scale = true;\r
+            }\r
+       },\r
+\r
+       addSmallControls: function() {\r
+            var map = this.maps[this.api];\r
+            var myOptions = {\r
+               navigationControl: true,\r
+               navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}\r
+            };\r
+            map.setOptions(myOptions);\r
+\r
+            this.addControlsArgs.pan = false;\r
+            this.addControlsArgs.scale = false;                        \r
+            this.addControlsArgs.zoom = 'small';\r
+       },\r
+\r
+       addLargeControls: function() {\r
+           var map = this.maps[this.api];\r
+            var myOptions = {\r
+                navigationControl:true,\r
+               navigationControlOptions: {style:google.maps.NavigationControlStyle.DEFAULT}\r
+            };\r
+            map.setOptions(myOptions);\r
+            this.addControlsArgs.pan = true;\r
+            this.addControlsArgs.zoom = 'large';\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+           var map = this.maps[this.api];\r
+            var myOptions = {\r
+                mapTypeControl: true,\r
+                mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT}\r
+            };\r
+            map.setOptions(myOptions);\r
+           this.addControlsArgs.map_type = true;\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               map.setCenter(pt);\r
+                map.setZoom(zoom);\r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+              return marker.toProprietary(this.api);           \r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+                // doesn't really remove them, just hides them\r
+                marker.hide();\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];          \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               var map = this.maps[this.api];\r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               return polyline.toProprietary(this.api);\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];          \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       getCenter: function() {\r
+               var map = this.maps[this.api];\r
+                var pt = map.getCenter();\r
+                return new mxn.LatLonPoint(pt.lat(),pt.lng());\r
+       },\r
+\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               if(options && options.pan) { \r
+                    map.panTo(pt);\r
+               }\r
+               else { \r
+                    map.setCenter(pt);\r
+               }\r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               map.setZoom(zoom);\r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               return map.getZoom();\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               var map = this.maps[this.api];\r
+               var sw = bbox.getSouthWest().toProprietary(this.api);\r
+               var ne = bbox.getNorthEast().toProprietary(this.api);\r
+               var gLatLngBounds = new google.maps.LatLngBounds(sw, ne);\r
+               map.fitBounds(gLatLngBounds);\r
+                return map.getZoom();\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                            map.setMapTypeId(google.maps.MapTypeId.ROADMAP);\r
+                           break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                            map.setMapTypeId(google.maps.MapTypeId.SATELLITE);\r
+                           break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                            map.setMapTypeId(google.maps.MapTypeId.HYBRID);\r
+                           break;\r
+                       default:\r
+                            map.setMapTypeId(google.maps.MapTypeId.ROADMAP);\r
+               }        \r
+       },\r
+\r
+       getMapType: function() {\r
+            var map = this.maps[this.api];\r
+            var type = map.getMapTypeId();\r
+                switch(type) {\r
+                        case google.maps.MapTypeId.ROADMAP:\r
+                                return mxn.Mapstraction.ROAD;\r
+                        case google.maps.MapTypeId.SATELLITE:\r
+                                return mxn.Mapstraction.SATELLITE;\r
+                        case google.maps.MapTypeId.HYBRID:\r
+                                return mxn.Mapstraction.HYBRID;\r
+                        //case google.maps.MapTypeId.TERRAIN:\r
+                        //        return something;\r
+                        default:\r
+                                return null;\r
+                }\r
+       },\r
+\r
+       getBounds: function () {\r
+           var map = this.maps[this.api];\r
+           var gLatLngBounds = map.getBounds();        \r
+            var sw = gLatLngBounds.getSouthWest();\r
+            var ne = gLatLngBounds.getNorthEast();\r
+            return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest().toProprietary(this.api);\r
+               var ne = bounds.getNorthEast().toProprietary(this.api);\r
+               var gLatLngBounds = new google.maps.LatLngBounds(sw, ne);\r
+               map.fitBounds(gLatLngBounds);\r
+       },\r
+\r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       setImagePosition: function(id, oContext) {\r
+               var map = this.maps[this.api];\r
+               var topLeftPoint; var bottomRightPoint;\r
+\r
+               // TODO: Add provider code\r
+\r
+               //oContext.pixels.top = ...;\r
+               //oContext.pixels.left = ...;\r
+               //oContext.pixels.bottom = ...;\r
+               //oContext.pixels.right = ...;\r
+       },\r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+               \r
+       },\r
+\r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom, map_type) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       getPixelRatio: function() {\r
+               var map = this.maps[this.api];\r
+\r
+               // TODO: Add provider code      \r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               var map = this.maps[this.api];\r
+\r
+               // TODO: Add provider code      \r
+       }\r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+            return new google.maps.LatLng(this.lat, this.lon);\r
+       },\r
+\r
+       fromProprietary: function(googlePoint) {\r
+               this.lat = googlePoint.lat();\r
+               this.lon = googlePoint.lng();\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               var options = {};\r
+\r
+                // do we have an Anchor?\r
+                var ax = 0;  // anchor x \r
+               var ay = 0;  // anchor y\r
+\r
+               if (this.iconAnchor) {\r
+                    ax = this.iconAnchor[0];\r
+                    ay = this.iconAnchor[1];\r
+                }\r
+                var gAnchorPoint = new google.maps.Point(ax,ay);\r
+\r
+               if (this.iconUrl) {\r
+                   options.icon = new google.maps.MarkerImage(\r
+                       this.iconUrl,\r
+                        new google.maps.Size(this.iconSize[0],\r
+                                            this.iconSize[1]),\r
+                        new google.maps.Point(0,0),\r
+                        gAnchorPoint\r
+                    );\r
+\r
+                    // do we have a Shadow?\r
+                   if (this.iconShadowUrl) {\r
+                       if (this.iconShadowSize) {\r
+                            var x = this.iconShadowSize[0];\r
+                            var y = this.iconShadowSize[1];\r
+                           options.shadow = new google.maps.MarkerImage(\r
+                               this.iconShadowUrl,\r
+                                new google.maps.Size(x,y),\r
+                                new google.maps.Point(0,0),\r
+                                gAnchorPoint \r
+                           );\r
+                       }\r
+                        else {\r
+                           options.shadow = new google.maps.MarkerImage(this.iconShadowUrl);\r
+                       }\r
+                   }\r
+               }\r
+               if (this.draggable){\r
+                   options.draggable = this.draggable;\r
+               }\r
+               if (this.labelText){\r
+                   options.title =  this.labelText;\r
+               }\r
+               if (this.imageMap){\r
+                    options.shape = {\r
+                        coord: this.imageMap,\r
+                        type: 'poly'\r
+                   };\r
+                }\r
+               \r
+               options.position = this.location.toProprietary(this.api);\r
+               options.map = this.map;\r
+\r
+               var marker = new google.maps.Marker(options);\r
+\r
+               if (this.infoBubble){\r
+                   var infowindow = new google.maps.InfoWindow({\r
+                       content: this.infoBubble\r
+                   });\r
+\r
+                    var event_action = "click";\r
+                   if (this.hover) {\r
+                       event_action = "mouseover";\r
+                   }\r
+                   google.maps.event.addListener(marker, event_action, function() { infowindow.open(this.map,marker); });\r
+               }\r
+\r
+                if (this.hoverIconUrl){\r
+                    var gSize = new google.maps.Size(this.iconSize[0],\r
+                                                   this.iconSize[1]);\r
+                    var zerozero = new google.maps.Point(0,0);\r
+                   var hIcon = new google.maps.MarkerImage(\r
+                       this.hoverIconUrl,\r
+                        gSize,\r
+                        zerozero,\r
+                        gAnchorPoint\r
+                    );\r
+                   var Icon = new google.maps.MarkerImage(\r
+                       this.iconUrl,\r
+                       gSize,\r
+                        zerozero,\r
+                        gAnchorPoint\r
+                    );\r
+                    google.maps.event.addListener(\r
+                        marker, \r
+                        "mouseover", \r
+                        function(){ \r
+                            marker.setIcon(hIcon); \r
+                        }\r
+                    );\r
+                    google.maps.event.addListener(\r
+                        marker, \r
+                        "mouseout", \r
+                        function(){ marker.setIcon(Icon); }\r
+                    );\r
+                }\r
+\r
+               google.maps.event.addListener(marker, 'click', function() {\r
+                       marker.mapstraction_marker.click.fire();\r
+               });\r
+               \r
+               return marker;\r
+       },\r
+\r
+       openBubble: function() {\r
+               var infowindow = new google.maps.InfoWindow({\r
+                       content: this.infoBubble\r
+           });\r
+           infowindow.open(this.map,this.proprietary_marker);\r
+       },\r
+\r
+       hide: function() {\r
+           this.proprietary_marker.setOptions({visible:false});\r
+       },\r
+\r
+       show: function() {\r
+           this.proprietary_marker.setOptions({visible:true});\r
+       },\r
+\r
+       update: function() {\r
+               // TODO: Add provider code\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {\r
+            throw 'Not implemented';\r
+       },\r
+       \r
+       show: function() {\r
+            throw 'Not implemented';\r
+       },\r
+\r
+       hide: function() {\r
+            throw 'Not implemented';\r
+       }\r
+       \r
+}\r
+\r
+});\r
diff --git a/plugins/Mapstraction/js/mxn.js b/plugins/Mapstraction/js/mxn.js
new file mode 100644 (file)
index 0000000..7ade41d
--- /dev/null
@@ -0,0 +1,505 @@
+// Auto-load scripts\r
+//\r
+// specify which map providers to load by using\r
+// <script src="mxn.js?(provider1,provider2,[module1,module2])" ...\r
+// in your HTML\r
+//\r
+// for each provider mxn.provider.module.js and mxn.module.js will be loaded\r
+// module 'core' is always loaded\r
+//\r
+// NOTE: if you call without providers\r
+// <script src="mxn.js" ...\r
+// no scripts will be loaded at all and it is then up to you to load the scripts independently\r
+(function() {\r
+       var providers = null;\r
+       var modules = 'core';\r
+       var scriptBase;\r
+       var scripts = document.getElementsByTagName('script');\r
+\r
+       // Determine which scripts we need to load      \r
+       for (var i = 0; i < scripts.length; i++) {\r
+               var match = scripts[i].src.replace(/%20/g , '').match(/^(.*?)mxn\.js(\?\(\[?(.*?)\]?\))?$/);\r
+               if (match != null) {\r
+                       scriptBase = match[1];\r
+                       if (match[3]) {\r
+                               var settings = match[3].split(',[');\r
+                               providers = settings[0].replace(']' , '');\r
+                               if (settings[1]) modules += ',' + settings[1];\r
+                       }\r
+                       break;\r
+          }\r
+       }\r
+       \r
+    if (providers == null || providers == 'none') return; // Bail out if no auto-load has been found\r
+       providers = providers.replace(/ /g, '').split(',');\r
+       modules = modules.replace(/ /g, '').split(',');\r
+\r
+       // Actually load the scripts\r
+       for (i = 0; i < modules.length; i++) {\r
+           document.write("<script type='text/javascript' src='" + scriptBase + 'mxn.' + modules[i] + '.js' + "'></script>");\r
+           for (var j = 0; j < providers.length; j++) document.write("<script type='text/javascript' src='" + scriptBase + 'mxn.' + providers[j] + '.' + modules[i] + '.js' + "'></script>");\r
+       }\r
+})();\r
+\r
+(function(){\r
+\r
+// holds all our implementing functions\r
+var apis = {};\r
+\r
+// Our special private methods\r
+/**\r
+ * Calls the API specific implementation of a particular method.\r
+ * @private\r
+ */\r
+var invoke = function(sApiId, sObjName, sFnName, oScope, args){\r
+       if(!hasImplementation(sApiId, sObjName, sFnName)) {\r
+               throw 'Method ' + sFnName + ' of object ' + sObjName + ' is not supported by API ' + sApiId + '. Are you missing a script tag?';\r
+       }\r
+       return apis[sApiId][sObjName][sFnName].apply(oScope, args);\r
+};\r
+       \r
+/**\r
+ * Determines whether the specified API provides an implementation for the \r
+ * specified object and function name.\r
+ * @private\r
+ */\r
+var hasImplementation = function(sApiId, sObjName, sFnName){\r
+       if(typeof(apis[sApiId]) == 'undefined') {\r
+               throw 'API ' + sApiId + ' not loaded. Are you missing a script tag?';\r
+       }\r
+       if(typeof(apis[sApiId][sObjName]) == 'undefined') {\r
+               throw 'Object definition ' + sObjName + ' in API ' + sApiId + ' not loaded. Are you missing a script tag?'; \r
+       }\r
+       return typeof(apis[sApiId][sObjName][sFnName]) == 'function';\r
+};\r
+\r
+/**\r
+ * @name mxn\r
+ * @namespace\r
+ */\r
+var mxn = window.mxn = /** @lends mxn */ {\r
+       \r
+       /**\r
+        * Registers a set of provider specific implementation functions.\r
+        * @function\r
+        * @param {String} sApiId The API ID to register implementing functions for.\r
+        * @param {Object} oApiImpl An object containing the API implementation.\r
+        */\r
+       register: function(sApiId, oApiImpl){\r
+               if(!apis.hasOwnProperty(sApiId)){\r
+                       apis[sApiId] = {};\r
+               }\r
+               mxn.util.merge(apis[sApiId], oApiImpl);\r
+       },              \r
+       \r
+       /**\r
+        * Adds a list of named proxy methods to the prototype of a \r
+        * specified constructor function.\r
+        * @function\r
+        * @param {Function} func Constructor function to add methods to\r
+        * @param {Array} aryMethods Array of method names to create\r
+        * @param {Boolean} bWithApiArg Optional. Whether the proxy methods will use an API argument\r
+        */\r
+       addProxyMethods: function(func, aryMethods, bWithApiArg){\r
+               for(var i = 0; i < aryMethods.length; i++) {\r
+                       var sMethodName = aryMethods[i];\r
+                       if(bWithApiArg){\r
+                               func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments, { overrideApi: true } );');\r
+                       }\r
+                       else {\r
+                               func.prototype[sMethodName] = new Function('return this.invoker.go(\'' + sMethodName + '\', arguments);');\r
+                       }\r
+               }\r
+       },\r
+       \r
+       /*\r
+       checkLoad: function(funcDetails){\r
+               if(this.loaded[this.api] === false) {\r
+                       var scope = this;\r
+                       this.onload[this.api].push( function() { funcDetails.callee.apply(scope, funcDetails); } );\r
+                       return true;\r
+               }\r
+               return false;\r
+       },\r
+       */\r
+                       \r
+       /**\r
+        * Bulk add some named events to an object.\r
+        * @function\r
+        * @param {Object} oEvtSrc The event source object.\r
+        * @param {String[]} aEvtNames Event names to add.\r
+        */\r
+       addEvents: function(oEvtSrc, aEvtNames){\r
+               for(var i = 0; i < aEvtNames.length; i++){\r
+                       var sEvtName = aEvtNames[i];\r
+                       if(sEvtName in oEvtSrc){\r
+                               throw 'Event or method ' + sEvtName + ' already declared.';\r
+                       }\r
+                       oEvtSrc[sEvtName] = new mxn.Event(sEvtName, oEvtSrc);\r
+               }\r
+       }\r
+       \r
+};\r
+\r
+/**\r
+ * Instantiates a new Event \r
+ * @constructor\r
+ * @param {String} sEvtName The name of the event.\r
+ * @param {Object} oEvtSource The source object of the event.\r
+ */\r
+mxn.Event = function(sEvtName, oEvtSource){\r
+       var handlers = [];\r
+       if(!sEvtName){\r
+               throw 'Event name must be provided';\r
+       }\r
+       /**\r
+        * Add a handler to the Event.\r
+        * @param {Function} fn The handler function.\r
+        * @param {Object} ctx The context of the handler function.\r
+        */\r
+       this.addHandler = function(fn, ctx){\r
+               handlers.push({context: ctx, handler: fn});\r
+       };\r
+       /**\r
+        * Remove a handler from the Event.\r
+        * @param {Function} fn The handler function.\r
+        * @param {Object} ctx The context of the handler function.\r
+        */\r
+       this.removeHandler = function(fn, ctx){\r
+               for(var i = 0; i < handlers.length; i++){\r
+                       if(handlers[i].handler == fn && handlers[i].context == ctx){\r
+                               handlers.splice(i, 1);\r
+                       }\r
+               }\r
+       };\r
+       /**\r
+        * Remove all handlers from the Event.\r
+        */\r
+       this.removeAllHandlers = function(){\r
+               handlers = [];\r
+       };\r
+       /**\r
+        * Fires the Event.\r
+        * @param {Object} oEvtArgs Event arguments object to be passed to the handlers.\r
+        */\r
+       this.fire = function(oEvtArgs){\r
+               var args = [sEvtName, oEvtSource, oEvtArgs];\r
+               for(var i = 0; i < handlers.length; i++){\r
+                       handlers[i].handler.apply(handlers[i].context, args);\r
+               }\r
+       };\r
+};\r
+\r
+/**\r
+ * Creates a new Invoker, a class which helps with on-the-fly \r
+ * invocation of the correct API methods.\r
+ * @constructor\r
+ * @param {Object} aobj The core object whose methods will make cals to go()\r
+ * @param {String} asClassName The name of the Mapstraction class to be invoked, normally the same name as aobj's constructor function\r
+ * @param {Function} afnApiIdGetter The function on object aobj which will return the active API ID\r
+ */\r
+mxn.Invoker = function(aobj, asClassName, afnApiIdGetter){\r
+       var obj = aobj;\r
+       var sClassName = asClassName;\r
+       var fnApiIdGetter = afnApiIdGetter;\r
+       var defOpts = { \r
+               overrideApi: false, // {Boolean} API ID is overridden by value in first argument\r
+               context: null, // {Object} Local vars can be passed from the body of the method to the API method within this object\r
+               fallback: null // {Function} If an API implementation doesn't exist this function is run instead\r
+       };\r
+       \r
+       /**\r
+        * Invoke the API implementation of a specific method.\r
+        * @param {String} sMethodName The method name to invoke\r
+        * @param {Array} args Arguments to pass on\r
+        * @param {Object} oOptions Optional. Extra options for invocation\r
+        * @param {Boolean} oOptions.overrideApi When true the first argument is used as the API ID.\r
+        * @param {Object} oOptions.context A context object for passing extra information on to the provider implementation.\r
+        * @param {Function} oOptions.fallback A fallback function to run if the provider implementation is missing.\r
+        */\r
+       this.go = function(sMethodName, args, oOptions){\r
+               \r
+               if(typeof(oOptions) == 'undefined'){\r
+                       oOptions = defOpts;\r
+               }\r
+                                               \r
+               var sApiId = oOptions.overrideApi ? args[0] : fnApiIdGetter.apply(obj);\r
+               \r
+               if(typeof(sApiId) != 'string'){\r
+                       throw 'API ID not available.';\r
+               }\r
+               \r
+               if(typeof(oOptions.context) != 'undefined' && oOptions.context !== null){\r
+                       // make sure args is an array\r
+                       args = Array.prototype.slice.apply(args);\r
+                       args.push(oOptions.context);\r
+               }\r
+               \r
+               if(typeof(oOptions.fallback) == 'function' && !hasImplementation(sApiId, sClassName, sMethodName)){\r
+                       // we've got no implementation but have got a fallback function\r
+                       return oOptions.fallback.apply(obj, args);\r
+               }\r
+               else {                          \r
+                       return invoke(sApiId, sClassName, sMethodName, obj, args);\r
+               }\r
+               \r
+       };\r
+       \r
+};\r
+\r
+/**\r
+ * @namespace\r
+ */\r
+mxn.util = {\r
+                       \r
+       /**\r
+        * Merges properties of one object into another recursively.\r
+        * @param {Object} oRecv The object receiveing properties\r
+        * @param {Object} oGive The object donating properties\r
+        */\r
+       merge: function(oRecv, oGive){\r
+               for (var sPropName in oGive){\r
+                       if (oGive.hasOwnProperty(sPropName)) {\r
+                               if(!oRecv.hasOwnProperty(sPropName)){\r
+                                       oRecv[sPropName] = oGive[sPropName];\r
+                               }\r
+                               else {\r
+                                       mxn.util.merge(oRecv[sPropName], oGive[sPropName]);\r
+                               }\r
+                       }\r
+               }\r
+       },\r
+       \r
+       /**\r
+        * $m, the dollar function, elegantising getElementById()\r
+        * @return An HTML element or array of HTML elements\r
+        */\r
+       $m: function() {\r
+               var elements = [];\r
+               for (var i = 0; i < arguments.length; i++) {\r
+                       var element = arguments[i];\r
+                       if (typeof(element) == 'string') {\r
+                               element = document.getElementById(element);\r
+                       }\r
+                       if (arguments.length == 1) {\r
+                               return element;\r
+                       }\r
+                       elements.push(element);\r
+               }\r
+               return elements;\r
+       },\r
+\r
+       /**\r
+        * loadScript is a JSON data fetcher\r
+        * @param {String} src URL to JSON file\r
+        * @param {Function} callback Callback function\r
+        */\r
+       loadScript: function(src, callback) {\r
+               var script = document.createElement('script');\r
+               script.type = 'text/javascript';\r
+               script.src = src;\r
+               if (callback) {\r
+                       if(script.addEventListener){\r
+                               script.addEventListener('load', callback, true);\r
+                       }\r
+                       else if(script.attachEvent){\r
+                               var done = false;\r
+                               script.attachEvent("onreadystatechange",function(){\r
+                                       if ( !done && document.readyState === "complete" ) {\r
+                                               done = true;\r
+                                               callback();\r
+                                       }\r
+                               });\r
+                       }                       \r
+               }\r
+               var h = document.getElementsByTagName('head')[0];\r
+               h.appendChild( script );\r
+               return;\r
+       },\r
+\r
+       /**\r
+        *\r
+        * @param {Object} point\r
+        * @param {Object} level\r
+        */\r
+       convertLatLonXY_Yahoo: function(point, level) { //Mercator\r
+               var size = 1 << (26 - level);\r
+               var pixel_per_degree = size / 360.0;\r
+               var pixel_per_radian = size / (2 * Math.PI);\r
+               var origin = new YCoordPoint(size / 2 , size / 2);\r
+               var answer = new YCoordPoint();\r
+               answer.x = Math.floor(origin.x + point.lon * pixel_per_degree);\r
+               var sin = Math.sin(point.lat * Math.PI / 180.0);\r
+               answer.y = Math.floor(origin.y + 0.5 * Math.log((1 + sin) / (1 - sin)) * -pixel_per_radian);\r
+               return answer;\r
+       },\r
+\r
+       /**\r
+        * Load a stylesheet from a remote file.\r
+        * @param {String} href URL to the CSS file\r
+        */\r
+       loadStyle: function(href) {\r
+               var link = document.createElement('link');\r
+               link.type = 'text/css';\r
+               link.rel = 'stylesheet';\r
+               link.href = href;\r
+               document.getElementsByTagName('head')[0].appendChild(link);\r
+               return;\r
+       },\r
+\r
+       /**\r
+        * getStyle provides cross-browser access to css\r
+        * @param {Object} el HTML Element\r
+        * @param {String} prop Style property name\r
+        */\r
+       getStyle: function(el, prop) {\r
+               var y;\r
+               if (el.currentStyle) {\r
+                       y = el.currentStyle[prop];\r
+               }\r
+               else if (window.getComputedStyle) {\r
+                       y = window.getComputedStyle( el, '').getPropertyValue(prop);\r
+               }\r
+               return y;\r
+       },\r
+\r
+       /**\r
+        * Convert longitude to metres\r
+        * http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM\r
+        * "A degree of longitude at the equator is 111.2km... For other latitudes,\r
+        * multiply by cos(lat)"\r
+        * assumes the earth is a sphere but good enough for our purposes\r
+        * @param {Float} lon\r
+        * @param {Float} lat\r
+        */\r
+       lonToMetres: function(lon, lat) {\r
+               return lon * (111200 * Math.cos(lat * (Math.PI / 180)));\r
+       },\r
+\r
+       /**\r
+        * Convert metres to longitude\r
+        * @param {Object} m\r
+        * @param {Object} lat\r
+        */\r
+       metresToLon: function(m, lat) {\r
+               return m / (111200 * Math.cos(lat * (Math.PI / 180)));\r
+       },\r
+\r
+       /**\r
+        * Convert kilometres to miles\r
+        * @param {Float} km\r
+        * @returns {Float} miles\r
+        */\r
+       KMToMiles: function(km) {\r
+               return km / 1.609344;\r
+       },\r
+\r
+       /**\r
+        * Convert miles to kilometres\r
+        * @param {Float} miles\r
+        * @returns {Float} km\r
+        */\r
+       milesToKM: function(miles) {\r
+               return miles * 1.609344;\r
+       },\r
+\r
+       // stuff to convert google zoom levels to/from degrees\r
+       // assumes zoom 0 = 256 pixels = 360 degrees\r
+       //               zoom 1 = 256 pixels = 180 degrees\r
+       // etc.\r
+\r
+       /**\r
+        *\r
+        * @param {Object} pixels\r
+        * @param {Object} zoom\r
+        */\r
+       getDegreesFromGoogleZoomLevel: function(pixels, zoom) {\r
+               return (360 * pixels) / (Math.pow(2, zoom + 8));\r
+       },\r
+\r
+       /**\r
+        *\r
+        * @param {Object} pixels\r
+        * @param {Object} degrees\r
+        */\r
+       getGoogleZoomLevelFromDegrees: function(pixels, degrees) {\r
+               return mxn.util.logN((360 * pixels) / degrees, 2) - 8;\r
+       },\r
+\r
+       /**\r
+        *\r
+        * @param {Object} number\r
+        * @param {Object} base\r
+        */\r
+       logN: function(number, base) {\r
+               return Math.log(number) / Math.log(base);\r
+       },\r
+                       \r
+       /**\r
+        * Returns array of loaded provider apis\r
+        * @returns {Array} providers\r
+        */\r
+       getAvailableProviders : function () {\r
+               var providers = [];\r
+               for (var propertyName in apis){\r
+                       if (apis.hasOwnProperty(propertyName)) {\r
+                               providers.push(propertyName);\r
+                       }\r
+               }\r
+               return providers;\r
+       }\r
+       \r
+};\r
+\r
+/**\r
+ * Class for converting between HTML and RGB integer color formats.\r
+ * Accepts either a HTML color string argument or three integers for R, G and B.\r
+ * @constructor\r
+ */\r
+mxn.util.Color = function() {  \r
+       if(arguments.length == 3) {\r
+               this.red = arguments[0];\r
+               this.green = arguments[1];\r
+               this.blue = arguments[2];\r
+       }\r
+       else if(arguments.length == 1) {\r
+               this.setHexColor(arguments[0]);\r
+       }\r
+};\r
+\r
+mxn.util.Color.prototype.reHex = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\r
+\r
+/**\r
+ * Set the color from the supplied HTML hex string.\r
+ * @param {String} strHexColor A HTML hex color string e.g. '#00FF88'.\r
+ */\r
+mxn.util.Color.prototype.setHexColor = function(strHexColor) {\r
+       var match = strHexColor.match(this.reHex);\r
+       if(match) {\r
+               strHexColor = match[1];\r
+       }\r
+       else {\r
+               throw 'Invalid HEX color format, expected #000, 000, #000000 or 000000';\r
+       }\r
+       if(strHexColor.length == 3) {\r
+               strHexColor = strHexColor.replace(/\w/g, function(str){return str.concat(str);});\r
+       }\r
+       this.red = parseInt(strHexColor.substr(0,2), 16);\r
+       this.green = parseInt(strHexColor.substr(2,2), 16);\r
+       this.blue = parseInt(strHexColor.substr(4,2), 16);\r
+};\r
+\r
+/**\r
+ * Retrieve the color value as an HTML hex string.\r
+ * @returns {String} Format '00FF88' - note no preceding #.\r
+ */\r
+mxn.util.Color.prototype.getHexColor = function() {\r
+       var vals = [this.red.toString(16), this.green.toString(16), this.blue.toString(16)];\r
+       for(var i = 0; i < vals.length; i++) {\r
+               vals[i] = (vals[i].length == 1) ? '0' + vals[i] : vals[i];\r
+               vals[i] = vals[i].toUpperCase();\r
+       }\r
+       return vals.join('');\r
+};\r
+\r
+})();
\ No newline at end of file
diff --git a/plugins/Mapstraction/js/mxn.microsoft.core.js b/plugins/Mapstraction/js/mxn.microsoft.core.js
new file mode 100644 (file)
index 0000000..292e45d
--- /dev/null
@@ -0,0 +1,402 @@
+mxn.register('microsoft', {    \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element, api) {          \r
+               var me = this;\r
+               if (VEMap){\r
+                       this.maps[api] = new VEMap(element.id);\r
+        \r
+                       \r
+                       \r
+                       this.maps[api].AttachEvent('onclick', function(event){\r
+                               me.clickHandler();\r
+                               var x = event.mapX;\r
+                               var y = event.mapY;\r
+                           var pixel = new VEPixel(x,y);\r
+                               me.click.fire({'location': new mxn.LatLonPoint(pixel.Latitude, pixel.Longitude)});\r
+                       \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onendzoom', function(event){\r
+                               me.moveendHandler(me);\r
+                               me.changeZoom.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onendpan', function(event){\r
+                               me.moveendHandler(me);\r
+                               me.endPan.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].AttachEvent('onchangeview', function(event){\r
+                               me.endPan.fire();\r
+                               \r
+                               \r
+                       });\r
+                       this.maps[api].LoadMap();\r
+                       document.getElementById("MSVE_obliqueNotification").style.visibility = "hidden"; \r
+               \r
+                       //removes the bird's eye pop-up\r
+                       this.loaded[api] = true;\r
+                       me.load.fire(); \r
+               }\r
+               else{\r
+                       alert(api + ' map script not imported')\r
+                       \r
+               }\r
+       \r
+       },\r
+       \r
+       applyOptions: function(){\r
+               var map = this.maps[this.api];\r
+               if(this.options.enableScrollWheelZoom){\r
+                       map.enableContinuousZoom();\r
+                       map.enableScrollWheelZoom();    \r
+               \r
+               }\r
+               \r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+               this.maps[this.api].Resize(width, height);\r
+       },\r
+\r
+       addControls: function( args ) {\r
+               var map = this.maps[this.api];\r
+        \r
+       if (args.pan) {\r
+                       map.SetDashboardSize(VEDashboardSize.Normal);\r
+               }\r
+               else {\r
+                       map.SetDashboardSize(VEDashboardSize.Tiny)\r
+               }\r
+\r
+       if (args.zoom == 'large') {\r
+                       map.SetDashboardSize(VEDashboardSize.Small)\r
+               }\r
+               else if ( args.zoom == 'small' ) {\r
+                       map.SetDashboardSize(VEDashboardSize.Tiny)\r
+               }\r
+               else {\r
+                       map.HideDashboard();\r
+                       map.HideScalebar();\r
+               }\r
+               \r
+               \r
+       },\r
+\r
+       addSmallControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.SetDashboardSize(VEDashboardSize.Tiny);\r
+               \r
+       },\r
+\r
+       addLargeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.SetDashboardSize(VEDashboardSize.Normal);\r
+               this.addControlsArgs.pan=true;\r
+               this.addControlsArgs.zoom = 'large';\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.addTypeControl();\r
+       \r
+       },\r
+\r
+       dragging: function(on) {\r
+               var map = this.maps[this.api];\r
+               if(on){\r
+                       map.enableDragMap();\r
+               }\r
+               else{\r
+                       map.disableDragMap();\r
+                       \r
+               }\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               var vzoom =  zoom;\r
+               map.SetCenterAndZoom(new VELatLong(point.lat,point.lon), vzoom)\r
+               \r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+               var map = this.maps[this.api];\r
+                marker.pinID = "mspin-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));\r
+               var pin = marker.toProprietary(this.api);\r
+               map.AddShape(pin);\r
+               //give onclick event\r
+               //give on double click event\r
+               //give on close window\r
+               //return the marker\r
+               \r
+               \r
+               return pin;\r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+               var map = this.maps[this.api];\r
+               var id = marker.proprietary_marker.GetID();\r
+               var microsoftShape = map.GetShapeByID(id);\r
+               map.DeleteShape(microsoftShape);\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               var pl = polyline.toProprietary(this.api);\r
+               pl.HideIcon();//hide the icon VE automatically displays\r
+               map.AddShape(pl);\r
+               \r
+               return pl;\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];\r
+               var id = polyline.proprietary_polyline.GetID();\r
+               var microsoftShape = map.GetShapeByID(id);\r
+               map.DeleteShape(microsoftShape);\r
+       },\r
+       \r
+       getCenter: function() {\r
+               var map = this.maps[this.api];\r
+               var LL = map.GetCenter();\r
+               var point = new mxn.LatLonPoint(LL.Latitude, LL.Longitude);\r
+               return point;\r
+               \r
+       },\r
\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               map.SetCenter(new VELatLong(point.lat, point.lon));\r
+               \r
+               \r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               map.SetZoomLevel(zoom);\r
+               \r
+               \r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               var zoom = map.GetZoomLevel();\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               var map = this.maps[this.api];\r
+               // NE and SW points from the bounding box.\r
+               var ne = bbox.getNorthEast();\r
+               var sw = bbox.getSouthWest();\r
+               var zoom;\r
+               \r
+               // TODO: Add provider code\r
+               \r
+               return zoom;\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                               map.SetMapStyle(VEMapStyle.Road);\r
+                               break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                               map.SetMapStyle(VEMapStyle.Aerial);\r
+                               break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                               map.SetMapStyle(VEMapStyle.Hybrid);\r
+                               break;\r
+                       default:\r
+                               map.SetMapStyle(VEMapStyle.Road);\r
+               }        \r
+       },\r
+\r
+       getMapType: function() {\r
+               var map = this.maps[this.api];\r
+               var mode = map.GetMapStyle();\r
+               switch(mode){\r
+                       case VEMapStyle.Aerial:\r
+                               return mxn.Mapstraction.SATELLITE;\r
+                       case VEMapStyle.Road:\r
+                               return mxn.Mapstraction.ROAD;\r
+                       case VEMapStyle.Hybrid:\r
+                               return mxn.Mapstraction.HYBRID;\r
+                       default:\r
+                               return null;\r
+                       \r
+               }\r
+       \r
+\r
+       },\r
+\r
+       getBounds: function () {\r
+               var map = this.maps[this.api];\r
+               view = map.GetMapView();\r
+               var topleft = view.TopLeftLatLong;\r
+               var bottomright = view.BottomRightLatLong;\r
+               \r
+               return new mxn.BoundingBox(bottomright.Latitude,topleft.Longitude,topleft.Latitude, bottomright.Longitude );\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest();\r
+               var ne = bounds.getNorthEast();\r
+               \r
+               var rec = new VELatLongRectangle(new VELatLong(ne.lat, ne.lon), new VELatLong(sw.lat, sw.lon));\r
+               map.SetMapView(rec);\r
+               \r
+               \r
+               \r
+       },\r
+\r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               var map = this.maps[this.api];\r
+               \r
+               // TODO: Add provider code\r
+       },\r
+\r
+       setImagePosition: function(id, oContext) {\r
+               var map = this.maps[this.api];\r
+               var topLeftPoint; var bottomRightPoint;\r
+\r
+               // TODO: Add provider code\r
+\r
+       //      oContext.pixels.top = ...;\r
+       //      oContext.pixels.left = ...;\r
+       //      oContext.pixels.bottom = ...;\r
+       //      oContext.pixels.right = ...;\r
+       },\r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+           var layer = new VEShapeLayer(); \r
+           var mlayerspec = new VEShapeSourceSpecification(VEDataType.GeoRSS, url, layer);\r
+               map.AddShapeLayer(layer);\r
+         \r
+       \r
+               \r
+       },\r
+\r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       getPixelRatio: function() {\r
+               throw 'Not implemented';\r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               var locDisp = document.getElementById(element);\r
+               if (locDisp != null) {\r
+                       var map = this.maps[this.api];\r
+                       map.AttachEvent("onmousemove", function(veEvent){\r
+                               var latlon = map.PixelToLatLong(new VEPixel(veEvent.mapX, veEvent.mapY));\r
+                               var loc = latlon.Latitude.toFixed(4) + " / " + latlon.Longitude.toFixed(4);\r
+                               locDisp.innerHTML = loc;\r
+\r
+                       });\r
+                       locDisp.innerHTML = "0.0000 / 0.0000";\r
+               }\r
+       }\r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+               return  new VELatLong(this.lat, this.lon);\r
+       },\r
+\r
+       fromProprietary: function(mpoint) {\r
+               this.lat =mpoint.Latitude;\r
+               this.lon =mpoint.Longitude;\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               var mmarker = new VEShape(VEShapeType.Pushpin, this.location.toProprietary('microsoft'));\r
+       \r
+       \r
+               return mmarker;\r
+               \r
+       },\r
+\r
+       openBubble: function() {                \r
+               var mmarker = this.proprietary_marker;\r
+               map.ClearInfoBoxStyles();\r
+               mmarker.SetTitle(this.infoBubble);\r
+       },\r
+\r
+       hide: function() {\r
+               this.proprietary_marker.hide();\r
+       },\r
+\r
+       show: function() {\r
+               this.proprietary_marker_unhide();\r
+       },\r
+\r
+       update: function() {\r
+               throw 'Not implemented';\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {\r
+               var mpoints =[];\r
+               for(var i =0, length = this.points.length; i < length; i++)\r
+               {\r
+                       mpoints.push(this.points[i].toProprietary('microsoft'));\r
+               }\r
+               var mpolyline = new VEShape(VEShapeType.Polyline, mpoints);\r
+               if(this.color){\r
+                       var color = new mxn.util.Color(this.color);\r
+                       var opacity = (typeof(this.opacity) == 'undefined' || this.opacity === null) ? 1.0 : this.opacity;\r
+                       var vecolor = new VEColor(color.red, color.green, color.blue, opacity);\r
+                       mpolyline.SetLineColor(vecolor);\r
+               }\r
+               //      TODO ability to change line width\r
+               return mpolyline;\r
+       },\r
+               \r
+       show: function() {\r
+                       this.proprietary_polyline.Show();\r
+       },\r
+\r
+       hide: function() {\r
+                       this.proprietary_polyline.Hide();\r
+       }\r
+       \r
+}\r
+\r
+});\r
diff --git a/plugins/Mapstraction/js/mxn.openlayers.core.js b/plugins/Mapstraction/js/mxn.openlayers.core.js
new file mode 100644 (file)
index 0000000..c04c332
--- /dev/null
@@ -0,0 +1,513 @@
+mxn.register('openlayers', {   
+
+    Mapstraction: {
+
+        init: function(element, api){
+            var me = this;
+            this.maps[api] = new OpenLayers.Map(
+                element.id,
+                {
+                    maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
+                    maxResolution:156543,
+                    numZoomLevels:18,
+                    units:'meters',
+                    projection: "EPSG:41001"
+                }
+            );
+
+            this.layers['osmmapnik'] = new OpenLayers.Layer.TMS(
+                'OSM Mapnik',
+                [
+                "http://a.tile.openstreetmap.org/",
+                "http://b.tile.openstreetmap.org/",
+                "http://c.tile.openstreetmap.org/"
+                ],
+                {
+                    type:'png',
+                    getURL: function (bounds) {
+                        var res = this.map.getResolution();
+                        var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
+                        var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
+                        var z = this.map.getZoom();
+                        var limit = Math.pow(2, z);
+                        if (y < 0 || y >= limit) {
+                            return null;
+                        } else {
+                            x = ((x % limit) + limit) % limit;
+                            var path = z + "/" + x + "/" + y + "." + this.type;
+                            var url = this.url;
+                            if (url instanceof Array) {
+                                url = this.selectUrl(path, url);
+                            }
+                            return url + path;
+                        }
+                    },
+                    displayOutsideMaxExtent: true
+                }
+            );
+
+            this.layers['osm'] = new OpenLayers.Layer.TMS(
+                'OSM',
+                [
+                "http://a.tah.openstreetmap.org/Tiles/tile.php/",
+                "http://b.tah.openstreetmap.org/Tiles/tile.php/",
+                "http://c.tah.openstreetmap.org/Tiles/tile.php/"
+                ],
+                {
+                    type:'png',
+                    getURL: function (bounds) {
+                        var res = this.map.getResolution();
+                        var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
+                        var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
+                        var z = this.map.getZoom();
+                        var limit = Math.pow(2, z);
+                        if (y < 0 || y >= limit) {
+                            return null;
+                        } else {
+                            x = ((x % limit) + limit) % limit;
+                            var path = z + "/" + x + "/" + y + "." + this.type;
+                            var url = this.url;
+                            if (url instanceof Array) {
+                                url = this.selectUrl(path, url);
+                            }
+                            return url + path;
+                        }
+                    },
+                    displayOutsideMaxExtent: true
+                }
+            );
+
+            this.maps[api].addLayer(this.layers['osmmapnik']);
+            this.maps[api].addLayer(this.layers['osm']);
+        },
+
+        applyOptions: function(){
+            // var map = this.maps[this.api];
+            // var myOptions = [];
+            // if (this.options.enableDragging) {
+            //     myOptions.draggable = true;
+            // } 
+            // if (this.options.enableScrollWheelZoom){
+            //     myOptions.scrollwheel = true;
+            // } 
+            // map.setOptions(myOptions);
+        },
+
+        resizeTo: function(width, height){     
+            this.currentElement.style.width = width;
+            this.currentElement.style.height = height;
+            this.maps[this.api].updateSize();
+        },
+
+        addControls: function( args ) {
+            var map = this.maps[this.api];     
+            // FIXME: OpenLayers has a bug removing all the controls says crschmidt
+            for (var i = map.controls.length; i>1; i--) {
+                map.controls[i-1].deactivate();
+                map.removeControl(map.controls[i-1]);
+            }
+            if ( args.zoom == 'large' )      {
+                map.addControl(new OpenLayers.Control.PanZoomBar());
+            }
+            else if ( args.zoom == 'small' ) {
+                map.addControl(new OpenLayers.Control.ZoomPanel());
+                if ( args.pan) {
+                    map.addControl(new OpenLayers.Control.PanPanel()); 
+                }
+            }
+            else {
+                if ( args.pan){
+                    map.addControl(new OpenLayers.Control.PanPanel()); 
+                }
+            }
+            if ( args.overview ) {
+                map.addControl(new OpenLayers.Control.OverviewMap());
+            }
+            if ( args.map_type ) {
+                map.addControl(new OpenLayers.Control.LayerSwitcher());
+            }
+        },
+
+        addSmallControls: function() {
+            var map = this.maps[this.api];
+            this.addControlsArgs.pan = false;
+            this.addControlsArgs.scale = false;                        
+            this.addControlsArgs.zoom = 'small';
+            map.addControl(new OpenLayers.Control.ZoomBox());
+            map.addControl(new OpenLayers.Control.LayerSwitcher({
+                'ascending':false
+            }));            
+        },
+
+        addLargeControls: function() {
+            var map = this.maps[this.api];
+            map.addControl(new OpenLayers.Control.PanZoomBar());
+            this.addControlsArgs.pan = true;
+            this.addControlsArgs.zoom = 'large';
+        },
+
+        addMapTypeControls: function() {
+            var map = this.maps[this.api];
+            map.addControl( new OpenLayers.Control.LayerSwitcher({
+                'ascending':false
+            }) );
+            this.addControlsArgs.map_type = true;
+        },
+
+        setCenterAndZoom: function(point, zoom) { 
+            var map = this.maps[this.api];
+            var pt = point.toProprietary(this.api);
+            map.setCenter(point.toProprietary(this.api), zoom);
+        },
+
+        addMarker: function(marker, old) {
+            var map = this.maps[this.api];
+            var pin = marker.toProprietary(this.api);
+            if (!this.layers['markers']) {
+                this.layers['markers'] = new OpenLayers.Layer.Markers('markers');
+                map.addLayer(this.layers['markers']);
+            }
+            this.layers['markers'].addMarker(pin);
+
+            return pin;
+        },
+
+        removeMarker: function(marker) {
+            var map = this.maps[this.api];
+            var pin = marker.toProprietary(this.api);
+            this.layers['markers'].removeMarker(pin);
+            pin.destroy();
+
+        },
+
+        removeAllMarkers: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        declutterMarkers: function(opts) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        addPolyline: function(polyline, old) {
+            var map = this.maps[this.api];
+            var pl = polyline.toProprietary(this.api);
+
+            if (!this.layers['polylines']) {
+                this.layers['polylines'] = new OpenLayers.Layer.Vector('polylines');
+                map.addLayer(this.layers['polylines']);
+            }
+            polyline.setChild(pl);
+            this.layers['polylines'].addFeatures([pl]);
+            return pl;
+        },
+
+        removePolyline: function(polyline) {
+            var map = this.maps[this.api];
+            var pl = polyline.toProprietary(this.api);
+            this.layers['polylines'].removeFeatures([pl]);
+        },
+        removeAllPolylines: function() {
+            var olpolylines = [];
+            for(var i = 0, length = this.polylines.length; i < length; i++){
+                olpolylines.push(this.polylines[i].toProprietary(this.api));
+            }
+            if (this.layers['polylines']) this.layers['polylines'].removeFeatures(olpolylines);            
+        },
+
+        getCenter: function() {
+            var map = this.maps[this.api];
+            pt = map.getCenter();
+            return new mxn.LatLonPoint(pt.lat, pt.lon);
+        },
+
+        setCenter: function(point, options) {
+            var map = this.maps[this.api];
+            var pt = point.toProprietary(this.api);
+            map.setCenter(pt);
+            
+        },
+
+        setZoom: function(zoom) {
+            var map = this.maps[this.api];
+            map.zoomTo(zoom);
+        },
+
+        getZoom: function() {
+            var map = this.maps[this.api];
+            return map.zoom;
+        },
+
+        getZoomLevelForBoundingBox: function( bbox ) {
+            var map = this.maps[this.api];
+            // throw 'Not implemented';
+            return zoom;
+        },
+
+        setMapType: function(type) {
+            var map = this.maps[this.api];
+            throw 'Not implemented (setMapType)';
+
+            // switch(type) {
+            //     case mxn.Mapstraction.ROAD:
+            //     map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
+            //     break;
+            //     case mxn.Mapstraction.SATELLITE:
+            //     map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
+            //     break;
+            //     case mxn.Mapstraction.HYBRID:
+            //     map.setMapTypeId(google.maps.MapTypeId.HYBRID);
+            //     break;
+            //     default:
+            //     map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
+            // }        
+        },
+
+        getMapType: function() {
+            var map = this.maps[this.api];
+            // TODO: implement actual layer support
+            return mxn.Mapstraction.ROAD;
+
+            // var type = map.getMapTypeId();
+            // switch(type) {
+            //     case google.maps.MapTypeId.ROADMAP:
+            //     return mxn.Mapstraction.ROAD;
+            //     case google.maps.MapTypeId.SATELLITE:
+            //     return mxn.Mapstraction.SATELLITE;
+            //     case google.maps.MapTypeId.HYBRID:
+            //     return mxn.Mapstraction.HYBRID;
+            //     //case google.maps.MapTypeId.TERRAIN:
+            //     //        return something;
+            //     default:
+            //     return null;
+            // }
+        },
+
+        getBounds: function () {
+            var map = this.maps[this.api];
+            var olbox = map.calculateBounds();
+            return new mxn.BoundingBox(olbox.bottom, olbox.left, olbox.top, olbox.right);            
+        },
+
+        setBounds: function(bounds){
+            var map = this.maps[this.api];
+            var sw = bounds.getSouthWest();
+            var ne = bounds.getNorthEast();
+
+            if(sw.lon > ne.lon) {
+                sw.lon -= 360;
+            }
+
+            var obounds = new OpenLayers.Bounds();
+            
+            obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
+            obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
+            map.zoomToExtent(obounds);
+        },
+
+        addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        setImagePosition: function(id, oContext) {
+            var map = this.maps[this.api];
+            var topLeftPoint; var bottomRightPoint;
+
+            // TODO: Add provider code
+
+            //oContext.pixels.top = ...;
+            //oContext.pixels.left = ...;
+            //oContext.pixels.bottom = ...;
+            //oContext.pixels.right = ...;
+        },
+
+        addOverlay: function(url, autoCenterAndZoom) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+
+        },
+
+        addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        toggleTileLayer: function(tile_url) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code
+        },
+
+        getPixelRatio: function() {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        },
+
+        mousePosition: function(element) {
+            var map = this.maps[this.api];
+
+            // TODO: Add provider code 
+        }
+    },
+
+    LatLonPoint: {
+
+        toProprietary: function() {
+            var ollon = this.lon * 20037508.34 / 180;
+            var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180);
+            ollat = ollat * 20037508.34 / 180;
+            return new OpenLayers.LonLat(ollon, ollat);            
+        },
+
+        fromProprietary: function(olPoint) {
+            var lon = (olPoint.lon / 20037508.34) * 180;
+            var lat = (olPoint.lat / 20037508.34) * 180;
+            lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
+            this.lon = lon;
+            this.lat = lat;
+        }
+
+    },
+
+    Marker: {
+
+        toProprietary: function() {
+            var size, anchor, icon;
+            if(this.iconSize) {
+                size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);
+            }
+            else {
+                size = new OpenLayers.Size(21,25);
+            }
+
+            if(this.iconAnchor) {
+                anchor = new OpenLayers.Pixel(this.iconAnchor[0], this.iconAnchor[1]);
+            }
+            else {
+                // FIXME: hard-coding the anchor point
+                anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);
+            }
+
+            if(this.iconUrl) {
+                icon = new OpenLayers.Icon(this.iconUrl, size, anchor);
+            }
+            else {
+                icon = new OpenLayers.Icon('http://openlayers.org/dev/img/marker-gold.png', size, anchor);
+            }
+            var marker = new OpenLayers.Marker(this.location.toProprietary("openlayers"), icon);
+
+            if(this.infoBubble) {
+                var popup = new OpenLayers.Popup(null,
+                    this.location.toProprietary("openlayers"),
+                    new OpenLayers.Size(100,100),
+                    this.infoBubble,
+                    true);
+                    popup.autoSize = true;
+                    var theMap = this.map;
+                    if(this.hover) {
+                        marker.events.register("mouseover", marker, function(event) {
+                            theMap.addPopup(popup);
+                            popup.show();
+                        });
+                        marker.events.register("mouseout", marker, function(event) {
+                            popup.hide();
+                            theMap.removePopup(popup);
+                        });
+                    }
+                    else {
+                        var shown = false;
+                        marker.events.register("mousedown", marker, function(event) {
+                            if (shown) {
+                                popup.hide();
+                                theMap.removePopup(popup);
+                                shown = false;
+                            } else {
+                                theMap.addPopup(popup);
+                                popup.show();
+                                shown = true;
+                            }
+                        });
+                    }
+                }
+
+                if(this.hoverIconUrl) {
+                    // TODO
+                }
+
+                if(this.infoDiv){
+                    // TODO
+                }
+                return marker;
+            },
+
+        openBubble: function() {               
+            // TODO: Add provider code
+        },
+
+        hide: function() {
+            this.proprietary_marker.setOptions({visible:false});
+        },
+
+        show: function() {
+            this.proprietary_marker.setOptions({visible:true});
+        },
+
+        update: function() {
+            // TODO: Add provider code
+        }
+
+    },
+
+    Polyline: {
+
+        toProprietary: function() {
+            var olpolyline;
+            var olpoints = [];
+            var ring;
+            var style = {
+                strokeColor: this.color || "#000000",
+                strokeOpacity: this.opacity || 1,
+                strokeWidth: this.width || 1,
+                fillColor: this.fillColor || "#000000",
+                fillOpacity: this.getAttribute('fillOpacity') || 0.2
+            };
+
+            //TODO Handle closed attribute
+
+            for (var i = 0, length = this.points.length ; i< length; i++){
+                olpoint = this.points[i].toProprietary("openlayers");
+                olpoints.push(new OpenLayers.Geometry.Point(olpoint.lon, olpoint.lat));
+            }
+
+            if (this.closed) {
+                // a closed polygon
+                ring = new OpenLayers.Geometry.LinearRing(olpoints);
+            } else {
+                // a line
+                ring = new OpenLayers.Geometry.LineString(olpoints);
+            }
+
+            olpolyline = new OpenLayers.Feature.Vector(ring, null, style);
+
+            return olpolyline;
+        },
+
+        show: function() {
+            throw 'Not implemented';
+        },
+
+        hide: function() {
+            throw 'Not implemented';
+        }
+
+    }
+
+});
\ No newline at end of file
diff --git a/plugins/Mapstraction/js/mxn.yahoo.core.js b/plugins/Mapstraction/js/mxn.yahoo.core.js
new file mode 100644 (file)
index 0000000..99e1958
--- /dev/null
@@ -0,0 +1,391 @@
+mxn.register('yahoo', {        \r
+\r
+Mapstraction: {\r
+       \r
+       init: function(element,api) {           \r
+               var me = this;\r
+               if (YMap) {\r
+                       this.maps[api] = new YMap(element);\r
+\r
+                       YEvent.Capture(this.maps[api], EventsList.MouseClick, function(event,location) {\r
+                               me.clickHandler(location.Lat, location.Lon, location, me);\r
+                               me.click.fire({'location': new mxn.LatLonPoint(location.Lat, location.Lon)});\r
+                       });\r
+                       YEvent.Capture(this.maps[api], EventsList.changeZoom, function() {\r
+                               me.moveendHandler(me);\r
+                               me.changeZoom.fire();\r
+                       });\r
+                       YEvent.Capture(this.maps[api], EventsList.endPan, function() {\r
+                               me.moveendHandler(me);\r
+                               me.endPan.fire();\r
+                       });\r
+                       YEvent.Capture(this.maps[api], EventsList.endAutoPan, function() {\r
+                               me.endPan.fire();\r
+                       });\r
+                       \r
+                       this.loaded[api] = true;\r
+                       me.load.fire();\r
+               }\r
+               else {\r
+                       alert(api + ' map script not imported');\r
+               }  \r
+       },\r
+       \r
+       applyOptions: function(){\r
+               \r
+               /*\r
+               if (this.options.enableDragging) {\r
+                       map.enableDragMap();\r
+               } else {\r
+                       map.disableDragMap();\r
+               }*/\r
+               \r
+       },\r
+\r
+       resizeTo: function(width, height){      \r
+               this.maps[this.api].resizeTo(new YSize(width,height));\r
+       },\r
+\r
+       addControls: function( args ) {\r
+               var map = this.maps[this.api];\r
+               \r
+               if (args.pan) {\r
+                       map.addPanControl();\r
+               }\r
+               else {\r
+                       // Yahoo doesn't check the pan control is there before trying to remove it\r
+                       // so throws an exception :(\r
+                       map.addPanControl();\r
+                       map.removePanControl();\r
+               }\r
+               \r
+               if (args.zoom == 'large') {\r
+                       map.addZoomLong();\r
+               }\r
+               else if ( args.zoom == 'small' ) {\r
+                       map.addZoomShort();\r
+               }\r
+               else {\r
+                       map.removeZoomScale();\r
+               }\r
+       },\r
+\r
+       addSmallControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.addPanControl();\r
+               map.addZoomShort();\r
+               this.addControlsArgs.pan = true;\r
+               this.addControlsArgs.zoom = 'small';\r
+       },\r
+\r
+       addLargeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.addPanControl();\r
+               map.addZoomLong();\r
+               this.addControlsArgs.pan = true;  // keep the controls in case of swap\r
+               this.addControlsArgs.zoom = 'large';\r
+       },\r
+\r
+       addMapTypeControls: function() {\r
+               var map = this.maps[this.api];\r
+               map.addTypeControl();\r
+       },\r
+\r
+       dragging: function(on) {\r
+               var map = this.maps[this.api];\r
+               if (on) {\r
+                       map.enableDragMap();\r
+               } else {\r
+                       map.disableDragMap();\r
+               }\r
+       },\r
+\r
+       setCenterAndZoom: function(point, zoom) { \r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               \r
+               var yzoom = 18 - zoom; // maybe?\r
+        map.drawZoomAndCenter(pt,yzoom);\r
+       },\r
+       \r
+       addMarker: function(marker, old) {\r
+               var map = this.maps[this.api];\r
+               var pin = marker.toProprietary(this.api);\r
+               map.addOverlay(pin);\r
+               YEvent.Capture(pin, EventsList.MouseClick, function() {\r
+                       marker.click.fire();\r
+               });\r
+               YEvent.Capture(pin, EventsList.openSmartWindow, function() {\r
+                       marker.openInfoBubble.fire();\r
+               });\r
+               YEvent.Capture(pin, EventsList.closeSmartWindow, function() {\r
+                       marker.closeInfoBubble.fire();\r
+               });\r
+               return pin;\r
+       },\r
+\r
+       removeMarker: function(marker) {\r
+               var map = this.maps[this.api];\r
+               map.removeOverlay(marker.proprietary_marker);\r
+       },\r
+\r
+       removeAllMarkers: function() {\r
+               var map = this.maps[this.api];\r
+               map.removeMarkersAll();\r
+       },\r
+       \r
+       declutterMarkers: function(opts) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       addPolyline: function(polyline, old) {\r
+               var map = this.maps[this.api];\r
+               var pl = polyline.toProprietary(this.api);\r
+               map.addOverlay(pl);\r
+               return pl;\r
+       },\r
+\r
+       removePolyline: function(polyline) {\r
+               var map = this.maps[this.api];\r
+               map.removeOverlay(polyline.proprietary_polyline);\r
+       },\r
+       \r
+       getCenter: function() {\r
+               var map = this.maps[this.api];\r
+               var pt = map.getCenterLatLon();\r
+        var point = new mxn.LatLonPoint(pt.Lat, pt.Lon);\r
+               return point;\r
+       },\r
+\r
+       setCenter: function(point, options) {\r
+               var map = this.maps[this.api];\r
+               var pt = point.toProprietary(this.api);\r
+               map.panToLatLon(pt);\r
+       },\r
+\r
+       setZoom: function(zoom) {\r
+               var map = this.maps[this.api];\r
+               var yzoom = 18 - zoom; // maybe?\r
+               map.setZoomLevel(yzoom);                  \r
+       },\r
+       \r
+       getZoom: function() {\r
+               var map = this.maps[this.api];\r
+               return 18 - map.getZoomLevel();\r
+       },\r
+\r
+       getZoomLevelForBoundingBox: function( bbox ) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       setMapType: function(type) {\r
+               var map = this.maps[this.api];\r
+               \r
+               switch(type) {\r
+                       case mxn.Mapstraction.ROAD:\r
+                               map.setMapType(YAHOO_MAP_REG);\r
+                               break;\r
+                       case mxn.Mapstraction.SATELLITE:\r
+                               map.setMapType(YAHOO_MAP_SAT);\r
+                               break;\r
+                       case mxn.Mapstraction.HYBRID:\r
+                               map.setMapType(YAHOO_MAP_HYB);\r
+                               break;\r
+                       default:\r
+                               map.setMapType(YAHOO_MAP_REG);\r
+               }\r
+       },\r
+\r
+       getMapType: function() {\r
+               var map = this.maps[this.api];\r
+               var type = map.getCurrentMapType();\r
+               switch(type) {\r
+                       case YAHOO_MAP_REG:\r
+                               return mxn.Mapstraction.ROAD;\r
+                       case YAHOO_MAP_SAT:\r
+                               return mxn.Mapstraction.SATELLITE;\r
+                       case YAHOO_MAP_HYB:\r
+                               return mxn.Mapstraction.HYBRID;\r
+                       default:\r
+                               return null;\r
+               }\r
+       },\r
+\r
+       getBounds: function () {\r
+               var map = this.maps[this.api];\r
+               var ybox = map.getBoundsLatLon();\r
+        return new mxn.BoundingBox(ybox.LatMin, ybox.LonMin, ybox.LatMax, ybox.LonMax);\r
+       },\r
+\r
+       setBounds: function(bounds){\r
+               var map = this.maps[this.api];\r
+               var sw = bounds.getSouthWest();\r
+               var ne = bounds.getNorthEast();\r
+                                               \r
+               if(sw.lon > ne.lon) {\r
+                       sw.lon -= 360;\r
+               }\r
+               var center = new YGeoPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2);\r
+               \r
+               var container = map.getContainerSize();\r
+               for(var zoom = 1 ; zoom <= 17 ; zoom++){\r
+                       var sw_pix = mxn.util.convertLatLonXY_Yahoo(sw,zoom);\r
+                       var ne_pix = mxn.util.convertLatLonXY_Yahoo(ne,zoom);\r
+                       if(sw_pix.x > ne_pix.x) {\r
+                               sw_pix.x -= (1 << (26 - zoom)); //earth circumference in pixel\r
+                       }\r
+                       if(Math.abs(ne_pix.x - sw_pix.x) <= container.width\r
+                               && Math.abs(ne_pix.y - sw_pix.y) <= container.height){\r
+                               map.drawZoomAndCenter(center, zoom); //Call drawZoomAndCenter here: OK if called multiple times anyway\r
+                               break;\r
+                       }\r
+               }               \r
+       },\r
+       \r
+       addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       setImagePosition: function(id) {\r
+          throw 'Not implemented';\r
+       },      \r
+       \r
+       addOverlay: function(url, autoCenterAndZoom) {\r
+               var map = this.maps[this.api];\r
+               map.addOverlay(new YGeoRSS(url));\r
+       },\r
+       \r
+       addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       toggleTileLayer: function(tile_url) {\r
+               throw 'Not implemented';\r
+       },\r
+       \r
+       getPixelRatio: function() {\r
+               throw 'Not implemented';        \r
+       },\r
+       \r
+       mousePosition: function(element) {\r
+               throw 'Not implemented';\r
+       }\r
+       \r
+},\r
+\r
+LatLonPoint: {\r
+       \r
+       toProprietary: function() {\r
+               return new YGeoPoint(this.lat,this.lon);\r
+       },\r
+\r
+       fromProprietary: function(yahooPoint) {\r
+               this.lat = yahooPoint.Lat;\r
+               this.lon = yahooPoint.Lon;\r
+       }\r
+       \r
+},\r
+\r
+Marker: {\r
+       \r
+       toProprietary: function() {\r
+               var ymarker, size;\r
+               var infoBubble, event_action, infoDiv, div;\r
+               \r
+           if(this.iconSize) {\r
+               size = new YSize(this.iconSize[0], this.iconSize[1]);\r
+           }\r
+           if(this.iconUrl) {\r
+               if(this.iconSize){\r
+                   ymarker = new YMarker(this.location.toProprietary('yahoo'), new YImage(this.iconUrl, size));\r
+                       }\r
+               else {\r
+                   ymarker = new YMarker(this.location.toProprietary('yahoo'), new YImage(this.iconUrl));\r
+                       }\r
+           }\r
+           else {\r
+               if(this.iconSize) {\r
+                   ymarker = new YMarker(this.location.toProprietary('yahoo'), null, size);\r
+                       }\r
+               else {\r
+                   ymarker = new YMarker(this.location.toProprietary('yahoo'));\r
+                       }\r
+           }\r
+\r
+           if(this.labelText) {\r
+               ymarker.addLabel(this.labelText);\r
+           }\r
+\r
+           if(this.infoBubble) {\r
+               infoBubble = this.infoBubble;\r
+               if(this.hover) {\r
+                   event_action = EventsList.MouseOver;\r
+               }\r
+               else {\r
+                   event_action = EventsList.MouseClick;\r
+               }\r
+               YEvent.Capture(ymarker, event_action, function() {\r
+                   ymarker.openSmartWindow(infoBubble);\r
+               });\r
+\r
+           }\r
+\r
+           if(this.infoDiv) {\r
+               infoDiv = this.infoDiv;\r
+               div = this.div;\r
+               if(this.hover) {\r
+                   event_action = EventsList.MouseOver;\r
+               }\r
+               else {\r
+                   event_action = EventsList.MouseClick;\r
+               }\r
+               YEvent.Capture(ymarker, event_action, function() {\r
+                   document.getElementById(div).innerHTML = infoDiv;\r
+               });\r
+           }\r
+\r
+           return ymarker;\r
+       },\r
+\r
+       openBubble: function() {\r
+               var ypin = this.proprietary_marker;\r
+        ypin.openSmartWindow(this.infoBubble);\r
+       },\r
+\r
+       hide: function() {\r
+               this.proprietary_marker.hide();\r
+       },\r
+\r
+       show: function() {\r
+               this.proprietary_marker.unhide();\r
+       },\r
+\r
+       update: function() {\r
+               throw 'Not implemented';\r
+       }\r
+       \r
+},\r
+\r
+Polyline: {\r
+\r
+       toProprietary: function() {             \r
+               var ypolyline;\r
+           var ypoints = [];\r
+           for (var i = 0, length = this.points.length ; i< length; i++){\r
+               ypoints.push(this.points[i].toProprietary('yahoo'));\r
+           }\r
+           ypolyline = new YPolyline(ypoints,this.color,this.width,this.opacity);\r
+           return ypolyline;\r
+       },\r
+       \r
+       show: function() {\r
+               throw 'Not implemented';\r
+       },\r
+\r
+       hide: function() {\r
+               throw 'Not implemented';\r
+       }\r
+       \r
+}\r
+\r
+});
\ No newline at end of file