Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/10/2017, 17:45
dairo65
 
Fecha de Ingreso: abril-2011
Mensajes: 168
Antigüedad: 13 años
Puntos: 5
poner imagen de fondo mapbox

saludos.

tengo este problema, y es que no se como poner una imagen de fondo para mi market aquí les dejo el codigo


Código Javascript:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset='utf-8' />
  5.     <title>MAPAS</title>
  6.     <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  7.     <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.41.0/mapbox-gl.js'></script>
  8.     <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.41.0/mapbox-gl.css' rel='stylesheet' />
  9.    
  10.     <style>
  11.         body {
  12.          margin:0; padding:0;
  13.           }
  14.         #map
  15.          {
  16.  
  17.             position:absolute; top:0; bottom:0; width:100%;
  18.              }
  19.  
  20.     </style>
  21. </head>
  22. <body>
  23.  
  24. <style>
  25. .coordinates {
  26.     background: rgba(0,0,0,0.5);
  27.     color: #fff;
  28.     position: absolute;
  29.     bottom: 10px;
  30.     left: 10px;
  31.     padding:5px 10px;
  32.     margin: 0;
  33.     font-size: 11px;
  34.     line-height: 18px;
  35.     border-radius: 3px;
  36.     display: none;
  37. }
  38.  
  39.  
  40. #point{
  41.   background-image: url('img/icono2.png');
  42.   background-size: cover;
  43.   width: 50px;
  44.   height: 50px;
  45.   border-radius: 50%;
  46.   cursor: pointer;  
  47. }
  48. </style>
  49.  
  50. <div id='map'></div>
  51. <pre id='coordinates' class='coordinates'></pre>
  52.  
  53. <script>
  54. mapboxgl.accessToken = 'pk.eyJ1IjoiZGFpcm9yaXZlcmExOTgyIiwiYSI6ImNqN2R6ZnA3cDBnNzUzNG10MmM1Z24xYTgifQ.7oz5IzjuIZOyXzFeuaekSw';
  55. // Holds mousedown state for events. if this
  56. // flag is active, we move the point on `mousemove`.
  57. var isDragging;
  58.  
  59. // Is the cursor over a point? if this
  60. // flag is active, we listen for a mousedown event.
  61. var isCursorOverPoint;
  62.  
  63. var coordinates = document.getElementById('coordinates');
  64. var map = new mapboxgl.Map({
  65.     container: 'map',
  66.     style: 'mapbox://styles/mapbox/streets-v9',
  67.    center: [ -73.357591, 5.544499],
  68.     zoom: 13
  69. });
  70.  
  71. var canvas = map.getCanvasContainer();
  72.  
  73. var geojson = {
  74.     "type": "FeatureCollection",
  75.     "features": [{
  76.         "type": "Feature",
  77.         "geometry": {
  78.             "type": "Point",
  79.             "coordinates": [ -73.357591, 5.544499]
  80.         }
  81.     }]
  82. };
  83.  
  84. function mouseDown() {
  85.     if (!isCursorOverPoint) return;
  86.  
  87.     isDragging = true;
  88.  
  89.     // Set a cursor indicator
  90.     canvas.style.cursor = 'grab';
  91.  
  92.     // Mouse events
  93.     map.on('mousemove', onMove);
  94.     map.once('mouseup', onUp);
  95. }
  96.  
  97. function onMove(e) {
  98.     if (!isDragging) return;
  99.     var coords = e.lngLat;
  100.  
  101.     // Set a UI indicator for dragging.
  102.     canvas.style.cursor = 'grabbing';
  103.  
  104.     // Update the Point feature in `geojson` coordinates
  105.     // and call setData to the source layer `point` on it.
  106.     geojson.features[0].geometry.coordinates = [coords.lng, coords.lat];
  107.     map.getSource('point').setData(geojson);
  108. }
  109.  
  110. function onUp(e) {
  111.     if (!isDragging) return;
  112.     var coords = e.lngLat;
  113.  
  114.     // Print the coordinates of where the point had
  115.     // finished being dragged to on the map.
  116.     coordinates.style.display = 'block';
  117.     coordinates.innerHTML = 'Longitude: ' + coords.lng + '<br />Latitude: ' + coords.lat;
  118.     canvas.style.cursor = '';
  119.     isDragging = false;
  120.  
  121.     // Unbind mouse events
  122.     map.off('mousemove', onMove);
  123. }
  124.  
  125. map.on('load', function() {
  126.  
  127.    
  128. // Añade un solo punto al mapa
  129.     map.addSource('point', {
  130.         "type": "geojson",
  131.         "data": geojson
  132.     });
  133.  
  134.     map.addLayer({
  135.         "id": "point",
  136.         "type": "circle",
  137.         "source": "point",
  138.         "paint": {
  139.             "circle-radius": 40,
  140.             "circle-color": "#3887be"
  141.             "background-image": "url('img/icono2.png')", ---------es aqui donde no me cuadra--------
  142.            
  143.         }
  144.     });
  145.  
  146.  
  147.  
  148.    
  149.  
  150.     // Cuando el cursor ingrese una característica en la capa de puntos, prepárese para arrastrar.
  151.     map.on('mouseenter', 'point', function() {
  152.         map.setPaintProperty('point', 'circle-color', 'yellow');
  153.         canvas.style.cursor = 'move';
  154.         isCursorOverPoint = true;
  155.         map.dragPan.disable();
  156.     });
  157.  
  158.     map.on('mouseleave', 'point', function() {
  159.         map.setPaintProperty('point', 'circle-color', 'green');/* accion al poner el mouse*/
  160.         canvas.style.cursor = '';
  161.         isCursorOverPoint = false;
  162.         map.dragPan.enable();
  163. });
  164.  
  165.  
  166.  
  167.     /// para posicionar al usuario
  168.  
  169. map.addControl(new mapboxgl.GeolocateControl({
  170.     positionOptions: {
  171.         enableHighAccuracy: true
  172.     },
  173.     trackUserLocation: true
  174. }));
  175.  
  176.     map.on('mousedown', mouseDown);
  177. });
  178.  
  179.  
  180.  
  181. </script>
  182.  
  183. </body>
  184. </html>


no se que estoy haciendo mal.

muchas gracias por su amable ayuda