Hi all,<br><br>First, thanks Paul and Jan for your very helpful emails. I've decided to try to go with Paul's method first, and if I understand correctly this should be it: However I get a parse error on the third line (default: OpenLayers...). I'm not sure what's going on here. Any suggestions?<br>
<br>var styleMap = new OpenLayers.StyleMap(<br> {<br> default: OpenLayers.Util.applyDefaults(<br> {<br> label: '${Name}', <br> strokeWidth:1,<br>
strokeColor:"#CCCCCC",<br> fillColor: "green"<br> })<br> }<br> );<br> <br> var cities = new OpenLayers.Layer.GML ("7th Century Cities", "data/cities.gml",<br>
{<br> styleMap: styleMap,<br> projection: new OpenLayers.Projection("EPSG:4326"),<br> format: OpenLayers.Format.GML<br> }<br> );<br>
map.addLayer(cities);<br><br><div class="gmail_quote">On Tue, Sep 29, 2009 at 3:57 PM, Paul Spencer <span dir="ltr"><<a href="mailto:pagameba@gmail.com">pagameba@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
A simpler styleMap would be to take the Name directly from the feature's attributes, but using a context to provide functions that calculate per-feature styles is very powerful<div class="im"><br>
<br>
var styleMap = new OpenLayers.StyleMap({<br>
default: OpenLayers.Util.applyDefaults({<br></div>
label: '${Name}', // this comes from <a href="http://feature.attributes.Name" target="_blank">feature.attributes.Name</a> and is case sensitive<div class="im"><br>
strokeWidth:1,<br>
strokeColor:"#CCCCCC",<br>
fillColor: "green"<br></div>
})<br>
});<br>
<br>
Cheers<br><font color="#888888">
<br>
Paul</font><div><div></div><div class="h5"><br>
<br>
On 2009-09-29, at 5:28 AM, Jan H. van der Ven wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dear Nicholas,<br>
<br>
<br>
I use a StyleMap like so:<br>
<br>
var styleMap = new OpenLayers.StyleMap(<br>
{<br>
"default":OpenLayers.Util.applyDefaults(<br>
{<br>
fillColor: stateColors[layerIndex],<br>
fillOpacity: 0.4,<br>
strokeColor: stateColors[layerIndex],<br>
strokeWidth: 2,<br>
label : "${getName}", // see context below<br>
labelAlign: "cm",<br>
fontColor: "yellow",<br>
fontSize: "12px",<br>
fontFamily: "Verdana",<br>
fontWeight: "bold"<br>
}<br>
,OpenLayers.Feature.Vector.style["default"])<br>
<br>
,"select":OpenLayers.Util.applyDefaults({},OpenLayers.Feature.Vector.style["select"])<br>
});<br>
// the labelFunction prevents the modify handles being labeled with<br>
"undefined"<br>
styleMap.styles["default"].context={getName: labelFunction};<br>
<br>
This StyleMap is then added as a parameter to the layer:<br>
var laag = new OpenLayers.Layer.GML(<br>
layerName,<br>
url,<br>
{<br>
format:OpenLayers.Format.GeoJSON,<br>
visibility:false,<br>
styleMap:styleMap,<br>
isBaseLayer:false,<br>
});<br>
<br>
And the labelFunction is used to show the label only at a certain zoom<br>
level:<br>
<br>
function labelFunction(feature){<br>
if (map.getZoom()>4){<br>
if (<a href="http://feature.attributes.name" target="_blank">feature.attributes.name</a> != undefined){<br>
return <a href="http://feature.attributes.name" target="_blank">feature.attributes.name</a>;<br>
}else{<br>
return '';<br>
}<br>
}else{<br>
return '';<br>
}<br>
}<br>
<br>
The part about undefined has to do with edit handles.<br>
<br>
Kind regards,<br>
<br>
<br>
Jan<br>
<br>
Nicholas Efremov-Kendall wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
Sorry to bug you all with a pretty simple question. I have a shp file<br>
converted to GML, with an attribute called "name." I'd like for this<br>
to be places as a label by the polygon feature. I think, based on my<br>
digging around on the lists that I need a function to first get the<br>
<a href="http://feature.attributes.Name" target="_blank">feature.attributes.Name</a> <<a href="http://feature.attributes.Name" target="_blank">http://feature.attributes.Name</a>>, which would<br>
then pass it to the label. Does anyone have a good example of this, or<br>
suggestions on implementation?<br>
<br>
var cities = new OpenLayers.Layer.GML ("7th Century Cities",<br>
"data/cities.gml",<br>
{<br>
style: {strokeWidth:1, strokeColor:"#CCCCCC", fillColor: "green"},<br>
projection: new OpenLayers.Projection("EPSG:4326"),<br>
format: OpenLayers.Format.GML,<br>
<br>
label: "$name",<br>
<br>
<br>
}<br>
);<br>
map.addLayer(cities);<br>
<br>
<br>
-- <br>
Nicholas Efremov-Kendall<br>
Fulbright Student 2009-2010, Ukraine<br>
<a href="mailto:nefremov@artsci.wustl.edu" target="_blank">nefremov@artsci.wustl.edu</a> <mailto:<a href="mailto:nefremov@artsci.wustl.edu" target="_blank">nefremov@artsci.wustl.edu</a>><br>
c/o Halyna Yerko<br>
Balzaka 92a, Kv 27<br>
02232<br>
Kyiv, Ukraine<br>
(mob) +380963576524<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@openlayers.org" target="_blank">Users@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
<br>
------------------------------------------------------------------------<br>
<br>
<br>
No virus found in this incoming message.<br>
Checked by AVG - <a href="http://www.avg.com" target="_blank">www.avg.com</a><br>
Version: 8.5.409 / Virus Database: 270.13.114/2401 - Release Date: 09/28/09 17:53:00<br>
<br>
<br>
</blockquote>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@openlayers.org" target="_blank">Users@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Nicholas Efremov-Kendall<br>Fulbright Student 2009-2010, Ukraine<br><a href="mailto:nefremov@artsci.wustl.edu">nefremov@artsci.wustl.edu</a><br>c/o Halyna Yerko<br>
Balzaka 92a, Kv 27<br>02232<br>Kyiv, Ukraine<br>(mob) +380963576524<br>