[OpenLayers-Users] Help with color-vector problem ?
koveras vehcna
silver_fox2006 at hotmail.com
Wed Jul 28 06:04:48 EDT 2010
Hello everyone, I am currently working on creating a map for personal use. In
my code, I can draw regular-irregular polygons -including defining the sides
of the polygons- , lines, points. Also I can navigate the map and modify the
drawings I have drawn -resize, reshape, drag and rotate-. I also wanted to
add the color feature so that I can draw different colored features. I have
implemented the code as following but there are two quite big problems:
Whenever I draw with selected color, all polygons turn into the color of the
last drawn vector's color -in case of refreshing the layer or zooming- and
also I can't modify the vectors in this case -rotate,resize etc.- And as if
this isn't enough, the code doesn't call the color change function in the
context of style but the function I wrote just under the text/javascript
part. And deleteing either one of these causes the coloring feature to be
inactivated. I have been fumbling with this for the past 2 days and it has
become quite frustrating since there are no examples or even tiny bit of
info about coloring vectors. Does anyone have any ideas ? The codes for
color, styling and vector are below:
var selectedColor;
function color(value){
if(value == "purple")
{
selectedColor = "purple";
}
else if(value == "blue")
{
selectedColor = "blue";
}
else if(value == "yellow")
{
selectedColor = "yellow";
}
else if(value == "red")
{
selectedColor = "red";
}
else if(value == "orange")
{
selectedColor = "orange";
}
else if(value == "green")
{
selectedColor ="green";
}
return selectedColor;
}
--------------------------------------------
styling part:
var value;
var myStyleMap = new OpenLayers.StyleMap(
new OpenLayers.Style({
fillColor: '${color}',
strokeColor: '${color}', strokeOpacity: 0.5,
fillOpacity: 0.5},
//call attribute of style in order to modify
{
context: {
color: function(feature) {
if(value == "purple")
{
selectedColor = "purple";
}
else if(value == "blue")
{
selectedColor = "blue";
}
else if(value == "yellow")
{
selectedColor = "yellow";
}
else if(value == "red")
{
selectedColor = "red";
}
else if(value == "orange")
{
selectedColor = "orange";
}
else if(value == "green")
{
selectedColor ="green";
}
return selectedColor;
}
}
}));
and the html part that shows options to change colors:
<select id="colors" onchange="color(this.value)">
<option value="purple">purple</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
<option value="red">red</option>
<option value="orange">orange</option>
<option value="green">green</option>
</select>
P.s: if the code is not detailed enough, I can e-mail the actual version.
Thanks and cheers
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Help-with-color-vector-problem-tp5345442p5345442.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list