All the vector objects discussed in this section must be added to a Vector layer to be visible. The vector objects are added through the addFeatures
method of the Vector layer.
Points can be used to mark specific locations on the map. The point can be drawn and styled as either a point of a particular radius or as an image.
Vector points are drawn using the ALKMaps.Feature.Vector
. The first parameter of the Vector object is a ALKMaps.Geometry.Point
defining the location for the point. The second parameter is addition attributes related to the point. The third parameter is for style definition.
In addition to manually styling the point, you can place an image at the desired location. This is done using different properties of the style paramter.
Lines are drawn using ALKMaps.Geometry.LineString
A ALKMaps.Geometry.LinearRing
object represents a closed sequence of points that can be filled. LinearRings are contructed from an array of points.
Polygons are constructed using a collection of ALKMaps.Geometry.LinearRing
objects. The first ring object in the collection should represent the outer bounds of the polygon and the rest of the ring objects represent internal holes.
If you have a vector layer with the potential of a high density of points, you may choose to use clustering to provide a cleaner visualization of those points.
When clustering is enabled, the map will automatically cluster points on the chosen layer based on two criteria. The first is a distance specified in pixels. The second criteria is a threshold of the number of points.
var clusterStrategy = new ALKMaps.Strategy.Cluster({ distance: 20, threshold: 2 }); var vectorLayer = new ALKMaps.Layer.Vector("Vector Layer", { strategies: [clusterStrategy], styleMap: pointStyleMap }); map.addLayer(vectorLayer);
To make the most of clustering, you will want to vary the styling of clustered points. You can create a style for your points that uses dynamic values to changes the visualization based on clustering.
var pointStyle = new ALKMaps.Style({ strokeColor: "#116666", pointRadius: "${radius}", strokeWidth: 2, fillColor: "${fill}", label: "${label}" },{ context: { fill: function(feature){ return (feature.cluster) ? "#99EEEE" :"#66AAAA"; }, radius: function(feature){ return (feature.cluster) ? 15 : 8; }, label: function(feature){ return (feature.cluster) ? feature.cluster.length : ""; } } });
Dynamic values in styles are handled via the context of the style. Each function in the context will receive the feature as a parameter to allow for inspection and use in the dynamic value. If the feature is a cluster, it will have a cluster property which is an array of the features in the cluster. More details are at Styling section