1/* (c) Copyright 2022 MiKa (http://wp-osm-plugin.Hyumika.com) 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; either version 2 of the License, or 6 (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16*/ 17 18function osm_addClusterPopupClickhandler(a_MapObj, a_MapStr) { 19 20 var container_div_id = a_MapStr + "_popup"; 21 var content_div_id = a_MapStr + "_popup-content"; 22 var closer_div_id = a_MapStr + "_popup-closer"; 23 24 var container = document.getElementById(container_div_id); 25 var content = document.getElementById(content_div_id); 26 var closer = document.getElementById(closer_div_id); 27 28 var popup = new ol.Overlay(/** @type {olx.OverlayOptions} */ ({ 29 element: container, 30 autoPan: true, 31 autoPanAnimation: { 32 duration: 250 33 } 34 })); 35 36 closer.onclick = function() { 37 popup.setPosition(undefined); 38 closer.blur(); 39 return false; 40 }; 41 42 a_MapObj.addOverlay(popup); 43 44 var ClickdisplayFeatureInfo = function(a_evt) { 45 var lonlat = ol.proj.transform(a_evt.coordinate, "EPSG:3857", "EPSG:4326"); 46 var lon = lonlat[0]; 47 var lat = lonlat[1]; 48 49 pixel = a_evt.pixel; 50 51 var features = []; 52 var NumOfNamedFeatures = 0; 53 a_MapObj.forEachFeatureAtPixel(pixel, function(feature, layer) { 54 features.push(feature); 55 }); 56 if (features.length > 0) { 57 58 var name_str, desc_str, info = []; 59 var description_str = []; 60 var i, ii; 61 for (i = 0, ii = features.length; i < ii; ++i) { 62 var cluster_features = features[i].get('features'); 63 if (cluster_features.length == 1){ 64 if (cluster_features[i].get("name")){ 65 NumOfNamedFeatures++; 66 name_str = cluster_features[i].get("name"); 67 desc_str = cluster_features[i].get("desc"); 68 description_str = features[i].get("description"); 69 if (desc_str != undefined){ 70 name_str = name_str + "<br>" + desc_str; 71 } 72 if (description_str != undefined){ 73 name_str = name_str + "<br>" + description_str; 74 } 75 if (cluster_features[i].length > 0) {name_str = name_str + "<br>"} 76 } 77 else{ 78 79 } 80 info.push(name_str); 81 } 82 } 83 84 content.innerHTML = info.join("") || "(unknown)"; 85 if (NumOfNamedFeatures > 0){ 86 popup.setPosition(a_evt.coordinate); 87 } 88 else { 89 popup.setPosition(undefined); 90 } 91 } 92 }; 93 a_MapObj.on("singleclick", function(evt) {ClickdisplayFeatureInfo(evt);}); 94} 95 96 97 98function osm_addPopupClickhandler(a_MapObj, a_MapStr) { 99 var container_div_id = a_MapStr + "_popup"; 100 var content_div_id = a_MapStr + "_popup-content"; 101 var closer_div_id = a_MapStr + "_popup-closer"; 102 103 var container = document.getElementById(container_div_id); 104 var content = document.getElementById(content_div_id); 105 var closer = document.getElementById(closer_div_id); 106 107 var popup = new ol.Overlay(/** @type {olx.OverlayOptions} */ ({ 108 element: container, 109 autoPan: true, 110 autoPanAnimation: { 111 duration: 250 112 } 113 })); 114 115 closer.onclick = function() { 116 popup.setPosition(undefined); 117 closer.blur(); 118 return false; 119 }; 120 121 a_MapObj.addOverlay(popup); 122 123 var ClickdisplayFeatureInfo = function(a_evt) { 124 var lonlat = ol.proj.transform(a_evt.coordinate, "EPSG:3857", "EPSG:4326"); 125 var lon = lonlat[0]; 126 var lat = lonlat[1]; 127 128 pixel = a_evt.pixel; 129 130 var features = []; 131 var NumOfNamedFeatures = 0; 132 a_MapObj.forEachFeatureAtPixel(pixel, function(feature, layer) { 133 features.push(feature); 134 }); 135 if (features.length > 0) { 136 var name_str, desc_str, info = []; 137 var description_str = []; 138 var i, ii; 139 for (i = 0, ii = features.length; i < ii; ++i) { 140 if (features[i].get("name")){ 141 NumOfNamedFeatures++; 142 name_str = features[i].get("name"); 143 desc_str = features[i].get("desc"); 144 description_str = features[i].get("description"); 145 if (desc_str != undefined){ 146 name_str = name_str + "<br>" + desc_str; 147 } 148 if (description_str != undefined){ 149 name_str = name_str + "<br>" + description_str; 150 } 151 if (features.length > 0) {name_str = name_str + "<br>"} 152 } 153 else{ 154 //name_str = "empty"; 155 } 156 info.push(name_str); 157 } 158 159 content.innerHTML = info.join("") || "(unknown)"; 160 if (NumOfNamedFeatures > 0){ 161 popup.setPosition(a_evt.coordinate); 162 } 163 else { 164 popup.setPosition(undefined); 165 } 166 } 167 }; 168 a_MapObj.on("singleclick", function(evt) {ClickdisplayFeatureInfo(evt);}); 169} 170 171 172 173 174function osm_addMarkerLayer(a_mapname, a_lon, a_lat, a_MarkerIcon, a_MarkerXAnchor, a_MarkerYAnchor, a_MarkerText) { 175 var iconFeature = new ol.Feature({ 176 geometry: new ol.geom.Point( 177 ol.proj.transform([a_lon,a_lat], "EPSG:4326", "EPSG:3857")), 178 name: a_MarkerText 179 }); 180 var iconStyle = new ol.style.Style({ 181 image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ 182 anchor: [(a_MarkerXAnchor * -1),(a_MarkerYAnchor * -1)], 183 anchorXUnits: "pixels", 184 anchorYUnits: "pixels", 185 opacity: 0.9, 186 src: a_MarkerIcon 187 })) 188 }); 189 iconFeature.setStyle(iconStyle); 190 191 var vectorMarkerSource = new ol.source.Vector({ 192 features: [iconFeature] 193 }); 194 195 var vectorMarkerLayer = new ol.layer.Vector({ 196 source: vectorMarkerSource, 197 zIndex: 92 198 }); 199 200 a_mapname.addLayer(vectorMarkerLayer); 201} 202 203function osm_addMouseHover(a_mapname){ 204 a_mapname.on('pointermove', function(evt) { 205 a_mapname.getTargetElement().style.cursor = 206 a_mapname.hasFeatureAtPixel(evt.pixel) ? 'pointer' : ''; 207 }); 208} 209 210function getTileLayer(a_source, a_api_key) { 211 212/* ++++++++ quickfix since stamen is now hosted by Stadia Maps */ 213 if ((a_source == "stamen_toner") || (a_source == "stamen_watercolor") || (a_source == "stamen_terrain")||(a_source == "stamen_terrain-labels")){ 214 a_source = "osm"; 215 } 216/* ------- */ 217 218 if ((a_source == "osm") || (a_source == "brezhoneg")||(a_source == "openseamap")){ 219 return new ol.layer.Tile({ 220 source: new ol.source.OSM({ }), 221 zIndex: 90 222 }); 223 } 224 else if (a_source == "hot"){ 225 return new ol.layer.Tile({ 226 source: new ol.source.OSM({ 227 attributions: "Maps © " + 228 "<a href=\"http://hot.openstreetmap.org/\">Humanitarian OpenStreetMap Team.</a>" + ol.source.OSM.ATTRIBUTION, 229 url: "https://{a-c}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png" 230 }), 231 zIndex: 90 232 }); 233 } 234 else if (a_source == "opentopomap"){ 235 return new ol.layer.Tile({ 236 source: new ol.source.XYZ({ 237 attributions: "Kartendarstellung: ©" + "<a href=\"https://opentopomap.org\">OpenTopoMap</a> (<a href=\"https://creativecommons.org/licenses/by-sa/3.0/\">CC-BY-SA</a>)" + "Maps © " + 238 "<a href=\"http://viewfinderpanoramas.org\">SRTM</a>" + ol.source.OSM.ATTRIBUTION, 239 url: "https://{a-c}.tile.opentopomap.org/{z}/{x}/{y}.png" 240 }), 241 zIndex: 90 242 }); 243 } 244 else if (a_source == "stamen_toner"){ 245 return new ol.layer.Tile({ 246 source: new ol.source.Stamen({ 247 layer: "toner" 248 }), 249 zIndex: 90 250 }); 251 } 252 else if (a_source == "stamen_watercolor"){ 253 return new ol.layer.Tile({ 254 source: new ol.source.Stamen({ 255 layer: "watercolor" 256 }), 257 zIndex: 90 258 }); 259 } 260 else if (a_source == "stamen_terrain"){ 261 return new ol.layer.Tile({ 262 source: new ol.source.Stamen({ 263 layer: "terrain" 264 }), 265 zIndex: 90 266 }); 267 } 268 else if (a_source == "stamen_terrain-labels"){ 269 return new ol.layer.Tile({ 270 source: new ol.source.Stamen({ 271 layer: "terrain-labels"}), 272 zIndex: 90 273 }); 274 } 275 else if (a_source == "cyclemap"){ 276 return new ol.layer.Tile({ 277 source: new ol.source.OSM({ 278 attributions: "Maps © " + 279 "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION, 280 url: "https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey="+ a_api_key 281 }), 282 zIndex: 90 283 }); 284 } 285 else if (a_source == "outdoor"){ 286 return new ol.layer.Tile({ 287 source: new ol.source.OSM({ 288 attributions: "Maps © " + 289 "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION, 290 url: "https://{a-c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png?apikey="+ a_api_key 291 }), 292 zIndex: 90 293 }); 294 } 295 296 else if (a_source == "landscape"){ 297 return new ol.layer.Tile({ 298 source: new ol.source.OSM({ 299 attributions: "Maps © " + 300 "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION, 301 url: "https://{a-c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey="+ a_api_key 302 }), 303 zIndex: 90 304 }); 305 } 306 307 else if (a_source == "spinal"){ 308 return new ol.layer.Tile({ 309 source: new ol.source.OSM({ 310 attributions: "Maps © " + 311 "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION, 312 url: "https://{a-c}.tile.thunderforest.com/spinal-map/{z}/{x}/{y}.png?apikey="+ a_api_key 313 }), 314 zIndex: 90 315 }); 316 } 317 else if (a_source == "pioneer"){ 318 return new ol.layer.Tile({ 319 source: new ol.source.OSM({ 320 attributions: "Maps © " + 321 "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION, 322 url: "https://{a-c}.tile.thunderforest.com/pioneer/{z}/{x}/{y}.png?apikey="+ a_api_key 323 }), 324 zIndex: 90 325 }); 326 327 } 328 329 else if (a_source == "basemap_at"){ 330 331 var template = "{Layer}/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"; 332 var urls_basemap = [ 333 "https://mapsneu.wien.gv.at/basemap/" + template 334 ]; 335 336 // HiDPI support: 337 // * Use "bmaphidpi" layer (pixel ratio 2) for device pixel ratio > 1 338 // * Use "geolandbasemap" layer (pixel ratio 1) for device pixel ratio == 1 339 var hiDPI = ol.has.DEVICE_PIXEL_RATIO > 1; 340 341 var source_basemap = new ol.source.WMTS({ 342 projection: "EPSG:3857", 343 //layer: hiDPI ? "bmaphidpi" : "geolandbasemap", 344 layer: "geolandbasemap", 345 tilePixelRatio: hiDPI ? 2 : 1, 346 style: "normal", 347 matrixSet: "google3857", 348 urls: urls_basemap, 349 requestEncoding: "REST", 350 tileGrid: new ol.tilegrid.WMTS({ 351 origin: [-20037508.3428, 20037508.3428], 352 resolutions: [ 353 559082264.029 * 0.28E-3, 354 279541132.015 * 0.28E-3, 355 139770566.007 * 0.28E-3, 356 69885283.0036 * 0.28E-3, 357 34942641.5018 * 0.28E-3, 358 17471320.7509 * 0.28E-3, 359 8735660.37545 * 0.28E-3, 360 4367830.18773 * 0.28E-3, 361 2183915.09386 * 0.28E-3, 362 1091957.54693 * 0.28E-3, 363 545978.773466 * 0.28E-3, 364 272989.386733 * 0.28E-3, 365 136494.693366 * 0.28E-3, 366 68247.3466832 * 0.28E-3, 367 34123.6733416 * 0.28E-3, 368 17061.8366708 * 0.28E-3, 369 8530.91833540 * 0.28E-3, 370 4265.45916770 * 0.28E-3, 371 2132.72958385 * 0.28E-3, 372 1066.36479193 * 0.28E-3 373 ], 374 matrixIds: [ 375 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 376 ] 377 }), 378 379 attributions: "Tiles © " + 380 "<a href=\"http://www.basemap.at/\">basemap.at</a>" + ol.source.OSM.ATTRIBUTION, 381 }); 382 383 384 return new ol.layer.Tile({ 385 extent: [977844.377599999, 5837774.6617, 1915609.8654, 6295560.8122], 386 source: source_basemap 387 }) 388 389 } 390 391 else {// unknwon => OSM map 392 return new ol.layer.Tile({ 393 source: new ol.source.OSM() 394 }); 395 } 396} 397 398function getVectorClusterLayer(a_vectorMarkerSource, a_taggedborderColor, a_taggedinnerColor, a_IconURL, a_IconOffsetwidth, a_IconOffsetheight) { 399 400 var clusterSource = new ol.source.Cluster({ 401 distance: 30, 402 source: a_vectorMarkerSource, 403 zIndex: 92 404 }); 405 406 var styleCache = {}; 407 var vectorMarkerLayer = new ol.layer.Vector({ 408 source: clusterSource, 409 zIndex: 92, 410 style: function(feature, resolution) { 411 var size = feature.get("features").length; 412 var features = feature.get("features"); 413 414 if (size > 1){ 415 var style = styleCache[size]; 416 if (!style) { 417 style = [new ol.style.Style({ 418 image: new ol.style.Circle({ 419 radius: 12, 420 stroke: new ol.style.Stroke({ 421 color: a_taggedborderColor, 422 width: 6, 423 }), 424 fill: new ol.style.Fill({ 425 color: a_taggedinnerColor 426 }) 427 }), 428 text: new ol.style.Text({ 429 text: size.toString(), 430 fill: new ol.style.Fill({ 431 color: "#fff" 432 }) 433 }) 434 })]; 435 styleCache[size] = style; 436 } 437 return style; 438 } 439 else { 440 var style = styleCache[size]; 441 if (!style) { 442 style = [new ol.style.Style({ 443 image: new ol.style.Icon(({ 444 anchor: [(a_IconOffsetwidth*-1),(a_IconOffsetheight*-1)], 445 anchorXUnits: "pixels", 446 anchorYUnits: "pixels", 447 opacity: 0.9, 448 src: a_IconURL})) 449 })]; 450 styleCache[size] = style; 451 } 452 return style; 453 } 454 } 455 }); 456 return vectorMarkerLayer; 457 458} 459
460function addControls2Map(a_map, MousePosition, OverviewMap, Rotate,Scaleline,Zoom,ZoomSlider,ZoomToExtent,FullScreen, Attribution) { 461 462 var osm_controls = [ 463 new ol.control.Attribution(), 464 new ol.control.MousePosition({ 465 undefinedHTML: "outside", 466 projection: "EPSG:4326", 467 coordinateFormat: function(coordinate) { 468 return ol.coordinate.format(coordinate, "{y}, {x}", 5); 469 } 470 }), 471 new ol.control.OverviewMap({ 472 layers: [ 473 new ol.layer.Tile({ 474 source: new ol.source.OSM(), 475 }), 476 ], 477 collapsed: false, 478 }), 479 new ol.control.Rotate({ 480 autoHide: false 481 }), 482 new ol.control.ScaleLine(), 483 new ol.control.Zoom(), 484 new ol.control.ZoomSlider(), 485 new ol.control.ZoomToExtent({ 486 extent: [-11243808.051695308, 1.202710291, 9561377.290892059, 6852382.107835932] 487 }), 488 new ol.control.FullScreen() 489 ]; 490 491 if (Scaleline == 1){a_map.addControl(osm_controls[4]);} 492 if (MousePosition == 1){a_map.addControl(osm_controls[1]);} 493 if (OverviewMap == 1){a_map.addControl(osm_controls[2]);} 494 if (FullScreen == 1){a_map.addControl(osm_controls[8]);} 495 if (Attribution == 0){ 496 a_map.getControls().forEach(function(control) { 497 if (control instanceof ol.control.Attribution) { 498 a_map.removeControl(control); 499 } 500 }, this); 501 } 502 503} 504
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.