[OpenLayers-Users] RegularPolygon as a search polygon
tino.desjardins at arcor.de
tino.desjardins at arcor.de
Mon Jul 12 09:07:14 EDT 2010
Hello Brad,
I think the problem is your own separate EventHandler and the wrong handler "draw". The DrawFeature-Control has an eventhandler "featureAdded". Take this instead.
e.g.
OpenLayers.Control.NoticeControl = OpenLayers.Class(OpenLayers.Control.DrawFeature,
{
initialize: function(layer, handler, options) {
OpenLayers.Control.DrawFeature.prototype.initialize.apply(this, [layer, handler, options]);
},
setMap: function(map) {
this.handler.setMap(map);
OpenLayers.Control.prototype.setMap.apply(this, arguments);
},
featureAdded: function(feature) {
alert(feature.geometry.toString());
this.deleteFeature(feature);
},
deleteFeature: function(feature) {
feature.state = OpenLayers.State.DELETE;
this.layer.events.triggerEvent("afterfeaturemodified",
{feature: feature});
this.layer.drawFeature(feature);
},
CLASS_NAME: "OpenLayers.Control.NoticeControl"
});
how to use:
var polyOptions = {sides: 4};
var noticeControl = new OpenLayers.Control.NoticeControl(polygonLayer, OpenLayers.Handler.RegularPolygon,
{handlerOptions: polyOptions});
map.addControl(noticeControl);
hope that works
Tino
----- Original Nachricht ----
Von: Brad Spencer <bradspencer at ozemail.com.au>
An: brad at numaps.com.au, users at openlayers.org
Datum: 11.07.2010 15:23
Betreff: Re: [OpenLayers-Users] RegularPolygon as a search polygon
> Guys,
>
>
>
> Still need some help on this.
>
>
>
> I have taken the simple app from examples and edited it to see if I can
> make
> this work. It works but not the way I expect it to work?
>
>
>
> See : http://staging.demos.numaps.com.au/shape_tester.html
>
>
>
> I have extended the DrawFeature control to echo out the coordinates of the
> vector generated polygon. When the control is deactivated (controlled by
> the
> 'navigate' radio) the notice function is triggered - not sure why?
>
> I am trying to trigger this function only when the control is activated.
>
>
>
> Its just not doing what I would have expected so I must be doing something
> really stupid.
>
>
>
> Can someone have a quick look at this for me?
>
>
>
> Cheers.
>
>
>
> Brad..
>
>
>
> From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
> Behalf Of Brad Spencer
> Sent: Friday, July 09, 2010 9:12 PM
> To: openlayers users
> Subject: [OpenLayers-Users] RegularPolygon as a search polygon
>
>
>
> Guys,
>
>
>
> I have been able to build a control to freehand digitize a polygon and then
> launch a function to use the polygon as a search polygon in a WFS request.
>
>
>
> This works for me:
>
>
>
> drawControls = new OpenLayers.Control.DrawFeature(vectorLayer,
> OpenLayers.Handler.Polygon) ;
>
> // extend the drawcontrol with its behavior
>
> OpenLayers.Util.extend(drawControls,
>
> { draw: function (){
>
> this.polygon = new OpenLayers.Handler.Polygon(drawControls,{"done":
> this.notice}); this.polygon.activate();},
>
> notice: function (polygon)
>
> {
>
> // get vertices of polygon
> into and array of coordinate pairs
>
> var polyString =
> polygon.toString() ;
>
>
>
> // do whatever with polygon
> linestring here
>
> .
>
> }
>
> });
>
> map.addControl(drawControls);
>
>
>
>
>
> I wanted to use the RegularPolygon feature to do the same but it does not
> launch the function in the same way after the vector geometry is
> successfully created.
>
>
>
> var polyType = 6;
>
> var rad = '';
>
> polyOptions = {sides: polyType, radius: rad, angle: 0}
>
> shapeControl = new OpenLayers.Control.DrawFeature(vectorLayer,
> OpenLayers.Handler.RegularPolygon, {handlerOptions: polyOptions});
>
> // extend the shapeControl with its behavior
>
> OpenLayers.Util.extend(shapeControl,
>
> { draw: function (){
>
> this.polygon = new
> OpenLayers.Handler.RegularPolygon(shapeControl, {"done": this.notice});
> this.polygon.activate();},
>
> notice: function (polygon)
>
> {
>
> // get vertices of polygon
> into and array of coordinate pairs
>
> var polyString =
> polygon.toString() ;
>
> // do whatever with polygon
> linestring here
>
> .
>
>
> }
>
> });
>
>
>
> In both cases the polygon is created and drawn to the vectorLayer.
>
>
>
> Can anyone see anything obviously wrong with the second piece of code?
>
>
>
> Cheers,
>
>
>
> Brad Spencer
>
> General Manager
>
> NuMaps
>
> "DemographicDrapes"
>
> www.numaps.com.au
>
> brad at numaps.com.au
>
> 0404 841 131
>
> (02)9481 7024
>
>
>
> "DemographicDrapes
> <http://www.numaps.com.au/numaps/index.cfm/resources/resources/apps4nsw-comp
>
> etition-winner/> wins NSW award"
>
>
>
>
>
> --------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Hotelbewertung: Bloß nicht die Katze im Sack kaufen bzw. den Floh auf der Matratze buchen -
ob geschäftlich oder privat - erst das Hotel im Reise-Channel auf arcor.de checken!
http://www.arcor.de/rd/footer.hotel
More information about the Users
mailing list