[OpenLayers-Users] Customising Toolbar

Benoit PESTY tchule at hotmail.com
Wed Apr 25 12:53:38 EDT 2007


My problem is that the OpenLayers.Control.SelectFeature is meant to be used 
with a vector layer.

I want to be able to click anywhere on the map and to launch a WFS request 
directly.

The onSelect and onUnselect callbacks are not launched if my cursor is not 
on a feature.
I'd like to call my function on a onClick event and to be able to toggle 
on/off this kind of event with the toolbar.

Thanks,

Tchule.


>From: "Cicconetti, Bob" <BCicconetti at dnr.state.md.us>
>To: "Benoit PESTY" <tchule at hotmail.com>,<users at openlayers.org>
>Subject: RE: [OpenLayers-Users] Customising Toolbar
>Date: Wed, 25 Apr 2007 12:42:23 -0400
>
>
>If you look at the code snippet I sent, there were references to three
>functions, using the onSelect and onUnselect callbacks.
>
>So, when the toolbar icon is selected, the
>OpenLayers.Control.SelectFeature associated with that icon is activated.
>Clicking on a feature then selects the feature, and calls the
>appropriate callback. So for the information button, it calculates
>area/length and puts that on the screen somewhere when a feature is
>clicked on. If the delete button is active, it deletes that feature.
>
>Note that you have to unselect the feature before deleting it, or Bad
>Things (TM) happen. Actually, I think it's a bug; I'll add it to the
>tracker later.
>
>R C
>
>
>// Calculate area or length of features; convert units.
>   function feature_info(feature) {
>    //Extend to allow string length as well.
>       if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon")
>	{
>
>	var str = feature.geometry.getArea();
>	// Assume units are meters, for now.
>	// Magic numbers are evil, but ah well.
>	var sqft = str / 0.09290304;
>	var acres = str / 4046.856422;
>
>	// FIXME: Round and truncate. 8 sig figs?
>	if (sqft < 4000)
>	 str = "Area: (sq ft.) " + sqft;
>	else
>	 str = "Area: (acres) " + acres;
>
>	document.getElementById('area').innerHTML = str;
>
>	}
>       else if (feature.geometry.CLASS_NAME ==
>"OpenLayers.Geometry.LineString")
>         {
>         var str = feature.geometry.getLength();
>	var feet = str / 0.3048;
>	var miles = str / 1609.344;
>
>	if (feet < 2000)
>	 str = "Length: (feet) " + feet;
>	else
>	 str = "Length: (miles) " + miles;
>
>	document.getElementById('area').innerHTML = str;
>         }
>
>   }
>
>   function clear_feature_info(geometry) {
>	document.getElementById('area').innerHTML = "Select Feature for
>Area or Length.";
>   }
>
>   function deleteFeature(geometry) {
>	this.unselect(geometry);
>//  	this.layer.removeFeatures(geometry.feature);
>   	this.layer.removeFeatures(geometry);
>   }
>
> > -----Original Message-----
> > From: Benoit PESTY [mailto:tchule at hotmail.com]
> > Sent: Wednesday, April 25, 2007 12:30 PM
> > To: Cicconetti, Bob; users at openlayers.org
> > Subject: RE: [OpenLayers-Users] Customising Toolbar
> >
> > Cannot help on this one, don't know ArcView ^^
> >
> > Another question about the toolbar :
> >
> > I've managed to add the Delete and Select tools on the vector layer.
> >
> > I have a function that give me info on a base layer (similar to the
>CIA
> > Factbook example) that is activated with the following line :
> >
> > map.events.register('click', map, feature_info);
> >
> > But this activation is permanent , what i'd like to do is to link this
> > function to my toolbar. Should I create a new Control object or is
>there a
> > way to bind my function to an existing Control (Navigation,
>MouseDefaults,
> > ...) ?
> >
> > Thanks a lot,
>

_________________________________________________________________
Exercise your brain! Try Flexicon. 
http://games.msn.com/en/flexicon/default.htm?icid=flexicon_hmemailtaglineapril07




More information about the Users mailing list