OpenLayers-detailed description of map layer data source (ol. source) and ps layer Mixed Mode

Source: Internet
Author: User

OpenLayers-detailed description of map layer data source (ol. source) and ps layer Mixed Mode

Source is an important component of a Layer, indicating the source of the Layer, that is, the service address. You can uselayer.setSource(source)Specify later.

1. types included

All of the classes described above can be instantiated. There are also some base classes that cannot be instantiated and are only responsible for being inherited. They include:

  • Ol. source. Image, which provides a single Image data type and directly inherits fromol.source.Source;
  • Ol. source. Tile, which provides image data split into grid slices and inherits fromol.source.Source;
  • Ol. source. Vector, which provides Vector layer data and inherits fromol.source.Source;
Ii. Usage description 1. ol. source. Vector

Vector layer data source

1.1 events

Contains four events,addfeature,changefeature,clear,removefeature.

addfeature, Triggered when an element is added to the source;
changefeatureTriggered when elements change;
clear, Triggered when the clear method of source is called;
removefeatureOccurs when the element is removed.

1.2 Parameters

Accepted parameters:

/** * @typedef {{attributions: (Array.<ol.Attribution>|undefined), *     features: (Array.<ol.Feature>|undefined), *     format: (ol.format.Feature|undefined), *     loader: (ol.FeatureLoader|undefined), *     logo: (string|olx.LogoOptions|undefined), *     strategy: (ol.LoadingStrategy|undefined), *     url: (string|undefined), *     wrapX: (boolean|undefined)}} * @api */
  • Attribution: the content of the logo in the lower right corner of the map;
  • Features: data read from strings by geographical elements;
  • Format: the data format used for loading elements after url attribute settings. asynchronous AJAX loading is used;
  • Loader: The loading function used to load elements;
  • Logo and logo content;
  • Strategy: the strategy used to load elements. By default, all elements are loaded at a time;
  • Url, the address of the element data;
  • WrapX: whether to repeat the horizontal axis of the map. The default value istrue.
1.3 instance

Features Method
Suppose there is a string containing space data, geojsonObject, which is in GeoJSON string format, it can be used to initialize a layer.

var vectorSource = new ol.source.Vector({    features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)});var vectorLayer = new ol.layer.Vector({    source: vectorSource,    style: style});map.addLayer(vectorLayer);

Url + format Method
If a file is used as the data source, you can configure the url attribute to load data:

var vectorLayer = new ol.layer.Vector({  source: new ol.source.Vector({    url: 'data/geojson/countries.geojson',    format: new ol.format.GeoJSON()  })});

Both methods specify the data source format. The formats supported by the vector data source include: gml, EsriJSON, geojson, gpx, igc, kml, osmxml, ows, polyline, topojson, wfs, wkt, and wms capabilities (compatible with wms formats) wms getfeatureinfo, wmts capabilities, xlink, xsd, and other formats. These formats include readFeatures, readFeature, and readGeometry for Data Reading.

2. ol. source. Tile

Provides image map data split into slices.
Configurable options

/** * @typedef {{attributions: (Array.<ol.Attribution>|undefined), *            extent: (ol.Extent|undefined), *            logo: (string|olx.LogoOptions|undefined), *            opaque: (boolean|undefined), *            tilePixelRatio: (number|undefined), *            projection: ol.proj.ProjectionLike, *            state: (ol.source.State|undefined), *            tileGrid: (ol.tilegrid.TileGrid|undefined), *            wrapX: (boolean|undefined)}} */

We will not introduce the same options as vector. We will introduce the unique options of vector:

  • Extent: the default coordinate range of the map view;
  • Opaque, whether it is opaque or not. A boolean value. The default value is false;
  • TilePixelRatio, slice size adjustment options, such as 256 × 256, and 512 × 512;
  • Projection, projection;
  • State, the status of the map, includingundefined,loading,ready,error;
  • TileGrid, covering the grid on the map;

Accepted events

  • Tileloadstart: The event triggered when the slice starts loading;
  • Tileloadend: this event is triggered after the slice is loaded;
  • Tileloaderror: processing of slice loading errors.
3. ol. source. Image

Provides a single image map.
Configurable options

/** * @typedef {{attributions: (Array.<ol.Attribution>|undefined), *            extent: (null|ol.Extent|undefined), *            logo: (string|olx.LogoOptions|undefined), *            projection: ol.proj.ProjectionLike, *            resolutions: (Array.<number>|undefined), *            state: (ol.source.State|undefined)}} */
  • Resolutions, map resolution. Other options are the same as those above.

Event triggered

  • Imageloadstart: The event triggered when the image map is loaded;
  • Imageloadend: The event triggered when the image map is loaded;
  • Imageloaderror: The event triggered when an error occurs during image map loading.
Iv. Summary

Source is a required option in layer. It defines the source of map data, and data-related functions, such as addfeature and getfeature, are defined in source, and the data source supports multiple formats.

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.