Special types of vector layersΒΆ

For example GML or KML are special types for vector layers. In fact, they are just normal Vector layers with features and everything, but they have also defined Protocol and Strategy.

Strategy is the way, how features are loaded from the server into the map, using for example BoundingBox of the map, Cluster or features etc. Protocol is the format, which will be used for communication between the server and mapping application, for example KML, GML, WFS, etc.

For files (GML or KML or similar), the protocol is OpenLayers.Protocol.HTTP . There is also OpenLayers.Protocol.WFS available.

Protocol usually needs the Format configuration option - that is the parser, which will make data to OpenLayers.Features, such as OpenLayers.Format.GML or OpenLayers.Format.KML and similar.

Conclusion: If you need to read vector data from the server, Strategy and Protocol have to be defined. Protocol needs at least url and format configuration options:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
            var kmlLayer = new OpenLayers.Layer.Vector("KML layer",
                    {
                        // A simple strategy that requests features once
                        // and never requests new data.
                        strategies: [new OpenLayers.Strategy.Fixed()],

                        // don't forget to define layer's coordinate
                        // system, if it differes from the map
                        projection: new OpenLayers.Projection("epsg:4326"),

                        // and protocol definition begins
                        protocol: new OpenLayers.Protocol.HTTP({
                            url: "czech_republic.kml", // data path

                            // format KML definition
                            format: new OpenLayers.Format.KML({ 
                                extractAttributes: true
                            })
                        })
                    });

See the whole result in 09_vector_layers.html

Main Menu


Previous topic

Layer object

Next topic

Controls

This Page