NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I'm new to OpenStreetMap and OpenLayers and want my map to resemble the Transport Map on the OpenStreetMap website.

My init() function looks like this: function init() { map = new OpenLayers.Map("map"); var mapnik = new OpenLayers.Layer.OSM(); map.addLayer(mapnik); var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984 var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection var position = new OpenLayers.LonLat(-1.83, 52.60).transform(fromProjection, toProjection); var zoom = 7; map.setCenter(position, zoom); }

My map currently looks like the Standard one. Does the OpenLayers.Layer.OSM() constructor take any parameters?

asked 07 Apr '13, 13:18

id94's gravatar image

id94
11112
accept rate: 0%

edited 08 Apr '13, 15:52

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


Try this

function init() {
        map = new OpenLayers.Map("map");
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        var mapnik = new OpenLayers.Layer.OSM();
        map.addLayer(mapnik);
        var transportmap = new  OpenLayers.Layer.OSM.TransportMap("OpenTransportMap"); //defined here http://www.openstreetmap.org/openlayers/OpenStreetMap.js
        map.addLayer(transportmap);
        var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
        var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
        var position = new OpenLayers.LonLat(-1.83, 52.60).transform(fromProjection, toProjection);
        var zoom = 7;
        map.setCenter(position, zoom);
    }
permanent link

answered 08 Apr '13, 19:20

amritkarma's gravatar image

amritkarma
684212941
accept rate: 11%

I've figured it out. I used WireShark to watch what my browser was doing while using the Transport Map and I can see the following HTTP headers being sent:

GET /transport/16/35668/20346.png HTTP/1.1
Host: b.tile2.opencyclemap.org
...

Looks like it using a tile server hosted by opencyclemap.org.

permanent link

answered 07 Apr '13, 18:52

id94's gravatar image

id94
11112
accept rate: 0%

1

Please make sure that you abide by the terms and conditions under which these tiles are offered!

(07 Apr '13, 21:18) Richard ♦
1

Thanks for the link to Thunderforest and the Ts & Cs. Doh! I've only just noticed the attribution at the bottom of the Transport map to Andy Allan and opencyclemap.org so perhaps my super-sleuthing was unnecessary!

(08 Apr '13, 09:56) id94
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×535
×122
×16

question asked: 07 Apr '13, 13:18

question was seen: 9,140 times

last updated: 08 Apr '13, 19:20

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum