[OpenLayers-Dev] MapQuest Open map class

christopher.schmidt at nokia.com christopher.schmidt at nokia.com
Wed Mar 16 07:43:42 EDT 2011


Feel free to open a ticket and create a patch with tests.

-- Chris

On Mar 16, 2011, at 7:34 AM, ext Martin Saturka wrote:

> Hi,
> could we have a class for MapQuest Open based maps, please? We use
> them, having the class below, just that may be it could be at the OL
> themselves.
> 
> OpenLayers.Layer.MapQuest = OpenLayers.Class(OpenLayers.Layer.OSMMod, {
>    name: "MapQuest",
>    attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'
> target='_blank'>OpenStreetMap</a>. Rendered by <a
> href='http://open.mapquest.co.uk/' target='_blank'>MapQuest</a>.",
>    sphericalMercator: true,
>    url: [
>        'http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
>        'http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
>        'http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
>        'http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png'
>    ],
>    CLASS_NAME: "OpenLayers.Layer.MapQuest"
> });
> 
> It can have a missed tile when an image is rendered too long by them
> (OL tries to load that immediately after a fail event, without
> possibility to wait for a while). We handle it with server
> randomization then (it looks it helps), and going back to an OSM tile
> when a problem. This way we can use the OSM tiles without making a
> load on the OSM servers.
> 
> OpenLayers.Util.originalOnImageLoadError = OpenLayers.Util.onImageLoadError;
> OpenLayers.Util.onImageLoadError = function() {
>    if (this.src.match(/^http:\/\/otile[1-4]\.mqcdn\.com\//)) {
>        if (!this._attempts) {this._attempts = 0;}
>        var mq_start = "http://otile" + Math.floor(1 + (4 *
> Math.random())) + ".mqcdn.com/tiles/1.0.0/osm/";
>        if ((2 + this._attempts) > OpenLayers.IMAGE_RELOAD_ATTEMPTS)
>        {
>            var osm_start = "http://tile.openstreetmap.org/";
>            this.src = osm_start + this.src.substr(mq_start.length);
>        }
>        else
>        {
>            this.src = mq_start + this.src.substr(mq_start.length);
>        }
>    }
>    OpenLayers.Util.originalOnImageLoadError();
> };
> 
> M.
> 
> -- 
> Martin Saturka
> Software Engineer, Sourcefabric
> www.sourcefabric.org
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev



More information about the Dev mailing list