Página 1 de 1

Creación de nuestro primer mapa con openlayers v4.3.1

Publicado: Vie Abr 13, 2018 8:55 am
por Jaibol Santaella
Hace poco publicamos como instalar openlayers en Linux.

Hoy explicaremos como crear un sencillo front-end para visualizar nuestro mapa utilizando openlayers y bing.

Si hacemos un "ls" para listar el directorio de openlayers observaremos que contiene los siguientes directorios y archivos:

Código: Seleccionar todo

root@Debian8-Desktop:/var/www/html/v4.3.1# ls

apidoc	build  closure-library	css  doc  examples  ol	ol.ext 
Por lo cual necesitaremos crear nuestro primer archivo (index.html)

Código: Seleccionar todo

touch index.html
Ahora debemos agregar a dicho archivo la arquitectura de cualquier html, posteriormente enlazar los css y js de openlayers en nuestro index.html.

Para ello copiar y pegar el siguiente código:

Código: Seleccionar todo

<!DOCTYPE html>
<html>
  <head>
    <title>Mi mapa Venezuela con openlayers</title>
    <link rel="stylesheet" href="/css/ol.css" type="text/css">
    <!-- 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>
    <script src="/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var layers = [
        new ol.layer.Tile({
          source: new ol.source.TileWMS({
            url: 'https://ahocevar.com/geoserver/wms',
            params: {
              'LAYERS': 'ne:NE1_HR_LC_SR_W_DR',
              'TILED': true
            }
          })
        })
      ];

      var map = new ol.Map({
        controls: ol.control.defaults().extend([
          new ol.control.ScaleLine({
            units: 'degrees'
          })
        ]),
        layers: layers,
        target: 'map',
        view: new ol.View({
          projection: 'EPSG:4326',
          center: [-64, 8],
          zoom: 6
        })
      });
    </script>
  </body>
</html>