[OpenLayers-Users] Is there a better way to use a StyleMap than
this?
David Martin
David at itbeyond.com.au
Tue Jul 7 05:13:11 EDT 2009
Hi all,
I am working on a new mapping interface using OL2.8 and have spent hours
on StyleMaps. I am not sure if I am doing things right so thought I
would ask the group. My StyleMap code is as follows:
var styleMap = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({ pointRadius: "${scaledSize}",
graphicYOffset: "-${scaledDSize}",
strokeColor: "${colorStroke}", strokeWidth:
"${scaledStroke}", strokeDashstyle: "solid", strokeOpacity: .75,
graphicZIndex: 11,
externalGraphic:
'//www.exploroz.com/Utilities/Scripts/Openlayers/img/marker-blue.png',
label: "${getTitle}",
labelAlign: "lb", fontColor: '#808080', fontSize:
'${scaledSize}px', fontFamily: 'arial',
fillColor: "#a0a0a0", fillOpacity: '${opacityFill}'
}, { context: {
getTitle: function(feature) { if
(feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point" &&
thisMap.Map.getZoom() > 4) return ' ' +
feature.attributes.title + ' '; else return ''; },
colorStroke: function(feature) { if
(feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") return
'#a0a0a0'; else return '#4F53FF'; },
opacityFill: function(feature) { if
(feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") return
'0.4'; else return '1'; },
scaledSize: function(feature) { val =
feature.layer.map.getZoom() * 1.5; val > 4 ? null : val = 4; return val;
},
scaledDSize: function(feature) { val =
feature.layer.map.getZoom() * 3; val > 8 ? null : val = 8; return val;
},
scaledStroke: function(feature) { val = feature.layer.map.getZoom(); val
< 2 ? val = 2 : val < 4 ? null
: val = 4; return val; }
}
}),
"select": new OpenLayers.Style({ strokeColor: "${colorStroke}",
fillColor: "#ee9900", externalGraphic:
'//www.exploroz.com/Utilities/Scripts/Openlayers/img/marker-green.png',
fontWeight: 'bold', fontColor: 'black'
}, { context: {
colorStroke: function(feature) { if (feature.geometry.CLASS_NAME
== "OpenLayers.Geometry.Polygon") return
'#ee9900'; else return '#90EE90'; }
}
})
});
Is there a better way to handle the scaling of objects and specifying
how to handle each type of feature than the above. It works fine but I
thought I would ask to see if there is a more correct way to accomplish
this task as I am wanting to now add a number of different point
graphics and this would involve some additional feature context
functions.
Thanks in advance.
David Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090707/7c72604c/attachment.html
More information about the Users
mailing list