OpenLayers 3 Beginner’s Guide

Go mobile!

Open sample in a new windows

<!doctype html>
<html>
  <head>
    <title>Mobile Examples</title>
    <!-- the viewport is important for mobile devices -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="../assets/ol3/css/ol.css" type="text/css" />
    <link rel="stylesheet" href="../assets/css/samples.css" type="text/css" />
  </head>
  <body>
    <div id="map" class="full-map"></div>
    <script src="../assets/ol3/js/ol.js"></script>
    <script>
      // other than adding the <meta> viewport above, our normal setup will
      // work fine for mobile
      var layer = new ol.layer.Tile({
        source: new ol.source.OSM()
      });
      var london = ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857');
      var view = new ol.View({
        center: london,
        zoom: 6
      });
      var map = new ol.Map({
        target: 'map',
        layers: [layer],
        view: view
      });
    </script>
  </body>
</html>