[OpenLayers-Users] How to draw a BoundingBox Vector feature?

Christopher Schmidt crschmidt at metacarta.com
Mon Nov 17 14:39:00 EST 2008


On Mon, Nov 17, 2008 at 02:23:11PM -0500, Heidt, Christopher M. wrote:
> Thank you. That helped tremendiously.
> 
> You wouldn't happen to know how I would go about changing the style of
> the Box would you?

The Box style is controlled by CSS -- specifically, the boxDivClassName
property of the Handler.Box controls what CSS class name to use. By
default, this is olHandlerBoxZoomBox , which you can find in
theme/default/style.css -- you can create your own similar CSS style and
pass boxDivClassName as an option to your handler to change the look.

> 
> -----Original Message-----
> From: Christopher Schmidt [mailto:crschmidt at metacarta.com] 
> Sent: Monday, November 17, 2008 11:44 AM
> To: Heidt, Christopher M.
> Cc: OpenLayers
> Subject: Re: [OpenLayers-Users] How to draw a BoundingBox Vector
> feature?
> 
> On Mon, Nov 17, 2008 at 11:37:49AM -0500, Heidt, Christopher M. wrote:
> > I need a way to allow the user to draw a bounding box on the map but 
> > there doesnt seem to be a builtin way of doing this.
> > polygon and regularPolygon are no good because you cant force them to 
> > be straight.
> >  
> > I'm attempting to use the Box Handler to allow the user to draw a 
> > bounding box on the map. (code below) The problem im having is that 
> > the feature that ends up being created is suppose to be a polygon with
> 
> > the same bounds produced by the box, but what i end up with is an 
> > extreamly tiny polygon at 0,0.
> > I'm using a google base so i thought maybe the projection was the 
> > culprit, but i've tried transforming the bounds and nothing good seems
> 
> > to come from it.
> > Any ideas? 
> 
> Handler.Box returns a Bounds which is in *pixel* space -- you have to
> convert the corners with getLonLatFromPixel:
> http://openlayers.org/dev/examples/custom-control.html demonstrates how.
> 
> > var control = new OpenLayers.Control({
> >     draw: function () {
> >         this.box = new OpenLayers.Handler.Box( control,
> >             {done: this.notice},
> >             {keyMask: OpenLayers.Handler.MOD_SHIFT});
> >         this.box.activate();
> >     },
> >     notice: function (bounds){
> >         var geom = bounds.toGeometry();
> >         var feature = new OpenLayers.Feature.Vector(geom);
> >         _bboxLayer.addFeatures(feature);
> >         _map.zoomToExtent(bounds,true);
> >     }
> > });
> 
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> 
> 
> --
> Christopher Schmidt
> MetaCarta

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list