liangzi7 / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Adding support for other tiling engines e.g. Bing Maps #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It is difficult to add support for other tiling engines as the
OpenStreetMapRendererInfo is an enum could it be an interface perhaps?

Here is how to add support for Bing Maps by hacking the
OpenStreetMapRendererInfo directly

package org.andnav.osm.views.util;

import org.andnav.osm.views.util.constants.OpenStreetMapViewConstants;

/**
 *
 * @author Nicolas Gramlich
 *
 */
public enum OpenStreetMapRendererInfo {
    OSMARENDER("http://tah.openstreetmap.org/Tiles/tile/", "OsmaRender",
            ".png", 17, 8), MAPNIK("http://tile.openstreetmap.org/", "Mapnik",
            ".png", 18, 8), CYCLEMAP(
            "http://b.andy.sandbox.cloudmade.com/tiles/cycle/", "Cycle Map",
            ".png", 17, 8), OPENARIELMAP(
            "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/",
            "OpenArialMap (Satellite)", ".jpg", 13, 8), CLOUDMADESMALLTILES(
            "http://tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/64/",
            "Cloudmade (Small tiles)", ".jpg", 13, 6), CLOUDMADESTANDARDTILES(

"http://tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/",
            "Cloudmade (Standard tiles)", ".jpg", 18, 8), VIRTUALEARTHROADS(
            "http://r2.ortho.tiles.virtualearth.net/tiles/r", "VE ROADS",
            ".png?g=2", 18, 8, true), VIRTUALEARTHHYBRID(
            "http://r2.ortho.tiles.virtualearth.net/tiles/h", "VE ARIAL+ROADS",
            ".png?g=2", 18, 8, true), VIRTUALEARTHARIAL(
            "http://r2.ortho.tiles.virtualearth.net/tiles/a", "VE ARIAL",
            ".png?g=2", 18, 8, true);

    // ===========================================================
    // Fields
    // ===========================================================

    public final String BASEURL, NAME, IMAGE_FILENAMEENDING;
    public final int ZOOM_MAXLEVEL, MAPTILE_ZOOM, MAPTILE_SIZEPX;
    private boolean quadKeyBased = false;

    // ===========================================================
    // Constructors
    // ===========================================================

    private OpenStreetMapRendererInfo(final String aBaseUrl,
            final String aName, final String aImageFilenameEnding,
            final int aZoomMax, final int aTileZoom) {
        this.BASEURL = aBaseUrl;
        this.NAME = aName;
        this.ZOOM_MAXLEVEL = aZoomMax;
        this.IMAGE_FILENAMEENDING = aImageFilenameEnding;
        this.MAPTILE_ZOOM = aTileZoom;
        this.MAPTILE_SIZEPX = 1 << aTileZoom;
    }

    public static OpenStreetMapRendererInfo getDefault() {
        return MAPNIK;
    }

    // ===========================================================
    // Methods
    // ===========================================================

    public String getTileURLString(final int[] tileID, final int zoomLevel) {
        if (!quadKeyBased)
            return new StringBuilder()
                    .append(this.BASEURL)
                    .append(zoomLevel)
                    .append("/")
                    .append(

tileID[OpenStreetMapViewConstants.MAPTILE_LONGITUDE_INDEX])
                    .append("/")
                    .append(

tileID[OpenStreetMapViewConstants.MAPTILE_LATITUDE_INDEX])
                    .append(this.IMAGE_FILENAMEENDING).toString();
        else
            return new StringBuilder()
                    .append(BASEURL)
                    .append(
                            quadTree(

tileID[OpenStreetMapViewConstants.MAPTILE_LONGITUDE_INDEX],

tileID[OpenStreetMapViewConstants.MAPTILE_LATITUDE_INDEX],

                                    zoomLevel)).append(IMAGE_FILENAMEENDING)
                    .toString();
    }

    private OpenStreetMapRendererInfo(final String aBaseUrl,
            final String aName, final String aImageFilenameEnding,
            final int aZoomMax, final int aTileZoom, boolean qkeyBased) {
        this.BASEURL = aBaseUrl;
        this.NAME = aName;
        this.ZOOM_MAXLEVEL = aZoomMax;
        this.IMAGE_FILENAMEENDING = aImageFilenameEnding;
        this.MAPTILE_ZOOM = aTileZoom;
        this.MAPTILE_SIZEPX = 1 << aTileZoom;
        quadKeyBased = qkeyBased;
    }

    private String quadTree(int tx, int ty, int zoom) {
        // "Converts TMS tile coordinates to Microsoft QuadTree"
        StringBuilder quadKey = new StringBuilder();
        // ty = (((int) Math.pow(2, zoom) - 1)) - ty;
        // for (int i = 1; i < zoom; i++) {// in range(zoom, 0, -1):
        for (int i = zoom; i > 0; i--) {
            int digit = 0;
            int mask = 1 << (i - 1);
            if ((tx & mask) != 0)
                digit += 1;
            if ((ty & mask) != 0)
                digit += 2;
            quadKey.append("" + digit);
        }

        return quadKey.toString();
    }
}

Original issue reported on code.google.com by carsten....@gmail.com on 2 Nov 2009 at 11:24

GoogleCodeExporter commented 9 years ago
Is it legal to display VE images in other applications? For google tiles it's 
not, so
I won't include it in the official code.

Original comment by ThyMythos@googlemail.com on 7 Nov 2009 at 12:21

GoogleCodeExporter commented 9 years ago
MapCruncher can produce Quadkey-organized tiles from any data source, without 
using VE 
images, so if you can build in support for generic URLs passing the quadkey as 
part of 
the URL for the tile, that would allow custom maps created by MapCruncher.

Original comment by agreen0...@gmail.com on 8 Nov 2009 at 3:26

GoogleCodeExporter commented 9 years ago
The Bing Map legal terms are here 
http://www.microsoft.com/maps/product/terms.html

The terms for Non-commercial use:

Restrictions on your use: We do have some restrictions on your use of the 
service.
You may not:

    * copy, store, archive, or create a database of the content, except that geocodes
may be stored locally only for use with your Applications;
    * exceed 50,000 geocoding transactions in any 24 hour period;
    * download more than 250 points of interest at any one time;
    * provide guidance based on the position or routing of multiple objects tracked
using GPS or other sensor-generated methods;
    * present or alert an end user to individual maneuvers of a route in any way that
is synchronized with the end-user’s sensor-based position along the route, 
(e.g.
“real-time” navigation);
    * change, obscure or remove any portion of the results (including, without
limitation, any logo, trademark, copyright or other notice of Microsoft or its
suppliers, digital watermarks, or any advertisement);
    * integrate the Bing Maps for Enterprise Platform or any of its content with any
other mapping platform.

Original comment by carsten....@gmail.com on 8 Nov 2009 at 9:03

GoogleCodeExporter commented 9 years ago
I have included the quadTree support but not the VE URLs. In future the info 
will not
be stored in an enum but in a sqlite database. Users can then supply their own 
schemes.

Original comment by ThyMythos@googlemail.com on 8 Nov 2009 at 10:54

GoogleCodeExporter commented 9 years ago
It is possible to support Bing Map only extending the OnlineTileSourceBase 
class (and implementing IStyledTileSource) in order to use Bing Map REST, the 
use the setTileSource method of the MapView to switch on this tile source.

Original comment by caerw...@gmail.com on 12 Apr 2011 at 1:28

GoogleCodeExporter commented 9 years ago
I've spent the last week or so struggling to incorporate Bing Maps, but without 
success.  There are some similarities in the API, but not enough to make it 
really compatible with osmdroid/Google.
http://bingmapsandroidsdk.codeplex.com/

Original comment by neilboyd on 13 Apr 2011 at 5:17

GoogleCodeExporter commented 9 years ago
This is code to support Bing Map.
It is not integrated to the lib but it should be included in your project or 
additional lib.
This is a sample use:

// init the BingMapTileSource
        try
        {
            BingMapTileSource.initMetaData(BING_MAP_KEY);
        }
        catch(Exception e)
        {
            Log.e(TAG, e.getMessage());
        }

        // create an instance of BingMapTileSource using French labels
        BingMapTileSource tileSource = new BingMapTileSource("BingMap","en-US");
        mapView.setTileSource(tileSource);
        ((IStyledTileSource) mapView.getTileProvider().getTileSource()).setStyle(BingMapTileSource.IMAGERYSET_ROAD);

Original comment by caerw...@gmail.com on 5 Jul 2011 at 10:51

Attachments:

GoogleCodeExporter commented 9 years ago
Thank's for this patch. It seems you've used the tiles directly rather than 
using the SDK.

Please do not add any more comments to this issue and use issue 236 instead.

A couple of comments (t ocarry forward to issue 236):

1. You could get the key from the manifest the same as the CloudMade key.
2. How does this fit with the Bing license?
3. Couldn't you extend QuadTreeTileSource instead of OnlineTileSourceBase?

Original comment by neilboyd on 5 Jul 2011 at 11:40