[OpenLayers-Users] how to update bounds in a vector feature
after modifications ?
JS Ubei
jsubei at yahoo.fr
Fri Nov 18 06:13:13 EST 2011
Hi Andreas,
I've try the second possibility :
boxFeature.geometry.components[0].components[0].x = longMin;
boxFeature.geometry.components[0].components[0].y = latMin;
boxFeature.geometry.components[0].components[0].clearBounds();
And this perfectly working !!!
Thanks a lot Andreas !
Best regards
----- Mail original -----
De : Andreas Hocevar <ahocevar at opengeo.org>
À : JS Ubei <jsubei at yahoo.fr>
Cc : "users at openlayers.org" <users at openlayers.org>
Envoyé le : Vendredi 18 Novembre 2011 11h55
Objet : Re: [OpenLayers-Users] how to update bounds in a vector feature after modifications ?
See answers inline.
On Nov 18, 2011, at 10:55 , JS Ubei wrote:
> Hi dear list,
>
> I have a vector feature "boxFeature" like :
>
> ########
> var pointList = [
> new OpenLayers.Geometry.Point(-180, -90),
> new OpenLayers.Geometry.Point(180, -90),
> new OpenLayers.Geometry.Point(180, 90),
> new OpenLayers.Geometry.Point(-180, 90),
> new OpenLayers.Geometry.Point(-180, -90)
> ];
> var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
> boxFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([linearRing]));
> ########
>
>
> After object creation, if I ask feature bounds I have :
>
> -180,-90,180,90
>
>
> Ok.
>
> After I modify my feature like :
>
> ########
>
> boxFeature.geometry.components[0].components[0].x = 0;
> boxFeature.geometry.components[0].components[0].y = 0;
You have to use the API to modify coordinates. Instead of the above two lines, just do:
boxFeature.geometry.components[0].components[0].move(180, 90);
Or if you want to set the coordinates directly, you have to call clearBounds() on the geometry you changed, i.e.
boxFeature.geometry.components[0].components[0].x = 0;
boxFeature.geometry.components[0].components[0].y = 0;
boxFeature.geometry.components[0].components[0].clearBounds();
> [etc.]
>
> myLayer.drawFeature(boxFeature);
>
> ########
>
>
> And when I ask for feature bounds I have the old values :
> -180,-90,180,90
Now you will still have the same bounds, because these are still the bounds of the polygon.
"POLYGON((0 0,180 -90,180 90,-180 90,0 0))"
But if you now do
boxFeature.geometry.components[0].components[1].move(-180,90);
your polygon will be
"POLYGON((0 0,0 0,180 90,-180 90,0 0))"
and the bounds will be
-180,0,180,90
Andreas.
>
>
> I've try to use some functions like :
>
> #######
> boxFeature.geometry.clearBounds();
> boxFeature.geometry.bounds = new OpenLayers.Bounds(0, 0, 180, 90);
> boxFeature.geometry.calculateBounds();
> #######
>
> But unfortunatly I always get the old bounds -180,-90,180,90
> ...
>
> Someone can help me ?
>
> Thanks and best regards,
>
> Nono
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list