[OpenLayers-Users] chenge style with zoom level

Luca Delucchi lucadeluge at gmail.com
Thu Oct 22 04:51:01 EDT 2009


Hi list, i'm newbye about this list. I'm trying to change the
pointRadius in my style when a change the zoom level, i read this [0]
but nothing change. i try a lot of  solution here:

###first solution like the mailing list

       var zumLevel;

	map.events.register('zoomend', map, function(e){
		zumLevel=map.getZoom()+5;
	});

	var CH_vend = new OpenLayers.Layer.WFS("Chardonnay indice vendemmia",
"http://10.0.101.11/cgi-bin/mapserv?map=/home/gis/mapserver/wfs_previsione_indici.map",
{typename: "CH_ind", maxfeatures: 1000}, {extractAttributes: true,
	styleMap: new OpenLayers.StyleMap({
		strokeColor: "#00FF00",
		strokeOpacity: 1,
		strokeWidth: 4,
		fillColor: "#FFFFFF",
		fillOpacity: 0.5,
		pointRadius: "${radius}",
		pointerEvents: "visiblePainted",
		label : "${vend_avg}",
		
		fontColor: "#000000",
		fontSize: "12px",
		fontFamily: "Courier New, monospace",
		fontWeight: "bold",
		labelAlign: "cm"
	}, {
		context: {
			radius: function(){
				return zumLevel;
			}
		}
	}
	)});

### second solution, the color change but the size not change

       var zumLevel, textLevel;

	var brix_context = {
		getScolor: function(feature) {
		if (feature.attributes.id_vitigno=="CH"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="MB"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="MG"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="IM"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="MT"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="NO"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="PB"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="PG"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="PV"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="TA"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="TR"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="VE"){
			scolor='#EEC900';
		} else if (feature.attributes.id_vitigno=="VT"){
			scolor='#EEC900';
		} else {
			scolor='#B23AEE';
		};
		return scolor;
		},
		brixavg: function(feature) {
			return feature.attributes.brix_avg;
		},
		radius: function(){
			map.events.register('zoomend', map, function(e){
				zumlevel=map.getZoom()+5;
				return zumLevel;
			});
		},
		testo: function(){
			map.events.register('zoomend', map, function(e){
				textlevel=map.getZoom();
				testolevel=textLevel.toString()+"px"
				return testolevel;
			});
		},
	};

	var brix_template = {
		fillColor:"#FFFFFF",
		fillOpacity: 0.5,
		strokeColor: "${getScolor}",
		strokeWidth: 4,
		strokeOpacity: 1,
		pointRadius: "${radius}",
		pointerEvents: "visiblePainted",
		label : "${brixavg}",
		
		fontColor: "#000000",
		fontSize: "${testo}",
		fontFamily: "Courier New, monospace",
		fontWeight: "bold",
		labelAlign: "cm"
	};

	var brix_style = new OpenLayers.Style(brix_template, {context:brix_context});

	var brix = new OpenLayers.Layer.WFS("Brix previsti a oggi",
"http://10.0.101.11/cgi-bin/mapserv?map=/home/gis/mapserver/wfs_previsione_indici.map",
{typename: "Indici_vendemmia", maxfeatures: 1000}, {extractAttributes:
true, visibility: false,	styleMap: new
OpenLayers.StyleMap(brix_style)});

someone can help me?

thanks
Luca

[0] http://www.mail-archive.com/users@openlayers.org/msg07140.html



More information about the Users mailing list