[Cartoweb-users] How to draw a circle
Oliver Christen
oliver.christen at camptocamp.com
Thu Feb 7 03:19:17 EST 2008
circle are not yet implemented in the current version or Cartoweb
but here is a patch that should enable it.
I did it myself because explaining you what to do would have taken me the
same amount of time.
I dont provide the tool icon though.
regards
Oliver
> Hi,
>
> I would like to know if it's possible to draw a circle (center and radius
> defined by the user) with the plugin "Outline" modified or with another
> solution?
>
> Thanks
>
> Patrick BERANGER
> Pôle Modernisation / Système d'Information Géographique
> DRE Rhône-Alpes / DDE Rhône
> Tél : 04 78 63 39 62
>
>
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>
-------------- next part --------------
Index: htdocs/js/dhtmlInit.js
===================================================================
RCS file: /var/lib/cvs/projects/cw3/cartoweb3/htdocs/js/dhtmlInit.js,v
retrieving revision 1.25
diff -u -r1.25 dhtmlInit.js
--- htdocs/js/dhtmlInit.js 20 Nov 2007 07:46:47 -0000 1.25
+++ htdocs/js/dhtmlInit.js 7 Feb 2008 08:02:02 -0000
@@ -428,6 +428,33 @@
};
};
/***** OUTLINE ****/
+Map.prototype.outline_circle = function(aDisplay) {
+ this.resetMapEventHandlers();
+ this.setCurrentLayer('outline_poly');
+ this.getDisplay(aDisplay).setTool('draw.circle');
+
+ this.onNewFeature = function(aFeature) {
+ this.onToolUnset();
+ };
+ this.onFeatureInput = this.onFeatureChange = function(aFeature) {
+ fillForm(aFeature);
+ if (typeof addLabel == 'undefined')
+ doSubmit();
+ else
+ addLabel(polyDefaultLabel, mouse_x, mouse_y);
+ };
+ this.onToolUnset = function() {
+ //clear the outline_poly's display layer
+ this.getDisplay(aDisplay).clearLayer('outline_poly');
+ this.onCancel();
+ };
+ this.onCancel = function() {
+ if (typeof hideLabel != 'undefined')
+ hideLabel();
+ emptyForm();
+ };
+};
+
Map.prototype.outline_poly = function(aDisplay) {
this.resetMapEventHandlers();
this.setCurrentLayer('outline_poly');
Index: plugins/outline/client/ClientOutline.php
===================================================================
RCS file: /var/lib/cvs/projects/cw3/cartoweb3/plugins/outline/client/ClientOutline.php,v
retrieving revision 1.59
diff -u -r1.59 ClientOutline.php
--- plugins/outline/client/ClientOutline.php 5 Nov 2007 10:08:44 -0000 1.59
+++ plugins/outline/client/ClientOutline.php 7 Feb 2008 08:03:36 -0000
@@ -121,6 +121,7 @@
const TOOL_LINE = 'outline_line';
const TOOL_RECTANGLE = 'outline_rectangle';
const TOOL_POLYGON = 'outline_poly';
+ const TOOL_CIRCLE = 'outline_circle';
/**
* Constructor
@@ -197,6 +198,7 @@
new ToolDescription(self::TOOL_LINE, true, 71),
new ToolDescription(self::TOOL_RECTANGLE, true, 72),
new ToolDescription(self::TOOL_POLYGON, true, 73),
+ new ToolDescription(self::TOOL_CIRCLE, true, 74),
);
}
@@ -211,9 +213,10 @@
public function filterGetRequest(FilterRequestModifier $request) {
// gets geometry type from GET request
$this->geomType = '';
- $poly = $request->getValue('outline_poly');
- $line = $request->getValue('outline_line');
- $point = $request->getValue('outline_point');
+ $poly = $request->getValue(self::TOOL_POLYGON);
+ $line = $request->getValue(self::TOOL_LINE);
+ $point = $request->getValue(self::TOOL_POINT);
+ $circle = $request->getValue(self::TOOL_CIRCLE);
// set correct parameters for new shape depending on type
if (!empty($poly)) {
@@ -228,6 +231,10 @@
$this->geomType = $tool = self::TOOL_POINT;
$selection_coords = $point;
$selection_type = 'point';
+ } elseif (!empty($point)) {
+ $this->geomType = $tool = self::TOOL_CIRCLE;
+ $selection_coords = $circle;
+ $selection_type = 'circle';
} else {
return;
}
@@ -318,6 +325,7 @@
case self::TOOL_RECTANGLE:
case self::TOOL_POLYGON:
+ case self::TOOL_CIRCLE:
$styledShape->shapeStyle = clone $this->outlineState->polygonStyle;
break;
@@ -577,6 +585,17 @@
protected function getShape($type, $values) {
switch ($type) {
+ case self::TOOL_CIRCLE :
+ $points = Utils::parseArray($values, ';');
+ if (sizeOf($points) != 2) return false;
+
+ $shape = new Circle;
+ $xy = Utils::parseArray($points[0], ',');
+ $shape->x = $xy[0];
+ $shape->y = $xy[1];
+ $shape->radius = $points[1];
+ return $shape;
+ break;
case self::TOOL_POLYGON :
$points = Utils::parseArray($values, ';');
if (sizeOf($points) <= 0) return false;
Index: plugins/outline/server/ServerOutline.php
===================================================================
RCS file: /var/lib/cvs/projects/cw3/cartoweb3/plugins/outline/server/ServerOutline.php,v
retrieving revision 1.55
diff -u -r1.55 ServerOutline.php
--- plugins/outline/server/ServerOutline.php 26 Oct 2007 12:56:19 -0000 1.55
+++ plugins/outline/server/ServerOutline.php 7 Feb 2008 08:02:48 -0000
@@ -71,6 +71,13 @@
$p->addXY($shape->maxx, $shape->miny);
$p->addXY($shape->minx, $shape->miny);
$p->addXY($shape->minx, $shape->maxy);
+ } else if ($className == 'Circle') {
+ $f = ms_newShapeObj(MS_SHAPE_POLYGON);
+ for ($i = 0; $i <= 360; $i = $i + 10) {
+ $x = $shape->x + (cos($i * (22 / 7) / 180) * $shape->radius);
+ $y = $shape->y - (sin($i * (22 / 7) / 180) * $shape->radius);
+ $p->addXY($x, $y);
+ }
} else {
if ($className == 'Line') {
$f = ms_newShapeObj(MS_SHAPE_LINE);
@@ -278,6 +285,7 @@
break;
case 'Rectangle':
case 'Polygon':
+ case 'Circle':
$this->drawPolygon($shape, $maskMode);
break;
default:
More information about the Cartoweb-users
mailing list