Advertisement
leonidasliakos

cyclosm in google maps js api

Dec 10th, 2023 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.71 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>Demo</title>
  6.     <style>
  7.     /* styles */
  8.  
  9.     html, body {
  10.       margin: 0;
  11.       padding: 0;
  12.     }
  13.  
  14.     #map {
  15.       width: 100vw;
  16.       height: 100vh;
  17.     }
  18.     </style>
  19.   </head>
  20.   <body>
  21.  
  22.     <div id="map"></div>
  23.  
  24.     <script>
  25.     var TILE_URL = 'https://c.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png';
  26.  
  27.  
  28.     var map;
  29.     var mapEl;
  30.     var layer;
  31.     var layerID = 'my-custom-layer';
  32.  
  33.     window.initMap = function() {
  34.       // Select the element with id="map".
  35.       mapEl = document.querySelector('#map');
  36.      
  37.      
  38.       // Create a new map.
  39.       map = new google.maps.Map(mapEl, {
  40.         center: new google.maps.LatLng(38.43847193095969, 22.42851725578549),
  41.         disableDefaultUI: true,
  42.         zoom: 13
  43.       });
  44.      
  45.       // Create a tile layer, configured to fetch tiles from TILE_URL.
  46.       layer = new google.maps.ImageMapType({
  47.         name: layerID,
  48.         getTileUrl: function(coord, zoom) {
  49.           console.log(coord);
  50.           var url = TILE_URL
  51.             .replace('{x}', coord.x)
  52.             .replace('{y}', coord.y)
  53.             .replace('{z}', zoom);
  54.           return url;
  55.         },
  56.         tileSize: new google.maps.Size(256, 256),
  57.         minZoom: 1,
  58.         maxZoom: 20
  59.       });
  60.      
  61.       // Apply the new tile layer to the map.
  62.       map.mapTypes.set(layerID, layer);
  63.       map.setMapTypeId(layerID);
  64.     };
  65.     </script>
  66.    
  67.     <!-- NOTE: The 'key' parameter should be replaced with your Google Maps API Key. -->
  68.     <script src="https://maps.googleapis.com/maps/api/js?callback=initMap&key=<INSERT YOUR API KEY>"></script>
  69.    
  70.   </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement