[OpenLayers-Users] Dynamic modify GeoJSON style without redownload of data?
Jay L.
jlaura at asu.edu
Wed Jan 30 12:47:09 PST 2013
List,
New user testing some backed processing. I am serving GeoJSON polygons
through GeoServer to my OpenLayer's client. I have a jQuery button that
calls a backend python script and returns data binning. What I am trying
to do is recolor my WFS on the client side without redownloading the data.
I have a style that is working on load, but when I attempt to set the
layer's new styleMap and refresh I get a blank map. Here is the relevant
code - any info appreciated!
Map:
map = new OpenLayers.Map('map', options);
layer0 = new OpenLayers.Layer.Vector("GML", {
isBaseLayer: true,
styleMap: new OpenLayers.StyleMap(style),
protocol: new OpenLayers.Protocol.HTTP({
url: "
http://osgeostack:8080/geoserver/fjtests/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=fjtests:counties
",
format: new OpenLayers.Format.GML()
}),
strategies: [new OpenLayers.Strategy.BBOX({ratio:3,
reFactor:2})]
jQuery Button:
$('#mp').click(function(){
var classes = $('#classes').val();
var attribute = $('#attr').val();
$.ajax({
url:"/cgi-bin/fj_mp.py",
type:"post",
data: {classes:classes, attribute:attribute},
success: function(response){
newMapStyle(classes, response.bins,attribute);
}
});
});
'Resymbolizer'
function newMapStyle(classes,bins,attribute){
var newstyle = new OpenLayers.Style();
var ruleArray = new Array()
var colorMap = [["#D8B365","#F5F5F5","#F5F5F5"],
["#A6611A","#DFC27D","#80CDC1","#018571"],
["#A6611A","#DFC27D","#F5F5F5","#80CDC1","#018571"],
["#8C510A","#D8B365","#F6E8C3","#C7EAE5","#5AB4AC","#01665E"],
["#8C510A","#D8B365","#F6E8C3","#F5F5F5","#C7EAE5","#5AB4AC","#01665E"],
["#8C510A","#BF812D","#DFC27D","#F6E8C3","#C7EAE5","#80CDC1","#35978F","#01665E"]]
var index = classes - 3;
for(var i=0;i<colorMap[index].length;i++){
(function(){
var rule = i
if(i==0){
rule = new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.BETWEEN,
property: attribute,
lowerBoundary: 0,
upperBoundary: bins[i]}),
symbolizer: {fillColor:colorMap[i],
strokeColor:"black",strokeWidth:0.25}});
}else if(i==colorMap[index].length-1){
var last = i - 1
rule = new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.BETWEEN,
property: attribute,
lowerBoundary: bins[last],
upperBoundary:9999}),
symbolizer: {fillColor:colorMap[i],
strokeColor:"black",strokeWidth:0.25}});
}else{
rule = new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.BETWEEN,
property: attribute,
lowerBoundary: bins[i-1],
upperBoundary: bins[i]}),
symbolizer: {fillColor:colorMap[i],
strokeColor:"black",strokeWidth:0.25}});
}
ruleArray[i] = rule
}());
}
newstyle.addRules(ruleArray)
layer0.styleMap = newstyle;
layer0.refresh({force:true});
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130130/81625255/attachment.html>
More information about the Users
mailing list