Telogis.GeoBase.Canvas |
Canvas inherits from AbstractDOMEntity.
A utility for managing and rendering primitive shapes to a VML (Internet Explorer v8 or less) or SVG (Webkit) element. Shapes are managed as individual entities, as is the style of vector-graphics implementations like VML and SVG, for performance reasons. That is, to draw on a canvas once it has been created, methods to create these primitives should be called (e.g. Canvas.circle, Canvas.rect), but if further manipulation of them is desired (e.g. to clear the Canvas), references to the objects returned by these functions should be kept and have appropriate methods called.
// Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined });
Name | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Canvas(config, beforeAttach) | Arguments
|
Name | Description |
---|---|
circle (Point center, Number radius, Widgets.Map map) | Creates a circle on the Canvas as an ellipse with identical horizontal and vertical axis lengths. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle 200 pixels down and right of the upper-left corner of the canvas var myCircle = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 50, map); myCircle.draw(); // Or use a LatLon location var myCircle1 = myCanvas.circle(new Telogis.GeoBase.LatLon(33.563259,-117.788995), 50, map); myCircle1.draw();
Canvas.Shapes.Ellipse - The ellipse representing the circle on the canvas. |
destroy () | Frees resources used by the canvas, and calls Canvas.Shapes.AbstractShape.destroy on each of its registered shapes. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle 200 pixels down and right of the upper-left corner of the canvas var myCircle = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 50); myCircle.draw(); // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Destroy the canvas and its content (the circle) myCanvas.destroy(); }; |
ellipse (Point center, Number radiusX, Number radiusY, Widgets.Map map) | Creates an ellipse on the Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw an ellipse 200 pixels down and right of the upper-left corner of the canvas. // Ellipse dimensions are 100 pixels wide by 20 pixels high var myEllipse = myCanvas.ellipse(new Telogis.GeoBase.Point(200,200), 100, 20, map); myEllipse.draw(); // Or use a LatLon location var myEllipse2 = myCanvas.ellipse(new Telogis.GeoBase.LatLon(33.563259,-117.788995), 100, 20, map); myEllipse2.draw();
Canvas.Shapes.Ellipse - The ellipse representing the new shape. |
getCenterXY () | Finds the center of the canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getCenterXY()); // 320x240 Point - The xy co-ordinates of the center of the canvas. |
getFillColor () | Finds the components of the default fill color for primitives constructed on this Canvas, if applicable. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getFillColor().toCSSRGBA()); // rgba(0,18,255,0.5) Color - The RGB fill color, or null if filling is disabled. |
getHeight () | Finds the visible height of the canvas, excluding buffering. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getHeight()); // 480 Number - The visible height of the canvas area, in pixels. |
getLineColor () | Finds the components of the default stroke color for primitives constructed on this Canvas, if applicable. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getLineColor().toCSSRGBA()); // rgba(0,18,255,0.9) Color - The RGB stroke color, or null if stroking is disabled. |
getLineWidth () | Finds the default stroke width for primitives constructed on this Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 4, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getLineWidth()); // 4 Number - The stroke width, in pixels. |
getSize () | Finds the visible width and height of the canvas, excluding buffering. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 4, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getSize()); // 640x480 Size - The visible dimensions of the canvas area, in pixels. |
getWidth () | Finds the visible width of the canvas, excluding buffering. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 4, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); alert(myCanvas.getWidth()); // 640 Number - The visible width of the canvas area, in pixels. |
group (Array shapes) | Creates a Canvas.Group on this Canvas. Arguments
|
image (Point point, String src, Widgets.Map map) | Creates an image on the Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); var myPoint = new Telogis.GeoBase.Point(200,200); // A relative point var myLoc = new Telogis.GeoBase.LatLon(33.563259,-117.788995); // A fixed location // Draw an image by specifying a point or location at which to render the image // and a string path (absolute or relative to the page) to the image file var myImage = myCanvas.image(myPoint,'http://localhost/GeoStream/scripts/images/pin-red.png', map); myImage.draw();
Canvas.Shapes.image - The image that was created. |
label (Point point, String text, Widgets.Map map) | Creates a label on the Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a label by specifying a point at which to render the label (relative to the // top-left corner of the visible canvas) and a string containing plain text var myLabel = myCanvas.label(new Telogis.GeoBase.Point(200,200),'Text Label to Display',map); myLabel.draw();
Canvas.Shapes.label - The label representing the new shape. |
line (Point start, Point end) | Creates a line segment on the Canvas as a polyline of only two points. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 4, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw an a line between two points relative to the upper-left corner of the canvas var myLine = myCanvas.line(new Telogis.GeoBase.Point(100,100), new Telogis.GeoBase.Point(300,300)); myLine.draw();
Canvas.Shapes.PolyLine - The polyline representing the line segment on the canvas. |
path (Array commands) | creates an arbitrary figure on the Canvas. Arguments
|
polyline (Array points, Boolean closed, Widgets.Map map) | creates a polyline on the Canvas. JavaScript Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Create an array of points that will form the start, end and junctures // of the line var pt1 = new Telogis.GeoBase.Point(200,150); var pt2 = new Telogis.GeoBase.Point(300,250); var pt3 = new Telogis.GeoBase.Point(200,350); var pointArray = [pt1, pt2, pt3]; // Or create an array of LatLon locations that will form the // start, end and junctures of the line var ll1 = new Telogis.GeoBase.LatLon(33.570967,-117.793688); var ll2 = new Telogis.GeoBase.LatLon(33.571029,-117.779229); var ll3 = new Telogis.GeoBase.LatLon(33.563794,-117.785815); var locArray = [ll1,ll2, ll3]; // Draw the polyline, in this case connecting the first and last points // to form a polygon (true) var myPolyline = myCanvas.polyline(pointArray, true, map); myPolyline.draw();
Canvas.Shapes.PolyLine - The polyline representing the new shape. |
rect (Point p1, Point p2, Widgets.Map map) | Creates a rectangle on the Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a rectangle by specifying two points (the top-left and bottom-right corners) var myRectangle = myCanvas.rect(new Telogis.GeoBase.Point(200,200),new Telogis.GeoBase.Point(230,230),map); myRectangle.draw();
Canvas.Shapes.Ellipse - The ellipse representing the new shape. |
remove (Telogis.GeoBase.AbstractShape shape) | Removes a given Telogis.GeoBase.AbstractShape from this Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw four circles on the canvas var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle1.draw(); var circle2 = myCanvas.circle(new Telogis.GeoBase.Point(200,300), 30); circle2.draw(); var circle3 = myCanvas.circle(new Telogis.GeoBase.Point(300,200), 30); circle3.draw(); var circle4 = myCanvas.circle(new Telogis.GeoBase.Point(300,300), 30); circle4.draw(); // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Remove two of the four circles from the canvas myCanvas.remove(circle1); myCanvas.remove(circle4); };
|
setFillColor (Color color) | Specifies the default fill color for new primitives constructed on this Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle on the canvas using the current default fill color var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle1.draw(); // Specify a new default fill color myCanvas.setFillColor(new Telogis.GeoBase.Color(255,156,0,0.5)); // use 'null' for no fill color >> myCanvas.setFillColor(null); // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Draw a new circle, using the new fill color var circle2 = myCanvas.circle(new Telogis.GeoBase.Point(200,300), 30); circle2.draw(); };
|
setLineColor (Color color) | Specifies the default stroke color for new primitives constructed on this Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle on the canvas using the current default line color var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle1.draw(); // Specify a new default line color myCanvas.setLineColor(new Telogis.GeoBase.Color(255,0,0,0.9)); // use 'null' for no fill color >> myCanvas.setLineColor(null); // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Draw a new circle, using the new line color var circle2 = myCanvas.circle(new Telogis.GeoBase.Point(200,300), 30); circle2.draw(); };
|
setLineWidth (Number width) | Specifies the default stroke width for new primitives constructed on this Canvas. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle on the canvas using the current default line width (1) var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle1.draw(); // Specify a new default line width myCanvas.setLineWidth(5); // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Draw a new circle, using the new line width (5) var circle2 = myCanvas.circle(new Telogis.GeoBase.Point(200,300), 30); circle2.draw(); };
|
setOffset (Point point) | Sets the offset of the Canvas, from its parent. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Create an image 300 pixels in and down from the top left-hand corner of the visible canvas. var image1 = myCanvas.image(new Telogis.GeoBase.Point(300,300), 'http://localhost/GeoStream/scripts/images/pin-red.png'); image1.draw(); // Call a test function when the document is clicked document.onclick = myTestFunction; function myTestFunction() { // Set a new canvas offset that moves the canvas 100 pixels up and to the left // relative to its parent myCanvas.setOffset(new Telogis.GeoBase.Point(100,100)); // Call update() of the canvas. The image now reflects the updated canvas offset. // The icon moves up and to the left by 100 pixels, but its specified point // location (300,300) remains unchanged myCanvas.update(); };
|
setSize (Size size) | Changes the dimensions of the canvas and calls Canvas.update. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle on the canvas at 200x200 (from top-left corner) // This is well within the current canvas size of 640x480 var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle1.draw(); // What is the current canvas size? alert('Canvas size is '+myCanvas.getSize()+'. Now click the canvas.' ); // 'Canvas size is 640x480. Now click the canvas.' // Call a test function when the canvas is clicked document.onclick = myTestFunction; function myTestFunction() { // Specify a new canvas size of 200x200. This function will also // call update(), removing the circle1 object myCanvas.setSize(new Telogis.GeoBase.Size(200,200)); // What it the canvas size now? alert('Canvas size is now '+myCanvas.getSize()+'. Only one quarter of the circle is now visible.'); // 'Canvas size is 200x200. Only one quarter of the circle is now visible.' // Redraw a circle at the same point (200x200) as the previous circle. // This is centered on the bottom-right corner of the new canvas. Only // 1/4 (top-left) will be visible as 3/4 is now off the edge of the canvas. var circle2 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); circle2.draw(); };
|
update () | Updates each of the Canvas's primitive shapes to reflect any changes that have been made to their properties. This should be called manually after drawing changes. JavaScript // Create a Canvas instance on a parent DOM element (DIV 'main_map') var myCanvas = new Telogis.GeoBase.Canvas({ fillColor: new Telogis.GeoBase.Color(0,18,255,0.5), id: 'new_canvas', lineColor: new Telogis.GeoBase.Color(0,18,255,0.9), lineWidth: 1, parent: 'main_map', // DOM entity. In this example the DIV 'main_map' size: new Telogis.GeoBase.Size(640,480) // Not needed if already defined }); // Draw a circle on the canvas at 200x200 (from top-left corner) var circle1 = myCanvas.circle(new Telogis.GeoBase.Point(200,200), 30); // Draw the circle circle1.draw(); // Change the center of the circle to a new point. The circle remains unchanged. circle1.center = new Telogis.GeoBase.Point(300,300); // Call a test function when the document is clicked document.onclick = myTestFunction; function myTestFunction() { // Update the canvas to display the circle at its new position myCanvas.update(); }; |
Name | Type | Description |
---|---|---|
BEZIER_ARC_APPROX | Number | The control point magnitude that can be used to approximate an ellipse with cubic bezier curves when scaled by the appropriate radius. |
COMMAND_BEZIER | Number | The enumerated value representing an instruction to draw a bezier curve in a Canvas.Shapes.Path. |
COMMAND_LINE | Number | The enumerated value representing an instruction to draw a line segment in a Canvas.Shapes.Path. |
COMMAND_MOVE | Number | The enumerated value representing an instruction to move the stroke pen in a Canvas.Shapes.Path. |