<div dir="ltr">Hello everybody,<div><br></div><div style>I am building a dynamic webmapping. I am able to update layer and symboloy of my map with openlayers but I am not able to update the legende that go with.</div><div style>
<br></div><div style>My script to update map and legend through a choose in a list :</div><div style><br></div><div style><div>function changeBySelect(layerToRedraw) {</div><div><span class="" style="white-space:pre"> </span>if (layerToRedraw == "alea"){</div>
<div><span class="" style="white-space:pre"> </span>var layerNumber = 0;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (layerToRedraw == "bati"){</div>
<div><span class="" style="white-space:pre"> </span>var layerNumber = 1;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (layerToRedraw == "routes"){</div>
<div><span class="" style="white-space:pre"> </span>var layerNumber = 2;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (layerToRedraw == "croisements"){</div>
<div><span class="" style="white-space:pre"> </span>var layerNumber = 3;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (layerToRedraw == "ZRO"){</div>
<div><span class="" style="white-space:pre"> </span>var layerNumber = 4;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (mappanel.map.getZoom() == 10){</div>
<div><span class="" style="white-space:pre"> </span>var layerScale = 0;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (mappanel.map.getZoom() == 11){</div>
<div><span class="" style="white-space:pre"> </span>var layerScale = 1;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (mappanel.map.getZoom() == 13){</div>
<div><span class="" style="white-space:pre"> </span>var layerScale = 2;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>if (mappanel.map.getZoom() == 14){</div>
<div><span class="" style="white-space:pre"> </span>var layerScale = 3;</div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>var param_index = "choix_"+layerToRedraw;</div>
<div><span class="" style="white-space:pre"> </span>var index = document.getElementById(param_index).selectedIndex;</div><div><span class="" style="white-space:pre"> </span>var coordonnee_zoom_02 = coordonnee_zoom[0][2];</div>
<div><span class="" style="white-space:pre"> </span>var coordonnee_zoom_12 = coordonnee_zoom[1][2];</div><div><span class="" style="white-space:pre"> </span>var coordonnee_zoom_22 = coordonnee_zoom[2][2];</div><div><span class="" style="white-space:pre"> </span>var coordonnee_zoom_32 = coordonnee_zoom[3][2];</div>
<div><span class="" style="white-space:pre"> </span>var vectorName = liste_layer[layerNumber][layerScale][index][0];</div><div><span class="" style="white-space:pre"> </span>var vectorUrl = liste_layer[layerNumber][layerScale][index][1];</div>
<div><span class="" style="white-space:pre"> </span>var styleName = liste_layer[layerNumber][layerScale][index][0];</div><div><span class="" style="white-space:pre"> </span>var styleRule = liste_layer[layerNumber][layerScale][index][2];</div>
<div><span class="" style="white-space:pre"> </span>vector = new OpenLayers.Layer.Vector(vectorName, {</div><div><span class="" style="white-space:pre"> </span>isBaseLayer: false,</div><div><span class="" style="white-space:pre"> </span>strategies:[new OpenLayers.Strategy.Fixed()],</div>
<div><span class="" style="white-space:pre"> </span>protocol: new OpenLayers.Protocol.HTTP({</div><div><span class="" style="white-space:pre"> </span>url: vectorUrl,</div><div><span class="" style="white-space:pre"> </span>format:new OpenLayers.Format.GML()</div>
<div><span class="" style="white-space:pre"> </span>}),</div><div><span class="" style="white-space:pre"> </span>styleMap: new OpenLayers.StyleMap({</div><div><span class="" style="white-space:pre"> </span>default: new OpenLayers.Style2({</div>
<div><span class="" style="white-space:pre"> </span>name: styleName,</div><div><span class="" style="white-space:pre"> </span>rules: styleRule</div><div><span class="" style="white-space:pre"> </span>})</div><div>
<span class="" style="white-space:pre"> </span>})</div><div><span class="" style="white-space:pre"> </span>});</div><div><span class="" style="white-space:pre"> </span>if (index == 0) {</div><div><span class="" style="white-space:pre"> </span>mappanel.map.removeLayer(vector);</div>
<div><span class="" style="white-space:pre"> </span>} else {</div><div><span class="" style="white-space:pre"> </span>mappanel.map.addLayer(vector)</div><div><span class="" style="white-space:pre"> </span>}</div><div>};</div>
<div><br></div><div style>liste_layer is a javascript list of list of list ... containing the values.</div><div style><br></div><div style>Thank you for you help.</div><div style><br></div><div style>Gaëtan</div></div></div>