[OpenLayers-Users] changing style of layer using radiobutton

vrbikdan vrbikdan at gmail.com
Sat Feb 25 13:19:06 EST 2012


Hi,
I'm trying to create map, where user could change style of polygon layer via
radiobutton. I wrote some rules for this and function, which should change
property and value in these rules. But it doesn't cause rules are in init
function and my function is onclick on radiobutton. So how I can allow user
to change style of layer via radiobutton? Part of my code is below, whole
code is here: http://vrbikdan.xf.cz/avon/avon.html
http://vrbikdan.xf.cz/avon/avon.html 

Thanks a lot,
Dan

zonyPrijem = new Array(10500, 11500, 12500, 17000);
zonyPopulace = new Array(200000, 250000, 300000, 350000);
zonyLady = new Array(1400, 1800, 2200, 2400);

polozkazonyPrijem = "prijem";
polozkazonyPopulace = "populace";
polozkazonyLady = "avonlady";
			
hranice = zonyPrijem;
polozka = polozkazonyPrijem;

function tematika (){
	if(document.forms.seznamVrstev.zonyAvon[0].checked)
	{
	hranice = zonyPrijem;
	polozka = polozkazonyPrijem;
	avonZony_layer.redraw();
	}
	else if(document.forms.seznamVrstev.zonyAvon[1].checked)
	{
	hranice = zonyPopulace;
	polozka = polozkazonyPopulace;
	avonZony_layer.redraw();
	}
	else if(document.forms.seznamVrstev.zonyAvon[2].checked)
	{
	hranice = zonyLady;
	polozka = polozkazonyLady;
	avonZony_layer.redraw();
	}
}

function init(){
            map = new OpenLayers.Map('mapa',{
				
                    controls: [
						new OpenLayers.Control.Navigation(),
						new OpenLayers.Control.PanPanel(),
						new OpenLayers.Control.ZoomPanel(),
                        new OpenLayers.Control.ScaleLine(),
                        new OpenLayers.Control.KeyboardDefaults()
                    ]});

                        style = new OpenLayers.Style();

			rule1 = new OpenLayers.Rule({
				filter: new OpenLayers.Filter.Comparison({
				type: OpenLayers.Filter.Comparison.LESS_THAN,
				property: polozka,
				value: hranice[0]
				}),
				symbolizer: {fillColor: "#ccFF00",
				fillOpacity: pruhlednost, strokeColor: "black"}
				});
			
			rule2 = new OpenLayers.Rule({
				filter: new OpenLayers.Filter.Comparison({
				type: OpenLayers.Filter.Comparison.BETWEEN,
				property: polozka,
				lowerBoundary: hranice[0]+=1,
                upperBoundary: hranice[1]
				}),
				symbolizer: {fillColor: "#CCCC00",
				fillOpacity: pruhlednost, strokeColor: "black"}
				});
			
			rule3 = new OpenLayers.Rule({
				filter: new OpenLayers.Filter.Comparison({
				type: OpenLayers.Filter.Comparison.BETWEEN,
				property: polozka,
				lowerBoundary: hranice[1]+=1,
                upperBoundary: hranice[2]
				}),
				symbolizer: {fillColor: "#CC9900",
				fillOpacity: pruhlednost, strokeColor: "black"}
				});
			
			rule4 = new OpenLayers.Rule({
				filter: new OpenLayers.Filter.Comparison({
				type: OpenLayers.Filter.Comparison.BETWEEN,
				property: polozka,
				lowerBoundary: hranice[2]+=1,
                upperBoundary: hranice[3]
				}),
				symbolizer: {fillColor: "#CC6600",
				fillOpacity: pruhlednost, strokeColor: "black"}
				});
			
			rule5 = new OpenLayers.Rule({
				filter: new OpenLayers.Filter.Comparison({
				type: OpenLayers.Filter.Comparison.GREATER_THAN,
				property: polozka,
				value: hranice[3]
				}),
				symbolizer: {fillColor: "#CC3300",
				fillOpacity: pruhlednost, strokeColor: "black"}
				});

				style.addRules([rule1, rule2, rule3, rule4, rule5]);

styleAvon = new OpenLayers.StyleMap({'default': style, 'select':
selectStyle});

			avonZony_layer = new OpenLayers.Layer.Vector("KML", {
									protocol: new
OpenLayers.Protocol.HTTP({url:"avonVrstvy/avon_zony.kml", 
																			format: new OpenLayers.Format.KML()}), 
									strategies: [new OpenLayers.Strategy.Fixed()],
									styleMap: styleAvon
									});
}

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/changing-style-of-layer-using-radiobutton-tp4507241p4507241.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list