Created
January 9, 2010 18:43
-
-
Save tmcw/273033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Google Maps API 2.0 | |
* MapBox integration. | |
* | |
* Do not remove the MapBox or OpenStreetMap attribution from this code, | |
* doing so is in violation of the terms of both licenses. | |
*/ | |
/** | |
* Factory function for a MapBox layer for use with a | |
* Google Map | |
* | |
* @param {string} layername | |
* layername in the TMS schema | |
* @param {string} layertitle | |
* layer will be called in the user interface | |
* @param {number} minZoom | |
* minimum (farthest out) zoom level, default 0 | |
* @param {number} maxZoom | |
* maximum (closest) zoom level, default 13 | |
* @return {GMapType} map | |
* GMapType object | |
*/ | |
function GMapBox(layername, layertitle, minZoom, maxZoom) { | |
var copyright, copyrightCollection, tilelayers, GMapTypeOptions; | |
if(minZoom === undefined) { | |
minZoom = 0; | |
} | |
if(maxZoom === undefined) { | |
maxZoom = 13; | |
} | |
// Copyright info | |
copyright = new GCopyright(1, | |
new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180) ), | |
0, "<a href='http://mapbox.com'><img src='mapbox.png'></a>"); | |
copyrightCollection = new GCopyrightCollection(); | |
copyrightCollection.addCopyright(copyright); | |
tilelayers = [new GTileLayer(copyrightCollection,minZoom,maxZoom)]; | |
tilelayers[0].getTileUrl = function(a,b){ | |
// Y coordinate is flipped in Mapbox, compared to Google | |
a.y = Math.abs(a.y - (Math.pow(2,b) - 1)); | |
return "http://a.tile.mapbox.com/1.0.0/" + layername + "/" + b + "/" + a.x + "/" + a.y + ".png"; | |
} | |
// Default options for the new map type. | |
GMapTypeOptions = {minResolution: minZoom, maxResolution: maxZoom}; | |
// Create the custom map type and add it to the map. | |
return new GMapType(tilelayers, new GMercatorProjection(maxZoom + 1), tilestitle, GMapTypeOptions); | |
} | |
map.addMapType(GMapBox('world-light', 'World Light')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment