[OpenLayers-Commits] r11604 - in sandbox/crschmidt/ovi-mobile: examples lib lib/OpenLayers/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Mar 1 14:37:50 EST 2011


Author: crschmidt
Date: 2011-03-01 11:37:49 -0800 (Tue, 01 Mar 2011)
New Revision: 11604

Added:
   sandbox/crschmidt/ovi-mobile/examples/ovi.html
   sandbox/crschmidt/ovi-mobile/lib/OpenLayers/Layer/Ovi.js
Modified:
   sandbox/crschmidt/ovi-mobile/lib/OpenLayers.js
Log:
Create compliant Ovi Maps layer.


Added: sandbox/crschmidt/ovi-mobile/examples/ovi.html
===================================================================
--- sandbox/crschmidt/ovi-mobile/examples/ovi.html	                        (rev 0)
+++ sandbox/crschmidt/ovi-mobile/examples/ovi.html	2011-03-01 19:37:49 UTC (rev 11604)
@@ -0,0 +1,45 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
+    <meta name="apple-mobile-web-app-capable" content="yes" />
+    <title>OpenLayers: Ovi Layer</title>
+    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+    <link rel="stylesheet" href="style.css" type="text/css" />
+        <script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
+    <script src="../lib/OpenLayers.js"></script>
+    <script type="text/javascript">
+        var map, layer, velayer;
+
+        function init(){
+            map = new OpenLayers.Map('map');
+
+            yahooLayer = new OpenLayers.Layer.Ovi( "Ovi");
+
+            map.addLayer(yahooLayer);
+
+            map.setCenter(new OpenLayers.LonLat(-5, 40), 4);
+            map.addControl(new OpenLayers.Control.LayerSwitcher());
+        }
+    </script>
+  </head>
+  <body onload="init()">
+    <h1 id="title">Ovi Base Layer Example</h1>
+
+        <div id="tags">
+            yahoo, layer
+        </div>
+
+        <p id="shortdesc">
+            Shows how you would add a yahoo layer and add the LayerSwitcher control
+        </p>
+
+        <div id="map" class="smallmap"></div>
+
+        <div id="docs">
+            This is an example of how to add a yahoo layer to the OpenLayers window.  In order to enable a
+            yahoo layer. Also shown in this example is the LayerSwitcher() control for toggling between both the yahoo layer and
+            the open layer WMS.
+        </div>
+
+  </body>
+</html>

Copied: sandbox/crschmidt/ovi-mobile/lib/OpenLayers/Layer/Ovi.js (from rev 11579, sandbox/crschmidt/ovi-mobile/lib/OpenLayers/Layer/Yahoo.js)
===================================================================
--- sandbox/crschmidt/ovi-mobile/lib/OpenLayers/Layer/Ovi.js	                        (rev 0)
+++ sandbox/crschmidt/ovi-mobile/lib/OpenLayers/Layer/Ovi.js	2011-03-01 19:37:49 UTC (rev 11604)
@@ -0,0 +1,402 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for 
+ * full list of contributors). Published under the Clear BSD license.  
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/Layer/SphericalMercator.js
+ * @requires OpenLayers/Layer/EventPane.js
+ * @requires OpenLayers/Layer/FixedZoomLevels.js
+ * @requires OpenLayers/Lang.js
+ */
+
+/**
+ * Class: OpenLayers.Layer.Ovi
+ * 
+ * Inherits from:
+ *  - <OpenLayers.Layer.EventPane>
+ *  - <OpenLayers.Layer.FixedZoomLevels>
+ */
+OpenLayers.Layer.Ovi = OpenLayers.Class(
+  OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
+    
+    /** 
+     * Constant: MIN_ZOOM_LEVEL
+     * {Integer} 0 
+     */
+    MIN_ZOOM_LEVEL: 0,
+    
+    /** 
+     * Constant: MAX_ZOOM_LEVEL
+     * {Integer} 17
+     */
+    MAX_ZOOM_LEVEL: 17,
+
+    /** 
+     * Constant: RESOLUTIONS
+     * {Array(Float)} Hardcode these resolutions so that they are more closely
+     *                tied with the standard wms projection
+     */
+    RESOLUTIONS: [
+        1.40625, 
+        0.703125, 
+        0.3515625, 
+        0.17578125, 
+        0.087890625, 
+        0.0439453125,
+        0.02197265625, 
+        0.010986328125, 
+        0.0054931640625, 
+        0.00274658203125, 
+        0.001373291015625, 
+        0.0006866455078125, 
+        0.00034332275390625, 
+        0.000171661376953125, 
+        0.0000858306884765625, 
+        0.00004291534423828125,
+        0.00002145767211914062,
+        0.00001072883605957031
+    ],
+
+    /**
+     * APIProperty: type
+     * {OviMapType}
+     */
+    type: null,
+    
+    /**
+     * APIProperty: wrapDateLine
+     * {Boolean} Allow user to pan forever east/west.  Default is true.  
+     *     Setting this to false only restricts panning if 
+     *     <sphericalMercator> is true. 
+     */
+    wrapDateLine: true,
+
+    /**
+     * APIProperty: sphericalMercator
+     * {Boolean} Should the map act as a mercator-projected map? This will
+     * cause all interactions with the map to be in the actual map projection,
+     * which allows support for vector drawing, overlaying other maps, etc. 
+     */
+    sphericalMercator: false, 
+
+    /** 
+     * Constructor: OpenLayers.Layer.Ovi
+     * 
+     * Parameters:
+     * name - {String}
+     * options - {Object}
+     */
+    initialize: function(name, options) {
+        OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
+        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, 
+                                                                    arguments);
+        if(this.sphericalMercator) {
+            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
+            this.initMercatorParameters();
+        }
+    },
+    
+    /**
+     * Method: loadMapObject
+     */
+    loadMapObject:function() {
+        try { //do not crash! 
+//            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
+            this.mapObject = new ovi.mapsapi.map.Display(this.div);
+
+            //can we do smooth panning? (moveByXY is not an API function)
+/*            if ( !this.mapObject.moveByXY || 
+                 (typeof this.mapObject.moveByXY != "function" ) ) {
+
+                this.dragPanMapObject = null;
+            }               */ 
+        } catch(e) {}
+    },
+
+    /**
+     * Method: onMapResize
+     * 
+     */
+    onMapResize: function() {
+        try {
+            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
+            this.mapObject.resizeTo(size);
+        } catch(e) {}     
+    },    
+    
+    
+    /** 
+     * APIMethod: setMap
+     * Overridden from EventPane because we need to remove this yahoo event
+     *     pane which prohibits our drag and drop, and we can only do this 
+     *     once the map has been loaded and centered.
+     * 
+     * Parameters:
+     * map - {<OpenLayers.Map>}
+     */
+    setMap: function(map) {
+        OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
+
+        //this.map.events.register("moveend", this, this.fixOviEventPane);
+    },
+
+    /** 
+     * Method: fixOviEventPane
+     * The map has been centered, so the mysterious yahoo eventpane has been
+     *     added. we remove it so that it doesnt mess with *our* event pane.
+     */
+    fixOviEventPane: function() {
+        /*var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
+        if (yahooEventPane != null) {
+            if (yahooEventPane.parentNode != null) {
+                yahooEventPane.parentNode.removeChild(yahooEventPane);
+            }
+            this.map.events.unregister("moveend", this, 
+                                       this.fixOviEventPane);
+        }*/
+    },
+
+    /** 
+     * APIMethod: getWarningHTML
+     * 
+     * Returns: 
+     * {String} String with information on why layer is broken, how to get
+     *          it working.
+     */
+    getWarningHTML:function() {
+        return OpenLayers.i18n(
+            "getLayerWarning", {'layerType':'Ovi', 'layerLib':'Ovi'}
+        );
+    },
+
+  /********************************************************/
+  /*                                                      */
+  /*             Translation Functions                    */
+  /*                                                      */
+  /*    The following functions translate GMaps and OL    */ 
+  /*     formats for Pixel, LonLat, Bounds, and Zoom      */
+  /*                                                      */
+  /********************************************************/
+
+
+  //
+  // TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
+  //
+
+    /************************************
+     *                                  *
+     *   MapObject Interface Controls   *
+     *                                  *
+     ************************************/
+
+
+  // Get&Set Center, Zoom
+
+    /** 
+     * APIMethod: setMapObjectCenter
+     * Set the mapObject to the specified center and zoom
+     * 
+     * Parameters:
+     * center - {Object} MapObject LonLat format
+     * zoom - {int} MapObject zoom format
+     */
+    setMapObjectCenter: function(center, zoom) {
+        this.mapObject.set({'center': center, 'zoomLevel': zoom});
+    },
+   
+    /**
+     * APIMethod: getMapObjectCenter
+     * 
+     * Returns: 
+     * {Object} The mapObject's current center in Map Object format
+     */
+    getMapObjectCenter: function() {
+        return this.mapObject.get('center');
+    },
+
+/*
+    /**
+     * APIMethod: dragPanMapObject
+     * 
+     * Parameters:
+     * dX - {Integer}
+     * dY - {Integer}
+     */
+    /*dragPanMapObject: function(dX, dY) {
+        this.mapObject.moveByXY({
+            'x': -dX,
+            'y': dY
+        });
+    },*/
+    
+    /** 
+     * APIMethod: getMapObjectZoom
+     * 
+     * Returns:
+     * {Integer} The mapObject's current zoom, in Map Object format
+     */
+    getMapObjectZoom: function() {
+        return this.mapObject.get('zoomLevel');
+    },
+
+
+  // LonLat - Pixel Translation
+  
+    /**
+     * APIMethod: getMapObjectLonLatFromMapObjectPixel
+     * 
+     * Parameters:
+     * moPixel - {Object} MapObject Pixel format
+     * 
+     * Returns:
+     * {Object} MapObject LonLat translated from MapObject Pixel
+     */
+    getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
+        var lonlat = OpenLayers.Layer.prototype.getLonLatFromViewPortPx.apply(this, [new OpenLayers.Pixel(moPixel[0], moPixel[1])]);
+        if (lonlat) {
+            return {'latitude': lonlat.lat, 'longitude': lonlat.lon};
+        } else {
+            return null;
+        }    
+    },
+
+    /**
+     * APIMethod: getMapObjectPixelFromMapObjectLonLat
+     * 
+     * Parameters:
+     * moLonLat - {Object} MapObject LonLat format
+     * 
+     * Returns:
+     * {Object} MapObject Pixel transtlated from MapObject LonLat
+     */
+    getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
+        var pixel = OpenLayers.Layer.prototype.getViewPortPxFromLonLat.apply(this, [new OpenLayers.LonLat(moLonLat[0], moLonLat[1])]);
+        if (pixel) {
+            return [pixel.x, pixel.y];
+        } else {
+            return null;
+        }    
+    },
+
+
+    /************************************
+     *                                  *
+     *       MapObject Primitives       *
+     *                                  *
+     ************************************/
+
+
+  // LonLat
+    
+    /**
+     * APIMethod: getLongitudeFromMapObjectLonLat
+     * 
+     * Parameters:
+     * moLonLat - {Object} MapObject LonLat format
+     * 
+     * Returns:
+     * {Float} Longitude of the given MapObject LonLat
+     */
+    getLongitudeFromMapObjectLonLat: function(moLonLat) {
+        return this.sphericalMercator ? 
+            this.forwardMercator(moLonLat.longitude, moLonLat.latitude).lon :
+            moLonLat.longitude;
+    },
+
+    /**
+     * APIMethod: getLatitudeFromMapObjectLonLat
+     * 
+     * Parameters:
+     * moLonLat - {Object} MapObject LonLat format
+     * 
+     * Returns:
+     * {Float} Latitude of the given MapObject LonLat
+     */
+    getLatitudeFromMapObjectLonLat: function(moLonLat) {
+        return this.sphericalMercator ? 
+            this.forwardMercator(moLonLat.longitude, moLonLat.latitude).lat :
+            moLonLat.latitude;
+    },
+
+    /**
+     * APIMethod: getMapObjectLonLatFromLonLat
+     * 
+     * Parameters:
+     * lon - {Float}
+     * lat - {Float}
+     * 
+     * Returns:
+     * {Object} MapObject LonLat built from lon and lat params
+     */
+    getMapObjectLonLatFromLonLat: function(lon, lat) {
+        var yLatLong;
+        if(this.sphericalMercator) {
+            var lonlat = this.inverseMercator(lon, lat);
+            yLatLong = [lonlat.lat, lonlat.lon];
+        } else {
+            yLatLong = [lat, lon];
+        }
+        return yLatLong;
+    },
+
+  // Pixel
+    
+    /**
+     * APIMethod: getXFromMapObjectPixel
+     * 
+     * Parameters:
+     * moPixel - {Object} MapObject Pixel format
+     * 
+     * Returns:
+     * {Integer} X value of the MapObject Pixel
+     */
+    getXFromMapObjectPixel: function(moPixel) {
+        return moPixel.x;
+    },
+
+    /**
+     * APIMethod: getYFromMapObjectPixel
+     * 
+     * Parameters:
+     * moPixel - {Object} MapObject Pixel format
+     * 
+     * Returns:
+     * {Integer} Y value of the MapObject Pixel
+     */
+    getYFromMapObjectPixel: function(moPixel) {
+        return moPixel.y;
+    },
+
+    /**
+     * APIMethod: getMapObjectPixelFromXY
+     * 
+     * Parameters:
+     * x - {Integer}
+     * y - {Integer}
+     * 
+     * Returns:
+     * {Object} MapObject Pixel from x and y parameters
+     */
+    getMapObjectPixelFromXY: function(x, y) {
+        return [x, y];
+    },
+    
+  // Size
+  
+    /**
+     * APIMethod: getMapObjectSizeFromOLSize
+     * 
+     * Parameters:
+     * olSize - {<OpenLayers.Size>}
+     * 
+     * Returns:
+     * {Object} MapObject Size from olSize parameter
+     */
+    getMapObjectSizeFromOLSize: function(olSize) {
+        return [olSize.w, olSize.h];
+    },
+    
+    CLASS_NAME: "OpenLayers.Layer.Ovi"
+});

Modified: sandbox/crschmidt/ovi-mobile/lib/OpenLayers.js
===================================================================
--- sandbox/crschmidt/ovi-mobile/lib/OpenLayers.js	2011-03-01 19:37:03 UTC (rev 11603)
+++ sandbox/crschmidt/ovi-mobile/lib/OpenLayers.js	2011-03-01 19:37:49 UTC (rev 11604)
@@ -131,6 +131,7 @@
                 "OpenLayers/Layer/Google/v3.js",
                 "OpenLayers/Layer/VirtualEarth.js",
                 "OpenLayers/Layer/Yahoo.js",
+                "OpenLayers/Layer/Ovi.js",
                 "OpenLayers/Layer/HTTPRequest.js",
                 "OpenLayers/Layer/Grid.js",
                 "OpenLayers/Layer/MapGuide.js",



More information about the Commits mailing list