OpenLayers OpenLayers

Ticket #1512 (closed feature: fixed)

Opened 2 years ago

Last modified 2 years ago

Canvas Renderer

Reported by: crschmidt Assigned to: crschmidt
Priority: critical Milestone: 2.7 Release
Component: Renderer Version: SVN
Keywords: Cc:
State: Complete

Description

Currently, we only have two renderers. Although this is somewhat usable, it's not the most interesting use of our relatively complex setup separating Vector Layers and rendering, especially since right now we just look at browser type.

Some browsers have a 2d element ('canvas') which is pretty useful: when drawing *lots* of points, one can imagine the utility of a 2d drawing canvas that requires more work, but won't slow down other performance (because elements aren't inserted into the dom).

Attachments

canvas.renderer.patch (15.6 kB) - added by crschmidt on 04/12/08 10:25:41.
canvas.patch (22.6 kB) - added by crschmidt on 08/01/08 09:04:27.
canvas.2.patch (22.5 kB) - added by crschmidt on 08/01/08 09:05:01.
canvas.3.patch (21.9 kB) - added by crschmidt on 08/01/08 09:53:13.
canvas.4.patch (24.6 kB) - added by crschmidt on 08/02/08 11:04:17.
canvas.5.patch (24.4 kB) - added by crschmidt on 08/04/08 04:55:23.

Change History

04/12/08 10:25:41 changed by crschmidt

  • attachment canvas.renderer.patch added.

04/12/08 10:29:49 changed by crschmidt

Attached is a patch for a Canvas renderer. It has been tested in Safari 3.1, FF2, and Opera 9.5 on Mac.

It implements feature selection by looping over its internal list of features, and doing intersection queries. Depending on the browser, this may or may not be reasonable. One thing that this behavior suggests is that the standard Feature Handler should perhaps be informed whether it is being used as a 'hover' handler: if it isn't, it shouldn't bother doing the (now somewhat expensive) getFeatureIdFromEvent check on mousemove as it currently does.

For browsing somewhat static vector data, this Renderer is quite effective, especially for browsers where SVG support is less fast: FF2, for example, gets to be much more usable on whole-world country borders maps that are currently being tossed about.

Includes support for stroke/fill width/color/opacity, externalGraphic, point/line/linearring/polygon and collections thereof.

04/12/08 10:31:39 changed by crschmidt

Other than the Renderer itself, only one small change was made to the code: the Vector Layer now sets 'locked' on the renderer to indicate that there are more operations coming up, and that if the Renderer has the ability to 'delay' redrawing, it should do so. I don't know if 'locked' is the right keyword for this, but it seemed to make sense.

04/12/08 15:00:26 changed by pgiraud

I'm certain that this is something Paul is very interested in. One year and a half ago, he wrote the first OL vector renderer and it was with canvas.

One important thing I first noticed is that panning seem much smoother in the canvas example. Thanks Chris for this great job.

04/12/08 15:10:29 changed by crschmidt

For the record, I wrote OpenLayers.Layer.Canvas (which was vector-ish) before Paul started his vector work ... ;)

04/12/08 16:11:55 changed by pspencer

very cool! I think this is a great addition, it works well for me in ffox2 and safari 3 on mac.

Is there anything missing, or is it close to being ready for review?

Would there be any benefit to creating a Tile sub-class with Canvas to render vectors into 'tiles'?

04/12/08 17:14:47 changed by crschmidt

It needs tests, and the patch should probably include something like the choropleth example I stuck in the sandbox. Also, I think my changes to the vector layer could use some further discussion before they become 'final': at the very least, they need docs on the base Renderer class, and it's possible that I've only implemented half of what we need.

Also, using the SelectControl feature with this is essentially unusable with any large-sized non-point layers at the moment due to the intersection-test on mousemove even when 'hover' is false. I think that's worth at least thinking about before we go any farther: Obviously, it liiiimits you such that you can't do 'hover: true' with large geometry sets, but you should still be able to do a click-based selectfeature control without too much trouble if we make it so that the feature handler isn't constantly looking to find intersecting geoms even when it doesn't need to.

To your tile question, I'm pretty sure the answer is 'no'. Tiles are a request mechanism: Layer.WFS could be (and has been, by users) updated to use Tiles (alternatively, we can implement this in the new Protocol handling that we're bandying about for 2.7 instead): the Renderer doesn't need to work in tiles...

Though I can sort of see the benefit, I guess: if there are 'tiles', then you only have to redraw that tile, not the whole view. Hm. I don't think it would need to be implemented as a tile subclass, in any case: I think that the Canvvas Renderer could do this as an optimization if we wanted it to.

Also of note: this doesn't help IE at all, which is where vectors are the slowest anyway, so anyone who needs to actively support IE is going to have to play "lowest common denominator" with IE anyway. (IECanvas is just a wrapper on VML -- a Canvas Renderer on top of a VML wrapper seems likely to be less effective than a VML Renderer directly.) It should be possible to do an image renderer in a similar way (with a PIL-backed image drawing server or something like that) to accomodate for IE's deficiencies in this regard.

04/12/08 17:31:31 changed by crschmidt

Also, need to run it in IE, and make sure that the 'supported()' test on the canvas renderer doesn't cause errors, and make sure that I didn't leave extra ,s in, etc. I'm sure *something* I did will break IE.

07/28/08 11:55:33 changed by crschmidt

  • owner set to crschmidt.
  • priority changed from minor to critical.
  • status changed from new to assigned.

08/01/08 09:04:27 changed by crschmidt

  • attachment canvas.patch added.

08/01/08 09:05:01 changed by crschmidt

  • attachment canvas.2.patch added.

08/01/08 09:53:13 changed by crschmidt

  • attachment canvas.3.patch added.

08/01/08 14:52:54 changed by crschmidt

  • state set to Review.

08/01/08 14:54:04 changed by crschmidt

Tests pass in FFox, Safari, are skipped in IE. WFS Reprojection example is changed to demonstrate functionality. Minor changes to Layer.Vector, and new Renderer added.

08/01/08 21:49:04 changed by crschmidt

  • owner deleted.
  • status changed from assigned to new.

08/02/08 09:44:09 changed by pagameba

I've taken a look and confirmed that this works nicely in Safari and Firefox, and the tests pass. It doesn't look like you've addressed some of your previous concerns (comment 6 above), which I think is fine for an initial implementation - if it gets used then issues will crop up (or not) and can be addressed at that time.

The implementation looks good, although I don't know enough about the internals of the Renderer architecture to tell if anything significant is missing - if you are concerned about this then one of the camptocamp guys should take a look, otherwise I think it is ready to commit with a couple of very minor comments:

* It looks like the getResolution function defined in the Canvas renderer is a dup of the base class getResolution and shouldn't be needed?

* jslint reveals missing semi-colons (line 175 and 240)

08/02/08 10:36:24 changed by crschmidt

Paul:

Thanks for the feedback. I addressed the Layer.Vector 'locked' thing in code, and I'm pretty happy with it. A brief conversation with Erik didn't throw up any red flags. As for the SelectFeature control, you're right: I discussed with Tim and then forgot to do anything about it. That's now #1655, thanks.

I'm uploading a new patch which removes the unneccesary getResolution and fixes the jslint errors. I think Erik still wanted to glance at this; if he gets a chance early next week, I'll let him, and otherwise I'll commit this.

Thanks again for the feedback.

08/02/08 11:04:17 changed by crschmidt

  • attachment canvas.4.patch added.

08/03/08 10:02:11 changed by euzuro

  • owner set to euzuro.
  • status changed from new to assigned.

08/04/08 03:42:38 changed by fredj

In lib/OpenLayers/Renderer/Canvas.js container, extent, size, resolution and map properties are defined but these properties are already defined in parent class (OpenLayers.Renderer).

They can be removed (unless I miss something else ...)

08/04/08 04:55:23 changed by crschmidt

  • attachment canvas.5.patch added.

08/04/08 04:56:26 changed by crschmidt

Yep, more sideeffects of starting by copying Renderer.js. Thanks. New patch attached.

08/04/08 05:37:17 changed by fredj

Chris, you forget the 'map' property.

The 'locked' attribut could also be use by the SVG renderer to ask the browser to suspend the redraw of the svg element. See (1), the functions are 'suspendRedraw' and 'unsuspendRedraw' but I don't know if it will speed up the rendering.

(1) http://www.w3.org/TR/2001/REC-SVG-20010904/struct.html#InterfaceSVGSVGElement

08/25/08 20:13:13 changed by euzuro

  • owner changed from euzuro to crschmidt.
  • status changed from assigned to new.

already enough reviews of this, don't need another pig in the kitchen.

08/26/08 09:22:59 changed by crschmidt

  • status changed from new to closed.
  • state changed from Review to Complete.
  • resolution set to fixed.

(In [7862]) Add support for a Canvas renderer. This renderer will allow for some new capabilties in OpenLayers Vector drawing, including:

  • Vector support for iPhone, Safari 2.x series browsers
  • Improved performance of dragging the map with a large number of geometries.

The Vector layer default renderer order is now SVG, VML, Canvas, so browsers with Canvas support and no SVG or VML will be able to draw vectors.

The Canvas layer has a number of limitations: getFeatureFromEvent is much slower than the other types of layer, and any change to any feature requires a redraw of the entire canvas. Because Canvas is typically a pretty fast drawing implementation, the latter is less problematic than it might otherwise be.

r=pagameba,fred, with glances from a couple other people. (Closes #1512)