OSM.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the 2-clause BSD license.
  3. * See license.txt in the OpenLayers distribution or repository for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Layer/XYZ.js
  7. */
  8. /**
  9. * Class: OpenLayers.Layer.OSM
  10. * This layer allows accessing OpenStreetMap tiles. By default the OpenStreetMap
  11. * hosted tile.openstreetmap.org Mapnik tileset is used. If you wish to use
  12. * a different layer instead, you need to provide a different
  13. * URL to the constructor. Here's an example for using OpenCycleMap:
  14. *
  15. * (code)
  16. * new OpenLayers.Layer.OSM("OpenCycleMap",
  17. * ["http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
  18. * "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
  19. * "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"]);
  20. * (end)
  21. *
  22. * Inherits from:
  23. * - <OpenLayers.Layer.XYZ>
  24. */
  25. OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
  26. /**
  27. * APIProperty: name
  28. * {String} The layer name. Defaults to "OpenStreetMap" if the first
  29. * argument to the constructor is null or undefined.
  30. */
  31. name: "OpenStreetMap",
  32. /**
  33. * APIProperty: url
  34. * {String} The tileset URL scheme. Defaults to
  35. * : http://[a|b|c].tile.openstreetmap.org/${z}/${x}/${y}.png
  36. * (the official OSM tileset) if the second argument to the constructor
  37. * is null or undefined. To use another tileset you can have something
  38. * like this:
  39. * (code)
  40. * new OpenLayers.Layer.OSM("OpenCycleMap",
  41. * ["http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
  42. * "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
  43. * "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"]);
  44. * (end)
  45. */
  46. url: [
  47. 'http://a.tile.openstreetmap.org/${z}/${x}/${y}.png',
  48. 'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png',
  49. 'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'
  50. ],
  51. /**
  52. * Property: attribution
  53. * {String} The layer attribution.
  54. */
  55. attribution: "&copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors",
  56. /**
  57. * Property: sphericalMercator
  58. * {Boolean}
  59. */
  60. sphericalMercator: true,
  61. /**
  62. * Property: wrapDateLine
  63. * {Boolean}
  64. */
  65. wrapDateLine: true,
  66. /** APIProperty: tileOptions
  67. * {Object} optional configuration options for <OpenLayers.Tile> instances
  68. * created by this Layer. Default is
  69. *
  70. * (code)
  71. * {crossOriginKeyword: 'anonymous'}
  72. * (end)
  73. *
  74. * When using OSM tilesets other than the default ones, it may be
  75. * necessary to set this to
  76. *
  77. * (code)
  78. * {crossOriginKeyword: null}
  79. * (end)
  80. *
  81. * if the server does not send Access-Control-Allow-Origin headers.
  82. */
  83. tileOptions: null,
  84. /**
  85. * Constructor: OpenLayers.Layer.OSM
  86. *
  87. * Parameters:
  88. * name - {String} The layer name.
  89. * url - {String} The tileset URL scheme.
  90. * options - {Object} Configuration options for the layer. Any inherited
  91. * layer option can be set in this object (e.g.
  92. * <OpenLayers.Layer.Grid.buffer>).
  93. */
  94. initialize: function(name, url, options) {
  95. OpenLayers.Layer.XYZ.prototype.initialize.apply(this, arguments);
  96. this.tileOptions = OpenLayers.Util.extend({
  97. crossOriginKeyword: 'anonymous'
  98. }, this.options && this.options.tileOptions);
  99. },
  100. /**
  101. * Method: clone
  102. */
  103. clone: function(obj) {
  104. if (obj == null) {
  105. obj = new OpenLayers.Layer.OSM(
  106. this.name, this.url, this.getOptions());
  107. }
  108. obj = OpenLayers.Layer.XYZ.prototype.clone.apply(this, [obj]);
  109. return obj;
  110. },
  111. CLASS_NAME: "OpenLayers.Layer.OSM"
  112. });