gpt4 book ai didi

How to add Alt Tag to Images loaded via OpenLayer(如何为通过OpenLayer加载的图像添加Alt标签)

转载 作者:bug小助手 更新时间:2023-10-25 18:56:36 24 4
gpt4 key购买 nike



I need to automatically add Alt tag to images generated automatically via Openlayer.
I tried different solutions via Jquery and js, but none seems to work

我需要自动添加Alt标签到通过OpenLayer自动生成的图像。我通过jQuery和js尝试了不同的解决方案,但似乎都不起作用


How to add an alt attribute of img tags with jquery

如何用jQuery添加img标签的alt属性


Is there a way to add alt text to an img tag using jquery?

有没有一种方法可以使用jquery将alt文本添加到img标签中?


https://www.3schools.in/2022/04/how-to-add-alt-text-to-image-.html

Https://www.3schools.in/2022/04/how-to-add-alt-text-to-image-.html


Set <img> alt tag with JavaScript

使用JavaScript设置alt标记


jQuery add alt tag to images with same src

JQuery将alt标记添加到具有相同源的图像


I tried to call by class selector and directly by tag.
Unfortunatly I have no control on ID's that are dinamically generated by openlayer

我尝试通过类选择器和直接通过标记进行调用。不幸的是,我无法控制由OpenLayer动态生成的ID


here is my code

以下是我的代码




    // Size the parent iFrame
function iframeResize() {
var height = $('body').outerHeight(); // IMPORTANT: If body's height is set to 100% with CSS this will not work.
parent.postMessage("resize::"+height,"*");
}

$(document).ready(function() {
// Resize iframe
setInterval(iframeResize, 1000);
});


var lat=46.238043
var lon=12.4377325
var zoom=10

var mappa; //complex object of type OpenLayers.Map

function initgpx() {
mappa = new OpenLayers.Map ("mappa", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );


var grayscale = new OpenLayers.Layer.OSM('OSM Greyscale', null, {
eventListeners: {
tileloaded: function(evt) {
var ctx = evt.tile.getCanvasContext();
if (ctx) {
var imgd = ctx.getImageData(0, 0, evt.tile.size.w, evt.tile.size.h);
var pix = imgd.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
pix[i] = pix[i + 1] = pix[i + 2] = (3 * pix[i] + 4 * pix[i + 1] + pix[i + 2]) / 8;
}
ctx.putImageData(imgd, 0, 0);
evt.tile.imgDiv.removeAttribute("crossorigin");
evt.tile.imgDiv.src = ctx.canvas.toDataURL();
}
}
}
});

mappa.addLayers([ grayscale] );
mappa.addControl(new OpenLayers.Control.LayerSwitcher());


var pois_Alloggi = new OpenLayers.Layer.Text( "Alloggi", { location:"https://atorinfriul.it/html/tracce_gpx/POI_Mappa/Longarone(SS51)_Vajont_Barcis(Ponte_Antoi)__POI_Alloggi.txt", projection: mappa.displayProjection});
mappa.addLayer(pois_Alloggi);



// Add the Layer with the GPX Track
var lgpx = new OpenLayers.Layer.Vector("Tracciato", {strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({url: "https://atorinfriul.it/html/percorsi/Longarone(SS51)_Vajont_Barcis(Ponte_Antoi)__timestamp.gpx", format: new OpenLayers.Format.GPX()}),
style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5}, projection: new OpenLayers.Projection("EPSG:4326")});
mappa.addLayer(lgpx);



var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), mappa.getProjectionObject());
mappa.setCenter(lonLat, zoom);


}

function osm_getTileURL(bounds) {
var res = this.mappa.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.mappa.getZoom();
var limit = Math.pow(2, z);

if (y < 0 && y >= limit) {
return OpenLayers.Util.getImagesLocation() + "404.png";
} else {
x = ((x % limit) + limit) % limit;
return this.url + z + "/" + x + "/" + y + "." + this.type;
}
}

html, body{
width:100%;
height:100%;
}


.olControlAttribution {
padding: 5px;
bottom: 0.2em !important;
overflow: hidden;
width: 33%;
font-size: 1em !important;
text-align: right;
/* for IE */
filter:alpha(opacity=90);
/* CSS3 standard */
border-radius: 4px;
}

<!DOCTYPE html>
<html lang="it">

<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">

<meta http-equiv="Cache-control" content="public, max-age=31536000, immutable">

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<!-- JS sezione Mappa POI's -->
<script src="https://atorinfriul.it/html/js/lib/OpenLayers.js"></script>
<script src="https://atorinfriul.it/html/js/OpenStreetMap.js"></script>

<!-- bring in the OpenStreetMap OpenLayers layers. Using this hosted file will make sure we are kept up to date with any necessary changes -->



<script type='text/javascript' src="https://atorinfriul.it/html/js/jquery.min.js"></script>

</head>
<!-- body.onload is called once the page is loaded (call the 'init' function) -->
<body onload="initgpx();"> <!-- define a DIV into which the map will appear. Make it take up the whole window -->



<div style="width:100%; height:90% ;border: 1px solid blue; background: url('https://atorinfriul.it/html/images/caricamento.gif') no-repeat center center; background-size: cover;" id="mappa"></div>
<script type="text/javascript">
$(function(){
jQuery(document).ready(function() {

//$('#mappa > img[alt]').attr('image');

$('img').attr('alt', 'Whatever you want');

//$('img:not([alt])').attr('alt', 'logo');

});
});
</script>





</body>
</html>




In bottom section I left my unsuccessful tries, uncommenting previous.

在底部,我留下了我不成功的尝试,没有评论以前的。


I noted, in snippet, map did't show gpx track and poi icon, but on real file them working perfect

我注意到,在代码片段中,地图没有显示GPX曲目和POI图标,但在真实文件中,它们工作得很好


in addition:
I use Openlayer 2.31 and check result via https://pagespeed.web.dev/

另外:我使用OpenLayer2.31,并通过https://pagespeed.web.dev/查看结果


Thanks for any suggestion

谢谢你的建议


更多回答
优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com