[GIS] How to use Canvas element with OpenLayers

html5openlayers

I would like to use element canvas of HTML 5 in OpenLayers to render maps.

I am searching some code or reference in which I can check it, can you help me in this?

Best Answer

You can have a look at this OpenLayers example. Below is the highlight of line from the code with mention the renderers.

var wfs = new OpenLayers.Layer.Vector("States", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
        version: "1.1.0",
        srsName: "EPSG:900913",
        url:  "http://v2.suite.opengeo.org/geoserver/wfs",
        featureType: "states",
        featureNS: "http://usa.opengeo.org"
    }),
    styleMap: styleMap,
    renderers: ["Canvas", "SVG", "VML"]
});

renderers: ["Canvas", "SVG", "VML"]

renderers array contains a list of renderers used by OpenLayers in the given order. So here first OpenLayers check for Canvas and if your browser doesnt supports HTML5Canvas, it switches to the next one in the row, SVG and if fails again it goes for VML (IE only i guess)

You can see the API doc of renderer class here. But its not very helpful. There is a nice report on different HTML5 renderers usage and performance analysis done by someone available in the trac wiki. Thanks for the work

Related Question