I want to know how I can interact with OpenStreetMap in a webpage via (only HTML, CSS, JavaScript) without Leaflet, OpenLayers, MapBox or anything like them (in backend or frontend). I am going to use pure OpenStreetMap only through URL.
For example in below code it seems I didn't run Leaflet but when I went to inspect webpage by DevTools I got Leaflet is running! And zoom control panel was belong to Leaflet.
I learned and used this question "openstreetmap-embedding-map-in-webpage-like-google-maps" asked in stackoverflow already.
<iframe width="400" height="600" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.openstreetmap.org/export/embed.html?bbox=51.2016004294,35.6079433209,51.5569619459,35.7819296463&layer=mapnik" style="border: 1px solid black"></iframe>
But when I changed code to different coordinate and webpage loaded again I saw map loaded perfect together with Leaflet control! Whereas I didn't write any code in page it will want to run Leaflet!
Best Answer
If you want to avoid any external libraries then you have to load the tiles directly.
OMS's standard tile layer uses TMS and consists of the following tile URLs:
To show a specific location you have to specify the zoom level
z
, longitudex
and latitudey
. How to do this is explained at slippy map tilenames, including example implementations in various languages.Example: https://b.tile.openstreetmap.org/13/4409/2741.png
To implement panning you have to change
x
andy
accordingly. To implement zooming you have to increase/decreasez
and adaptx
andy
to match the new subtile.