Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
Javascript: Polygon not showing on the map

Why polygon not showing on the map? I was trying to highlight a specific location using polygon but it is not showing on the map even though there is no error. here is the code:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" 
    />
    <link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js"> 
</script>
<style>
  #map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
</style>
</head>
<body>
<div id="map">
  <a href="https://www.maptiler.com" 
style="position:absolute;left:10px;bottom:10px;z-index:999;"><img 
src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo"></a>
</div>
<p><a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a 
href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap 
contributors</a></p>
<script>
  var map = L.map('map').setView([8.94917, 125.54361], 12);
  L.tileLayer('https://api.maptiler.com/maps/streets/{z}/{x}/{y}.png? 
key=aLd1dKi19JrBFCzDze2p',{
    tileSize: 512,
    zoomOffset: -1,
    minZoom: 1,
    attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" 
target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca 
href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; 
OpenStreetMap contributors\u003c/a\u003e",
    crossOrigin: true
  }).addTo(map);
  var polygon = L.polygon([8.94917, 125.54361],[9.00333023, 125.48916626], 
[8.85280991, 125.66551208]).addTo(map);
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are several issues that prevent the map from displaying, and the polygon shape for loading:

  1. some small errors in source, caused by line returns: see browser console to check and correct these. (note these might not exist in your source, but may be caused by line wrapping when copy/pasting the source).

  2. Main issue is that the polygon coordinates should be wrapped in an array, as shown in bold in this example :

    var polygon = L.polygon( [ [8.94917, 125.54361],[9.00333023, 125.48916626], [8.85280991, 125.66551208] ] ).addTo(map);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda