[OpenLayers-Users] Create Circle

Kenny France kenny at xarex.com
Fri Sep 12 05:43:40 EDT 2008


Hi All,
 
I have the following code that creates a circle using googlemaps,
 
GEvent.addListener(map, 'click', mapClick);
 
function mapClick(marker, point) {
 var zoom = map.getZoom();
 
 if (!centerMarker) {
  centerMarker = createMarker(point)
  map.addOverlay(centerMarker);
  lat = point.y.toFixed(6);
     lng = point.x.toFixed(6);
 }
 else if (!radiusMarker){
  if (rLine) map.removeOverlay(rLine);
  radiusMarker = point;
  drawCircle();
  var radOnEarth =
(centerMarker.getPoint().distanceFrom(radiusMarker)/1000).toFixed(3);
  ajax_loadContent('add_marker','add_circle.php?latbox=' + lat + '&lonbox='
+ lng +'&radius='+ radOnEarth);
 }
}
 
function drawCircle(){
 var zoom = map.getZoom();
    var centerPt = normalProj.fromLatLngToPixel(centerMarker.getPoint(),
zoom);
 var radiusPt = normalProj.fromLatLngToPixel(radiusMarker, zoom);
    var circlePoints = Array();
    with (Math) {
  var radius = floor(sqrt(pow((centerPt.x-radiusPt.x),2) +
pow((centerPt.y-radiusPt.y),2)));
 
  for (var a = 0 ; a < 361 ; a+=10 ) {
   var aRad = a*(PI/180);
   y = centerPt.y + radius * sin(aRad)
   x = centerPt.x + radius * cos(aRad)
   var p = new GPoint(x,y);
   circlePoints.push(normalProj.fromPixelToLatLng(p, zoom));
  }
 if (circleLine) map.removeOverlay(circleLine);
  circleLine = new GPolyline(circlePoints,'#FF0000',2,1);
  map.addOverlay(circleLine);
  }
}
 
function createMarker(point) {
 var marker = new GMarker(point);
 return marker;
}
 
now i am rewriting my app with openlayers and have a small problem
 
has anyone done something similar to this ?
 
basically i click on the map to add a center point then the seconf click is
the size of the circle, this then calls a form so i can give this circle a
name
 
simple
 
K-
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080912/0c659657/attachment.html


More information about the Users mailing list