Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/06/2015, 10:27
Avatar de pcarvajal
pcarvajal
 
Fecha de Ingreso: enero-2002
Mensajes: 701
Antigüedad: 23 años, 2 meses
Puntos: 8
Pregunta arreglo dinamico de mapas solo me muestra el ultimo valor

Hola,
Estoy mostrando en un mapa de leaflet de la siguiente forma:

Código Javascript:
Ver original
  1. <script>       
  2.         //begin no modificar -->
  3.         var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>',
  4.             thunLink = '<a href="http://thunderforest.com/">Thunderforest</a>';
  5.        
  6.         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  7.             osmAttrib = '&copy; ' + osmLink + ' Contributors',
  8.             landUrl = 'http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png',
  9.             thunAttrib = '&copy; '+osmLink+' Contributors & '+thunLink;
  10.  
  11.         var osmMap = L.tileLayer(osmUrl, {attribution: osmAttrib}),
  12.             landMap = L.tileLayer(landUrl, {attribution: thunAttrib});
  13.  
  14.         var map = L.map('map', {
  15.                 layers: [osmMap] // only add one! este es mapa base
  16.             })
  17.             .setView([-33.4387,-70.647], 18); //Chile
  18.         //<-- end no modificar
  19.  
  20.  
  21.  
  22.         var baseLayers = {
  23.             "OSM Mapnik": osmMap,
  24.             "Landscape": landMap
  25.         };     
  26.        
  27. /////////////////////////////////////////////////////////////////////////////////////////////
  28. var overlays = {
  29.             'Precipitaciones': L.tileLayer.provider('OpenWeatherMap.PrecipitationClassic'),
  30.             'Lluvia': L.tileLayer.provider('OpenWeatherMap.RainClassic'),
  31.             'Presión': L.tileLayer.provider('OpenWeatherMap.Pressure'),
  32.             'Control de Presion': L.tileLayer.provider('OpenWeatherMap.PressureContour'),
  33.             'Viento': L.tileLayer.provider('OpenWeatherMap.Wind'),
  34.             'Temperatura': L.tileLayer.provider('OpenWeatherMap.Temperature')
  35.         };
  36. /////////////////////////////////////////////////////////////////////////////////////////////
  37.  
  38.    
  39.         L.control.layers(baseLayers,overlays).addTo(map);
  40.  
  41.     </script>
  42. </body>
  43. </html>

pero necesito modificar el codigo del overlay y armarlo dinamicamente, entonces tenemos:

Código Javascript:
Ver original
  1. <script>       
  2.         //begin no modificar -->
  3.         var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>',
  4.             thunLink = '<a href="http://thunderforest.com/">Thunderforest</a>';
  5.        
  6.         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  7.             osmAttrib = '&copy; ' + osmLink + ' Contributors',
  8.             landUrl = 'http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png',
  9.             thunAttrib = '&copy; '+osmLink+' Contributors & '+thunLink;
  10.  
  11.         var osmMap = L.tileLayer(osmUrl, {attribution: osmAttrib}),
  12.             landMap = L.tileLayer(landUrl, {attribution: thunAttrib});
  13.  
  14.         var map = L.map('map', {
  15.                 layers: [osmMap] // only add one! este es mapa base
  16.             })
  17.             .setView([-33.4387,-70.647], 18); //Chile
  18.         //<-- end no modificar
  19.  
  20.  
  21.         var baseLayers = {
  22.             "OSM Mapnik": osmMap,
  23.             "Landscape": landMap
  24.         };     
  25.  
  26. /////////////////////////////////////////////////////////////////////////////////////////////
  27. var overlays = {};
  28.         var item1 = "Lluvia";
  29.         var valor1 = "L.tileLayer.provider('OpenWeatherMap.PrecipitationClassic')";
  30.         var item2 = "Temperatura";
  31.         var valor2 = "L.tileLayer.provider('OpenWeatherMap.Temperature')";     
  32.  
  33.         overlays[item1] = valor1;
  34.         overlays[item2] = valor2;[/B][/COLOR]
  35. /////////////////////////////////////////////////////////////////////////////////////////////
  36.        
  37.         L.control.layers(baseLayers,overlays).addTo(map);
  38.  
  39.     </script>

el problema es que el menu solo me muestra el ultimo item que he agregado y no se como hacerlo para que me los muestre todos
__________________
18 laaaaargos años en FDW... y soy de los pocos que ví correr sangre! :X