1. The view properties

1.1 Common attributes of view
  • Center is a coordinate [x, y] that represents the center position of the map view;
  • It is a projection coordinate system for maps. The default projection is spherical Mercator coordinates (‘EPSG: 3857’).
  • Zoom indicates the initial zoom level of the map;

2. The view method

View class methods are mainly for view attributes of get and set methods, its basic methods are many, we will commonly used methods are classified:

Bold is a common method

Get the class:

  • GetCenter gets the view center and returns the coordinates of a map center.
  • GetZoom Gets the current zoom level. This method may return a non-integer scale level if the view does not limit resolution or is interacting or animating.
  • GetMaxZoom Gets the maximum zoom level of the view.
  • GetMinZoom Gets the minimum zoom level of the view.
  • GetAnimating Determines whether the view is animated.
  • Gettens determines whether a user is interacting with a view, such as panning or scaling.
  • GetKeys gets a list of object property names.
  • GetMaxResolution gets the maximum resolution of the view.
  • GetMinResolution gets the lowest resolution of the view
  • GetProjection retrieves the “projection coordinate system” used by maps, e.g. EPSG:4326;
  • GetProperties gets the object with all the property names and values.
  • GetResolution gets the view resolution.
  • GetResolutionForExtent gets the resolution of the supplied range (in map units) and size (in pixels).
  • GetResolutionForZoom Gets the resolution of the zoom level.
  • GetResolutions gets the resolution of the view. This returns an array of resolutions passed to the View’s constructor, or undefined if not given.
  • GetRevision gets the version number of this object. Each time you modify an object, its version number increases.
  • GetRotation Gets view rotation.
  • GetZoomForResolution gets the zoom level of the resolution.

The set class:

  • SetCenter sets the center of the current view. Any scope restrictions will apply.
  • SetConstrainResolution sets whether the view should allow intermediate zoom levels.
  • SetZoom scales to a specific zoom level. Any resolution limits will apply.
  • SetMaxZoom sets the new maximum zoom level for the view.
  • SetMinZoom sets the new minimum zoom level for the view.
  • SetProperties Sets the collection of key-value pairs. Note that this changes all existing attributes and adds new ones (none are deleted).
  • SetResolution sets the resolution of this view. Any resolution constraints will apply.
  • SetRotation Sets the rotation Angle of the view. Any rotation constraints will apply.

Other categories:

  • Rotate takes two arguments, the number of rotation angles (rotation) and the center of rotation (opt_anchor, optional), and rotates the map around the opt_anchor.
  • IfDef checks if the center and resolution of the map have been set, returns true if both are set, false otherwise;
  • FitExtent (extent, size) accepts two parameters: extent and size. The type of extent is ol. extent – [left, bottom, right, top], and size is obtained by map.getSize(). This function is similar to the zoom to layer function of ArcGIS, which scales the view of the map to a suitable scale visible to the extent area.
  • FitGeometry (Geometry, size, opt_options), the parameters are geographical elements, map size, and optional parameters; According to the given geographical elements, scale the view to the size suitable for geographical elements display;

3. Specific example of view method

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the set class * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / adjust the center of the view The default projection is spherical Mercator (EPSG:3857) coordinates such as [13070000, 3060000] map.view.setCenter(fromLonLat([120.15723903726405, 28.40811810432885]) // Adjust the view resolution to 344 map.view.setresolution (344) // Adjust the view rotation 60 degrees map.view.setrotation (math.pi / 3) // SetZoom (9) // Set view value Add object with GGG value 444 map.view.set(" GGG ", Unset (" GGG ") // Set view Value add multiple attribute values object map.view.setProperties({" GGG ": 444, 'kkk': 777}) / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * get class * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / access to view the value of the attribute Map. The getKeys () / / access to view the value of the object map. The getProperties () / * * * * * * * * * * * * * * * * * * * * * * * * * * the animate class * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / add animation to jump to a particular location, zoom and center separate written said first zoom level, at the center of the set, if / / {zoom: 7,center: fromLonLat([125.15723903726405, 28.40811810432885]), duration:2000} 7, duration: 2000}, {center: fromLonLat ([125.15723903726405, 28.40811810432885]), duration: 2000}); / / cancel the above to jump to a map for the location of the animation. The cancelAnimations (); / * * * * * * * * * * * * * * * * * * * * * * * * * * event listeners class * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / change event monitoring, Once ("change", this.aa) // Listen for the change event, On ("change", this.aa) // Remove listener change map.view. UN ("change", This.aa) // dispatchEvent listens for such events (event) => { map.view.dispatchEvent("change") // map.view.dispatchEvent({type: "change", event: Event}) // Return true to live false})Copy the code