Openlayers 3 map vector Layer (ol.layer.Vector) detailed

Source: Internet
Author: User
Tags map vector

In GIS, maps are generally divided into two categories: raster maps and vector maps, and raster maps are digital photographs, but some satellites. They have a common feature, that is, they are made up of many pixels, the pixel size is consistent, the row height and the column width are consistent, from this point of view, a remote sensing image is like a grid.

Vector maps are made up of many elements, each with its own geographical coordinates, based on mathematical rules, and no matter how the vector map zooms in, the map will not be distorted. It's a OpenLayers very important layer type, and with vector maps you can implement a lot of features, such as dynamic plotting, invoking WFS services, editing features, clickable features, dynamically loading features, and more.

Composition of vector layers

Vector layers are rendered on the client, and in the Web environment, the browser is the corresponding one. A vector layer consists of a data (source) and a style (style) that make up the features of the vector layer, and the style specifies how and how the features are displayed. A successful initialization vector layer contains one to multiple features (feature), each feature consists of a geographic attribute (geometry) and several other attributes, which may contain names, etc. Structures such as:

There are a number of options for configuring the behavior and appearance of vector layers when initializing vector layers, which are commonly used:

    • Brightness, contrast, layer brightness and contrast, are all a numeric value;
    • Renderorder, a function that specifies a rule (the ol. Feature, OL. Feature));
    • Hue, hue, is a value;
    • Minresolution, the smallest visible resolution;
    • Maxresolution, the maximum visible resolution;
    • Opacity, the transparency of the layer, the value between the 0~1, 1 means opaque;
    • saturation, saturation;
    • Source, layer data sources;
    • style, layer style, a ol.style.Style or an Ol.style.Style array, or a function that returns Ol.style.Style;
    • Visible, layer visibility, default to true .
Initialize a vector layer

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

varnew ol.layer.Vector({  new ol.source.Vector({    ‘data/china_province_boundries.geojson‘,    ‘EPSG:3857‘,    new ol.format.GeoJSON({        false    })  }),  style: style});

The URL in the example sets the source of the source data, projection sets up the geographic coordinate system, and format sets the parser for the data, because the URL specifies that the data source is the Geojson format, so the parser is also the Geojson parser new ol.format.GeoJSON .

Get the essentials

So, in a vector layer how to get one of its feature, the general idea is vector.getfeature (), actually not, the vector data is contained in the source, to obtain the vector feature data, in the source, For example Vector.getsource (). Getfeatures (), the function returns a feature array, directly using [], fetching, or based on the ID of the feature (Getfeaturebyid ()).

Similarly, as long as the data-related operations are given the source instance of the vector, then operations such as adding features (Addfeature), deleting features (removefeature), and doing the same for each feature (Foreachfeature).

Geometry of acquired elements

With Getgeometry (), you can get the geographic attributes of a feature, which of course returns features that contain many types of geometry,geometry, primarily point, multi Point, linear ring, line string, Multi line string, polygon, multi polygon, circle.

After obtaining the geometry, the coordinates of the elements can be obtained, and some geographical judgments can be made according to the coordinates, such as determining whether a coordinate is located within the feature ( containsCoordinate(coordinate) or containsXY(x, y) ), and obtaining the central coordinate of the element.

Summarize

With vector layers, you can implement many functions, such as dynamically loading vector data, invoking WFS services, dynamically plotting, and editing features, respectively, at the layer level and at the feature level.

For example, you can do this by drawing different graphs on a vector layer, adding properties, and then updating to a database, i.e. plotting the system dynamically, or dynamically loading feature-level data, such as tracking a car's trajectory.

Openlayers 3 map vector Layer (ol.layer.Vector) detailed

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.