This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How do I add a map key in my “openlayers” local OSM map?

0

Hello,

I want to show MAP key as it is there on https://www.openstreetmap.org/#map=9/23.2439/71.1063

Below is my simple code for map:

<div id="ourMap"></div>

<script  src="http://www.openlayers .org/api/OpenLayers.js"></script> 
<script>  
    map = new  OpenLayers.Map("ourMap"); 
    map.addLayer(new  OpenLayers.Layer.OSM());  
    map.zoomToMaxExtent(); 
</script>

Is there any feature which I have to turn on to show the Map key with same feature as it is giving in above URL?

Regards, Hardik Pancholi

asked 07 Apr '14, 11:02

hardikpancholi85's gravatar image

hardikpancho...
41335
accept rate: 0%

edited 07 Apr '14, 13:41

scai's gravatar image

scai ♦
33.3k21309459


One Answer:

2

OpenLayers doesn't support an OpenStreetMap Map Key out of the box, so there's no single feature you can enable for this purpose. Also, the OpenStreetMap main page uses Leaflet rather than OpenLayers, which makes a copy&paste somewhat difficult.

Maybe you could use this URL as a starting point to get at least the Map Key information and then enable/disable some of the elements according to your zoom layer (see data-zoom-min/data-zoom-max below). The question remains how to best embed that URL in your application. Maybe you want to use concept similar to a side bar to display your Map Key.

tr class="mapkey-table-entry" data-zoom-max="19" data-zoom-min="0" data-layer="mapnik"

answered 21 Apr '14, 08:05

mmd's gravatar image

mmd
5.7k15388
accept rate: 37%

Source code available on GitHub .