LoginSignup
3
6

More than 5 years have passed since last update.

OpenLayers v5.1.3 による地図表示例

Last updated at Posted at 2018-08-26

OpenLayers ExamplesGIS OpenLayers3 Raster Layer の例を参考に、OepnLayers パッケージのダウンロードなしで、各種地図を OepnLayers v5.1.3 で表示するように調整。

  • 動作確認環境: MacbookPro (2015early), google chrome (68.0.3440.106,64bit)

OSM (OpenStreetMap)

osm-tiles.html
<!DOCTYPE html>
<html>
  <head>
    <title>Canvas Tiles</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v5.1.3/css/ol.css" type="text/css">
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3/build/ol.js"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <title>OpenLayers 5.1.3 example OSM+debug</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var osmSource = new ol.source.OSM();
      var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: osmSource
          })
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: {
            collapsible: false
          }
        }),
        view: new ol.View({
          center: ol.proj.fromLonLat([139.63, 35.51]),
          zoom: 10
        })
      });
    </script>
  </body>
</html>

Stamen Tile Server (watercolor)

stamen-water-tiles.html
<!DOCTYPE html>
<html>
  <head>
    <title>Canvas Tiles</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v5.1.3/css/ol.css" type="text/css">
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3/build/ol.js"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <title>OpenLayers 5.1.3 example STAMEN+debug</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var stamenSource = new ol.source.Stamen({layer: 'watercolor'});
      var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: stamenSource
          })
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: {
            collapsible: false
          }
        }),
        view: new ol.View({
          center: ol.proj.fromLonLat([139.63, 35.51]),
          zoom: 10
        })
      });
    </script>
  </body>
</html>

Stamen Tile Server (toner)

stamen-toner-tiles.html
<!DOCTYPE html>
<html>
  <head>
    <title>Canvas Tiles</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v5.1.3/css/ol.css" type="text/css">
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3/build/ol.js"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <title>OpenLayers 5.1.3 example STAMEN+debug</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var stamenSource = new ol.source.Stamen({layer: 'toner'});
      var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: stamenSource
          })
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: {
            collapsible: false
          }
        }),
        view: new ol.View({
          center: ol.proj.fromLonLat([139.63, 35.51]),
          zoom: 10
        })
      });
    </script>
  </body>
</html>

地理院タイル (白地図)

gsi-tiles.html
<!DOCTYPE html>
<html>
  <head>
    <title>Canvas Tiles</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v5.1.3/css/ol.css" type="text/css">
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3/build/ol.js"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <title>OpenLayers 5.1.3 example GSI+debug</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var gsi_raster = new ol.layer.Tile({
        source: new ol.source.XYZ({
          attribution: [
            new ol.control.Attribution({
              html: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院白地図</a>"
            })
          ],
          url: "https://cyberjapandata.gsi.go.jp/xyz/blank/{z}/{x}/{y}.png",
          projection: "EPSG:3857"
        })
      });

      var map = new ol.Map({
        layers: [
          gsi_raster
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: {
            collapsible: false
          }
        }),
        view: new ol.View({
          center: ol.proj.fromLonLat([139.63, 35.51]),
          zoom: 10
        })
      });
    </script>
  </body>
</html>
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6