OpenLayers 3: map Vector layer (ol. layer. Vector), openlayersvector

Source: Internet
Author: User
Tags map vector

OpenLayers 3: map Vector layer (ol. layer. Vector), openlayersvector

In GIS, maps are generally divided into two categories: raster maps and vector maps. raster maps are actually digital photos, but some are satellite photos. They share a common feature, that is, they are all composed of multiple pixels. The pixel size is consistent, and the Row Height and column width are consistent. From this perspective, A remote sensing image is like a grid.

A vector map is composed of many elements. Each element has its own geographic coordinates. based on mathematical rules, no matter how the vector map is enlarged, the map will not be distorted. It isOpenLayersIs a very important layer type, using vector map can achieve a lot of functions, such as dynamic plotting, callingWFSService, editing elements, clickable elements, dynamic loading elements, and so on.

Composition of vector layers

The vector layer is rendered on the client and corresponds to the browser in the web environment. A vector layer consists of a data source and a style. The data forms the elements of the vector layer, and the style specifies the display mode and appearance of the elements. An initialized vector layer contains one or more features, each of which consists of a geographical attribute and multiple other attributes, which may contain names. The structure is as follows:

When initializing a vector layer, you can configure the behavior and appearance of the vector layer with the following options:

  • Brightness, contrast, layer brightness and contrast are both numerical values;
  • RenderOrder, a function that specifies a rule (function (ol. Feature, ol. Feature ));
  • Hue, tone, is a numerical value;
  • MinResolution: Minimum visible resolution;
  • MaxResolution, the maximum visible resolution;
  • Opacity, transparency of layers, 0 ~ Value Between 1, 1 indicates opacity;
  • Saturation, saturation;
  • Source, layer data source;
  • Style, layer style, An ol. Style. style or an ol. Style. style array, or a function that returns ol. Style. style;
  • Visible, layer visibility, default value:true.
Initialize a vector Layer

Use an example to illustrate how to initialize a vector layer:

var vector = new ol.layer.Vector({  source: new ol.source.Vector({    url: 'data/china_province_boundries.geojson',    projection: 'EPSG:3857',    format: new ol.format.GeoJSON({        extractStyles: false    })  }),  style: style});

In this examplesourceThe url sets the data source, the projection sets the geographic coordinate system, and the format sets the data parser. Because the data source specified by the url is in geojson format, the parser is also a geojson parser.new ol.format.GeoJSON.

Acquisition Element

So how to obtain a certain feature of a vector Layer? The general idea is vector. getFeature () is actually not. The data of the vector is contained in the source. To obtain the feature data of the vector, it must be in the source, for example, vector. getSource (). getFeatures (), this function returns a feature array, directly using [], you can use it, or get it according to the element ID (getFeatureById ()).

Similarly, as long as data-related operations are performed, the source instance of the vector needs to be obtained and then operated, for example, adding elements (addFeature) and deleting elements (removeFeature ), perform the same operation (forEachFeature) on each element ).

Geometry

GetGeometry () can be used to obtain the geographical attributes of elements. Of course, this function returns the geometry contained by the elements. geometry contains many types, mainly include point, multi point, linear ring, line string, multi line string, polygon, multi polygon, and circle.

After geometry is obtained, you can obtain the coordinates of the elements. You can make some geographic judgments based on the coordinates, such as determining whether a coordinate is within the element (containsCoordinate(coordinate)OrcontainsXY(x, y)) To obtain the central coordinates of the elements.

Summary

Using vector layers, you can achieve many functions, such as dynamic loading of vector data and callingWFSService, dynamic plotting, and editing elements are performed at the layer level and element level respectively.

For example, different images can be drawn on the vector layer, and attributes can be added, and then updated to the database, that is, the dynamic plotting system; or element-level data can be dynamically loaded, such as tracking the vehicle trajectory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.