1(function(window) { 2 'use strict'; 3 4 const openFreeMapAttribution = '<a href="https://openfreemap.org/" target="_blank" rel="noopener noreferrer">OpenFreeMap</a> © <a href="https://openmaptiles.org/" target="_blank" rel="noopener noreferrer">OpenMapTiles</a> Data from <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener noreferrer">OpenStreetMap</a>'; 5 6 function getRegistry() { 7 return window.oum_map_style_registry || {}; 8 } 9 10 function getStyleKey(mapStyle) { 11 const normalizedStyle = String(mapStyle || '').toLowerCase(); 12 13 return Object.keys(getRegistry()).find(function(styleKey) { 14 return styleKey.toLowerCase() === normalizedStyle; 15 }) || ''; 16 } 17 18 function getStyleDefinition(mapStyle) { 19 const styleKey = getStyleKey(mapStyle); 20 21 if (styleKey) { 22 return getRegistry()[styleKey]; 23 } 24 25 if (String(mapStyle || '').toLowerCase() === 'customimage') { 26 return { 27 provider: 'custom_image' 28 }; 29 } 30 31 return getOpenFreeMapDefinition(mapStyle); 32 } 33 34 function getOpenFreeMapDefinition(mapStyle) { 35 const styleSlug = String(mapStyle || '').replace(/^OpenFreeMap\./i, '').toLowerCase(); 36 const openFreeMapStyleUrls = { 37 liberty: 'https://tiles.openfreemap.org/styles/liberty', 38 bright: 'https://tiles.openfreemap.org/styles/bright', 39 positron: 'https://tiles.openfreemap.org/styles/positron', 40 dark: 'https://tiles.openfreemap.org/styles/dark', 41 fiord: 'https://tiles.openfreemap.org/styles/fiord' 42 }; 43 44 // Safety net for cached/optimized pages where localized registry data is missing. 45 return openFreeMapStyleUrls[styleSlug] 46 ? { 47 provider: 'openfreemap', 48 url: openFreeMapStyleUrls[styleSlug] 49 } 50 : null; 51 } 52 53 function ensureLeafletZoomBounds(map) { 54 // MarkerCluster requires a finite Leaflet maxZoom; vector layers do not provide one. 55 if (map && typeof map.getMaxZoom === 'function' && !isFinite(map.getMaxZoom()) && typeof map.setMaxZoom === 'function') { 56 map.setMaxZoom(20); 57 } 58 } 59 60 function getKey(options, key) { 61 return options && options[key] ? options[key] : ''; 62 } 63 64 function addCartoTileLayer(map, mapStyle, options) { 65 const cartoKey = getKey(options, 'cartoKey'); 66 67 // Saved no-key CARTO styles are switched server-side before this code runs. 68 if (!cartoKey) { 69 console.warn('Open User Map: This CARTO style requires an API key.'); 70 return null; 71 } 72 73 return window.L.tileLayer.provider(mapStyle, { 74 apikey: cartoKey 75 }).addTo(map); 76 } 77 78 function addCustomCartoLayers(map, style, options) { 79 const cartoKey = getKey(options, 'cartoKey'); 80 81 // Custom styles are built from direct CARTO tile URLs and need the key manually. 82 if (!cartoKey) { 83 console.warn('Open User Map: This CARTO style requires an API key.'); 84 return null; 85 } 86 87 const keyParam = '?key=' + encodeURIComponent(cartoKey); 88 window.L.tileLayer(style.carto_base_url + keyParam).addTo(map); 89 90 return window.L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png' + keyParam, { 91 tileSize: 512, 92 zoomOffset: -1 93 }).addTo(map); 94 } 95 96 function addMapBoxLayer(map, style, options) { 97 const mapboxKey = getKey(options, 'mapboxKey'); 98 99 // Saved no-key MapBox styles are switched server-side before this code runs. 100 if (!mapboxKey) { 101 console.warn('Open User Map: This MapBox style requires an API key.'); 102 return null; 103 } 104 105 return window.L.tileLayer.provider('MapBox', { 106 id: style.mapbox_id, 107 accessToken: mapboxKey 108 }).addTo(map); 109 } 110 111 function addCustomImageLayer(map, options) { 112 if (options && typeof options.setupCustomImageLayer === 'function') { 113 options.setupCustomImageLayer(); 114 } 115 116 if (options && options.customImageHideTiles) { 117 const layer = window.L.tileLayer('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', { 118 attribution: '', 119 opacity: 0 120 }).addTo(map); 121
122 if (options.customImageBackgroundColor) { 123 map.getContainer().style.backgroundColor = options.customImageBackgroundColor; 124 } 125 126 return layer; 127 } 128 129 return window.L.tileLayer.provider('OpenStreetMap.Mapnik').addTo(map); 130 } 131 132 function addOpenFreeMapLayer(map, style) { 133 if (!window.L || typeof window.L.maplibreGL !== 'function') { 134 console.warn('Open User Map: MapLibre assets are required for OpenFreeMap styles.'); 135 return window.L && window.L.tileLayer && window.L.tileLayer.provider 136 ? window.L.tileLayer.provider('OpenStreetMap.Mapnik').addTo(map) 137 : null; 138 } 139 140 ensureLeafletZoomBounds(map); 141 142 return window.L.maplibreGL({ 143 style: style.url, 144 attributionControl: { 145 customAttribution: openFreeMapAttribution 146 } 147 }).addTo(map); 148 } 149 150 function addBaseLayer(map, mapStyle, options) { 151 const style = getStyleDefinition(mapStyle) || {}; 152 153 if (style.provider === 'openfreemap') { 154 return addOpenFreeMapLayer(map, style); 155 } 156 157 if (style.provider === 'custom_image') { 158 return addCustomImageLayer(map, options); 159 } 160 161 if (style.mapbox_id) { 162 return addMapBoxLayer(map, style, options); 163 } 164 165 if (style.carto_base_url) { 166 return addCustomCartoLayers(map, style, options); 167 } 168 169 if (style.provider === 'carto') { 170 return addCartoTileLayer(map, mapStyle, options); 171 } 172 173 return window.L.tileLayer.provider(mapStyle).addTo(map); 174 } 175 176 window.OUMMapStyles = { 177 getStyleDefinition: getStyleDefinition, 178 isOpenFreeMapStyle: function(mapStyle) { 179 const style = getStyleDefinition(mapStyle); 180 181 return !!style && style.provider === 'openfreemap'; 182 }, 183 addOpenFreeMapLayer: function(map, mapStyle) { 184 const style = getStyleDefinition(mapStyle); 185 186 return style && style.provider === 'openfreemap' ? addOpenFreeMapLayer(map, style) : null; 187 }, 188 addBaseLayer: addBaseLayer 189 }; 190})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.