当前位置: 代码迷 >> 综合 >> openlayer 方法记录
  详细解决方案

openlayer 方法记录

热度:76   发布时间:2023-12-16 09:34:04.0

文章目录

    • 源文件蓝奏云:
    • 1. ol.Map类:该类是一个地图容器类
    • 2、ol.Control类:该类是一个地图控件基类
    • 3、ol.Collection类:地图容器类,用于扩展JS数组,提供快捷操作。
    • 4、ol.control.ZoomToExtent类:放大到设定区域地图控件类
    • 5、ol.layer.Tile类:该类是一个瓦片图层类,用于显示瓦片资源。
    • 6、ol.source.OSM类:OpenStreetMap瓦片图层资源。
    • 7、ol.View类:该类是一个地图显示视图类。
    • 8、ol.control.MousePosition类:该类是控制显示鼠标光标的坐标
    • 9、ol.control.ScaleLine类:比例尺控件,显示地图当前视图的比例尺。
    • 10 、ol.control.OverviewMap类:鹰眼控件
    • 11、ol.source.BingMaps类:必应地图的瓦片资源。
    • 12、ol.layer.Vector类:用于显示在客户端渲染的矢量数据。
    • 13、ol.source.Vector类:矢量要素来源。
    • 14、ol.format.GeoJSON类:操作GeoJSON数据,包括各种读写方法。
    • 15、ol.format.KML类:操作KML数据,包括各种读写方法。
    • 16、ol.proj类:坐标系统定义和转换类
    • 17、ol.Feature类:该类是设置一个矢量要素的几何属性和其他属性。
    • 18、ol.geom.Point类:该类是设置点矢量特性的呈现风格。
    • 19、ol.style.Style类:控制地图样式,其包含了地图样式的方方面面
    • 20、ol.style.Fill类:该类是设置矢量要素的填充类型。
    • 21、ol.style.Stroke类:该类是设置矢量要素的边界样式。
    • 22、ol.style.Image类:该类是设置矢量要素的图片样式(包含的子类有ol.style.Circle、ol.style.Icon、ol.style.RegularShape)。
    • 23、ol.style.Text类:该类是设置矢量要素的文字样式。
    • 24、ol.geom.LineString类:该类是设置线矢量特性的呈现风格。
    • 25、ol.geom.Circle类:该类是设置圆矢量特性的呈现风格。
    • 26、ol.geom.Polygon类:该类是设置一个多边形几何体类。
    • 27、ol.interaction.Draw类:该类是实例化地图交互绘制类对象。
    • 28、ol.proj.fromLonLat(地理坐标,投影坐标):将地理坐标转化为投影坐标
    • 29、ol.animation.rotate类:
    • 30、ol.animation.pan类:
    • 31、ol.animation.bounce类:
    • 32、ol.proj.transform (坐标,源,目标)

源文件蓝奏云:

https://rod.lanzous.com/b0dkhla8f

1. ol.Map类:该类是一个地图容器类

		 //实例化Map对象加载地图var map = new ol.Map({
    //地图容器div的IDtarget: 'mapCon',controls: ol.control.defaults({
    /** @type {olx.control.AttributionOptions} */attributionOptions: ({
    collapsible: true})}).extend([new ol.control.ZoomToExtent({
    extent: [813079.7791264898, 5929220.284081122,848966.9639063801, 5936863.986909639]})]),//地图容器中加载的图层layers: [TiandiMap_vec, Tianditu_cva],//地图视图设置view: new ol.View({
    //地图初始中心点center: [0, 0],//地图初始显示级别zoom: 2,projection: "EPSG:3857"})

1.1 构造函数:ol.Map(options)

参数说明:
options:(object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】target:(Element | string | undefined)可选项,指定地图所在的网页div元素的id,
如果在构建时未指定,则必须调用ol.Map()类的setTarget()方法以便绘制地图。【2】layers:(Array-[ol.layer.Base] | ol.Collection[ol.layer.Base | undefined])可选项,指定加载的图层。
如果未定义,则将呈现不包含图层的地图(图层是按提供的顺序呈现的,如果想要矢量图层显示在瓦片图层顶部,则必须位于瓦片图层之后)。【3】view:(ol.View | undefined)可选项,设置地图显示视图。
如果在构建时未指定,则必须通过ol.Map()类的setView()方法指定,否则不会提取图层源。

1.2 方法说明:

render():请求地图渲染(下一帧动画)。getEventPixel(event):获取相对于浏览器窗口的地图像素位置。
event:(event)事件。getView():获取地图视图。返回值为{
    ol.View}类。addLayer(layer):将地图图层添加到地图容器中。
layer:(ol.layer.Base)地图图层。removeLayer(layer):将图层从地图容器中移除。
layer:(ol.layer.Base)地图图层。addControl(control):将指定的控件添加到当前地图容器中。
control:(ol.layer.Base)控件。

2、ol.Control类:该类是一个地图控件基类

	    controls: ol.control.defaults({
    /** @type {olx.control.AttributionOptions} */attributionOptions: ({
    collapsible: true})}).extend([new ol.control.ZoomToExtent({
    extent: [813079.7791264898, 5929220.284081122,848966.9639063801, 5936863.986909639]})

2.1方法说明:

ol.control.defaults(opt_options):
该方法表示地图默认包含的一组控件。
除非另外配置,否则将返回一组默认的地图控件,分别是:ol.control.Zoom(地图缩放控件),ol.control.Rotate(地图旋转控件),ol.control.Attribution(地图属性控件)。
返回值为{
    ol.Collection | [ol.control.control]}类。opt_options:
(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。attributionOptions:
( olx.control.AttributionOptions | undefined)设置属性控件的相关属性
例如:collapsible: true,即表示地图数据源信息控件可收缩。默认为true。zoom:(number | undefined)可选项,设置地图初始的缩放级别
(如果在构建时未指定,则必须通过ol.View()类的constrainResolution()方法确定初始缩放级别)

3、ol.Collection类:地图容器类,用于扩展JS数组,提供快捷操作。

3.1 构造函数:ol.Collection(opt_array)

参数说明:
opt_array:(Array类型)数组

3.2方法说明:

extend(arr):该方法实现将要素添加到集合中
arr:(Array类型)将要添加进集合的数组。例如代码中的[ol.control.MousePosition()]

4、ol.control.ZoomToExtent类:放大到设定区域地图控件类

 		 //实例化ZoomSlider控件并加载到地图容器中var zoomslider = new ol.control.ZoomSlider();map.addControl(zoomslider);//实例化zoomToExtent控件并加载到地图容器中var zoomToExtent = new ol.control.ZoomToExtent({
    extent: [813079.7791264898, 5929220.284081122,848966.9639063801, 5936863.986909639]});map.addControl(zoomToExtent);

4.1 构造函数:new ol.control.ZoomToExtent(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。extent:(ol.Extent | undefined)
可选项,表示放大到范围的大小。maxResolution:(number | undefined)
可选项,最大分辨率minResolution:(number | undefinedd)
可选项,最小分辨率className:(string | undefined)
可选项,表示图标样式的类名

5、ol.layer.Tile类:该类是一个瓦片图层类,用于显示瓦片资源。

这些瓦片提供了预渲染,并且由特定分辨率的缩放级别组织的瓦片图片网格组成。

	   var TiandiMap_vec = new ol.layer.Tile({
    title: "天地图矢量图层",source: new ol.source.XYZ({
    url: "http://t0.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=" + parent.TiandituKey(),//parent.TiandituKey()为天地图密钥wrapX: false})});var Tianditu_cva = new ol.layer.Tile({
    title: "天地图矢量注记图层",source: new ol.source.XYZ({
    url: "http://t0.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=" + parent.TiandituKey(),//parent.TiandituKey()为天地图密钥wrapX: false})});

5.1 构造函数:ol.layer.Tile(options)

参数说明:
options:(object类型)可选项,设置该对象其他属性,以键值对的形式设置。
【1】source:(ol.source.Tile)必填项。为图层设置来源、服务地址。

6、ol.source.OSM类:OpenStreetMap瓦片图层资源。

6.1 构造函数:ol.source.OSM(opt_options)

参数说明:
opt_options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。
【1】cacheSize:(number|undefined)可选项,设置缓存大小。
默认是2048。【2】crossOrigin:(null|string|undefined)可选项,设置加载瓦片的跨域属性。
默认是匿名的。【3】maxZoom:(number|undefined)可选项,设置最大放大级别。
默认是19。【4】opaque:(boolean|undefined)可选项,设置图层是否是不透明的。
默认是true。【5】reprojectionErrorThreshold:(number|undefined)可选项,设置重投影允许的最大误差(以像素为单位)。
设置值越大,精度越低。默认是0.5。【6】tileLoadFunction:(ol.TileLoadFunctionType|undefined )可选项,设置通过给定的URL加载瓦片的功能。
默认是function(imageTile, src) {
    imageTile.getImage().src = src; };7】url:(string|undefined)可选项,设置url模板。默认为https://{
    a-c}.tile.openstreetmap.org/{
    z}/{
    x}/{
    y}.png。【8】wrapX:(boolean|undefined)可选项,设置是否在地图水平坐标轴上重复。
默认是true

7、ol.View类:该类是一个地图显示视图类。

ol.View对象是地图初始化必备三要素之一,表示一个简单的二维视图的映射,主要控制地图与用户的交互,如进行缩放,调节分辨率、地图的旋转等。

7.1 构造函数:ol.View(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
【1】center:(ol.Coordinate|undefined)可选项,设置地图显示中心;【2】zoom:(number|undefined)可选项,设置地图的显示级数。【3】minZoom:(number|undefined)可选项,设置地图最小缩放级别
它与maxZoom(或minResolution)和zoomFactor一起使用
如果同时给出maxResolution,maxResolution优先级高于minZoom。
默认值为0。【4】maxZoom:(number|undefined)可选项,设置地图最大缩放级别
它与minZoom(或maxResolution)和zoomFactor一起使用
如果同时给出minResolution,minResolution优先级高于maxZoom。
默认值为28。【5】rotation:(number|undefined)可选项,设置初始视图的旋转弧度(顺时针方向)。
默认值为0。【6】projection:(ol.ProjectionLike)可选项,地图的投影坐标系。
默认为EPSG:3857,即墨卡托坐标系。

7.2 方法说明:

setCenter(center):设置地图视图的中心坐标。
center:(ol.Coordinate | undefined)地图视图的中心坐标。setZoom(zoom):设置地图视图的缩放级别。
zoom:(number)地图视图的缩放级别。

8、ol.control.MousePosition类:该类是控制显示鼠标光标的坐标

		//实例化鼠标位置控件(MousePosition)var mousePositionControl = new ol.control.MousePosition({
    //坐标格式coordinateFormat: ol.coordinate.createStringXY(4),//地图投影坐标系(若未设置则输出为默认投影坐标系下的坐标)//projection: 'EPSG:4326',//坐标信息显示样式类名,默认是'ol-mouse-position'className: 'custom-mouse-position',//显示鼠标位置信息的目标容器target: document.getElementById('mouse-position'),//未定义坐标的标记undefinedHTML: ' '});

8.1 构造函数:ol.control.MousePosition(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】coordinateFormat:(ol.CoordinateFormatType|undefined)可选项,设置坐标格式。【2】projection:(ol.ProjectionLike)可选项,设置投影信息。
默认是地图本身投影。【3】className:(string|undefined)可选项,设置坐标信息样式类名。
默认为ol-mouse-position。【4】target:(Element|undefined)可选项,设置显示鼠标位置信息的目标容器。例如代码中:document.getElementById('mouse-position')。【5】undefinedHTML:(string|undefined)可选项,标记未定义坐标。
默认为空字符串。

9、ol.control.ScaleLine类:比例尺控件,显示地图当前视图的比例尺。

当地图无投影信息时,比例尺无法显示。默认左下角显示。

		 //实例化比例尺控件(ScaleLine)var scaleLineControl = new ol.control.ScaleLine({
    //设置比例尺单位,degrees、imperial、us、nautical、metric(度量单位)units: "metric"});

9.1 构造函数:ol.control.MousePosition(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】units:(ol.control.ScaleLine.Units|string | undefined)可选项,设置比例尺单位。
例如代码中:metric。默认为metric。【2】className:(string | undefined])可选项,设置比例尺样式类名。
默认为ol-scale-line。【3】minWidth:(number | undefined类型)可选项,设置比例尺的最小宽度(以像素为单位)。
默认为64

10 、ol.control.OverviewMap类:鹰眼控件

		//实例化鹰眼控件(OverviewMap),最简单的默认样式鹰眼控件// var overviewMapControl = new ol.control.OverviewMap();//实例化鹰眼控件(OverviewMap),自定义样式的鹰眼控件var overviewMapControl = new ol.control.OverviewMap({
    //鹰眼控件样式(see in overviewmap-custom.html to see the custom CSS used)className: 'ol-overviewmap ol-custom-overviewmap',//鹰眼中加载同坐标系下不同数据源的图层layers: [TiandiMap_vec],//鹰眼控件展开时功能按钮上的标识(网页的JS的字符编码)collapseLabel: '\u00BB',//鹰眼控件折叠时功能按钮上的标识(网页的JS的字符编码)label: '\u00AB',//初始为展开显示方式collapsed: false});

10.1 构造函数:ol.control.OverviewMap(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】className:(string | undefined)可选项,设置鹰眼控件样式类名。
例如代码中:ol-overviewmap ol-custom-overviewmap。【2】layers:(Array.[ol.layer.layer] | ol.Collection.[ol.layer.layer] | undefined])可选项
设置鹰眼控件针对的图层。
默认情况下为所有图层。【3】collapseLabel:(string | Node | undefined)可选项
设置鹰眼控件展开时功能按钮上的标识(网页的JS的字符编码)。【4】label:(number|undefined类型)可选项,设置鹰眼控件收缩为图标按钮时
按钮上的标识(网页的JS的字符编码)。【5】collapseLabel:(number | undefined)可选项,设置鹰眼控件初始显示方式。
默认为true,即不显示。【6】collapsed:(boolean | undefined)可选项,设置鹰眼控件是否可进行收缩
。默认为true,即可收缩。

11、ol.source.BingMaps类:必应地图的瓦片资源。

11.1 构造函数:ol.source.BingMaps(options)

参数说明:
options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。【1】key:(string类型)必选项。必应瓦片地图API密钥。【2】imagerySet:(string类型)必选项。设置必应瓦片地图类型。 
例如:"Road","Aerial","AerialWithLabels", "collinsBart", "ordnanceSurvey"。
详细介绍如下:"Road":卫星拍摄道路影像。"Aerial":航拍影像。"AerialWithLabels":道路覆盖航拍影像。

12、ol.layer.Vector类:用于显示在客户端渲染的矢量数据。

12.1 构造函数:ol.layer.Vector(opt_options)

参数说明:
opt_options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。【1】source:(string)必选项,设置矢量图层数据来源。【2】style:(ol.style.Style | Array-[ol.style.style] | ol.StyleFunction | undefined)图层样式
一个ol.style.Style或者一个ol.style.Style数组,或者一个返回 ol.style.Style 的函数。

13、ol.source.Vector类:矢量要素来源。

13.1 构造函数:ol.source.Vector(opt_options)

参数说明:
opt_options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。【1】url:(string | ol.FeatureUrlFunction | undefined)可选项,矢量图层数据的url。【2】format:(ol.format.Feature | undefined)可选项,url属性设置后,XHR方式加载要素使用的数据格式。默认是未定义的。注意:如果设置了url,format一定要设置,否则可以忽略。【3】attribution:(ol.AttributionLike | undefined)可选项,地图右下角的 logo 包含的内容。【4】features:(Array-[ol.feature] | ol.Collection-[ol.feature] | undefined)可选项
地理要素,从字符串读取的数据。【5】loader:(ol.FeatureLoader | undefined)可选项,加载要素使用的加载函数。【6】logo:(string | olx.LogoOptions | undefined)可选项,logo包含的内容。【7】strategy:(ol.LoadingStrategy | undefined)可选项,加载要素使用的策略。
默认是一次性加载所有要素。【8】wrapX:(boolean | undefined)可选项,是否在地图水平坐标轴上重复。
默认是 true

14、ol.format.GeoJSON类:操作GeoJSON数据,包括各种读写方法。

14.1 构造函数:ol.format.GeoJSON(opt_options)

参数说明:
opt_options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。【1】defaultDataProjection:(ol.ProjectionLike)可选项,数据默认坐标系。
默认是EPSG:4326,即为地理坐标系。【2】featureProjection:(ol.ProjectionLike)可选项,通过format解析的要素坐标系。【3】geometryName:(string | undefined)可选项,创建要素时几何要素名。

15、ol.format.KML类:操作KML数据,包括各种读写方法。

15.1 构造函数:ol.format.KML(opt_options)

参数说明:
opt_options:(object类型)可选项,设置该图层的配置选项,以键值对的形式设置。【1】extractStyles:(boolean | undefined)可选项,是否提取KML样式。
默认是true。【2】showPointNames:(boolean | undefined)可选项,是否显示地点标记名称。
默认是true。【3】defaultStyle:(Array-[l.style.style] | undefined)可选项,默认样式。
默认缺省样式为Google Earth。【4】writeStyles:(boolean | undefined)可选项,是否给KML写入样式 。
默认是true

16、ol.proj类:坐标系统定义和转换类

		var py = ol.proj.fromLonLat([pntX, pntY]);//平移地图view.setCenter(py);view.setZoom(6);

16.1方法说明:

ol.proj.fromLonLat(coordinate, opt_projection):将地理坐标转化为其他坐标。coordinate:(ol.Coordinate)必选项,地理坐标,即用经度和纬度组成的二维数组。
例如代码中:[-109, 46.5]aopt_projection:(ol.ProjectionLik)可选项,设置目的坐标系。
默认为墨卡托投影,即EPSG:3857。ol.proj.get(projectionLike):获取坐标系信息。
projectionLike:(ol.ProjectionLike)必选项,坐标系。例如代码中:EPSG:3857,即墨卡托坐标系。

17、ol.Feature类:该类是设置一个矢量要素的几何属性和其他属性。

	 //创建一个点var point = new ol.Feature({
    geometry: new ol.geom.Point([11505912.0, 4011415.0])});//设置点1的样式信息point.setStyle(new ol.style.Style({
    //填充色fill: new ol.style.Fill({
    color: 'rgba(255, 255, 255, 0.2)'}),//边线颜色stroke: new ol.style.Stroke({
    color: '#ffcc33',width: 2}),//形状image: new ol.style.Circle({
    radius: 17,fill: new ol.style.Fill({
    color: '#ffcc33'})})}));//实例化一个矢量图层Vector作为绘制层var source = new ol.source.Vector({
    features: [point]});//创建一个图层var vector = new ol.layer.Vector({
    source: source});//将绘制层添加到地图容器中map.addLayer(vector);

17.1 构造函数:ol.Feature(opt_geometryOrProperties)

参数说明:
opt_geometryOrProperties:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】geometry:(ol.geom.Geometry)可选项,指定默认几何特性。

17.2方法说明:

setStyle(style):该方法设置要素的类型。
style:(ol.style.Style|Array[ol.style.style]|ol.FeatureStyleFunction类型)要素样式

18、ol.geom.Point类:该类是设置点矢量特性的呈现风格。

new ol.geom.Point([11505912.0, 4011415.0])

18.1 构造函数:ol.geom.Point(coordinates, opt_layout)

参数说明:
coordinates:(ol.Coordinate类型)可选项,设置坐标。
opt_layout:(ol.geom.GeometryLayout类型)可选项,设置布局。

19、ol.style.Style类:控制地图样式,其包含了地图样式的方方面面

例如,填充色、图标样式、图片样式、规则图形样式、边界样式、文字样式等,样式一般针对矢量要素图层。矢量图层样式可以事先写好,写成静态的,矢量图层直接按照定义好的样式渲染,也可以动态使用样式的 set() 方法,但是要注意刷新矢量图层,重新渲染,否则动态样式不生效。

 //设置点1的样式信息point.setStyle(new ol.style.Style({
    //填充色fill: new ol.style.Fill({
    color: 'rgba(255, 255, 255, 0.2)'}),//边线颜色stroke: new ol.style.Stroke({
    color: '#ffcc33',width: 2}),//形状image: new ol.style.Circle({
    radius: 17,fill: new ol.style.Fill({
    color: '#ffcc33'})})

19.1 构造函数:ol.style.Style(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】geometry:(string|ol.geom.Geometry|ol.StyleGeometryFunction)可选项
设置要素的属性或者要素或者一个返回地理要素的函数,用来渲染成相应的地理要素。【2】fill:(ol.style.Fill|undefined)可选项,设置矢量要素的填充样式。【3】stroke:(ol.style.Stroke|undefined)可选项,设置矢量要素的边界样式。【4】image:(ol.style.Image|undefined)可选项,设置矢量要素的图片样式。【5】text:(ol.style.Text|undefined)可选项,设置矢量要素的文字样式。【6】zIndex:(number|undefined)可选项,CSS中的zIndex,即叠置的层次,为数字类型。

20、ol.style.Fill类:该类是设置矢量要素的填充类型。

fill: new ol.style.Fill({
    color: 'rgba(255, 255, 255, 0.2)'}),

20.1 构造函数:ol.style.Fill(opt_options)

参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
【1】color:(ol.Color|ol.ColorLike类型)可选项,设置要素的填充颜色和透明度。
格式为 [R, G, B, A],分别代表 RGB 的三个分量,A 代表 alpha
即透明度([0, 1] 区间内的值[透明—不透明])。

21、ol.style.Stroke类:该类是设置矢量要素的边界样式。

21.1 构造函数:ol.style.Stroke(opt_options)

stroke: new ol.style.Stroke({
    color: '#ffcc33',width: 2}),
参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】color:(ol.Color|ol.ColorLike类型)可选项,设置要素边界的颜色。
默认值是null,如果为空,画布渲染器将使用默认的黑色。【2】lineCap:(string|undefined类型)可选项,设置要素边界线端点样式。
默认值是round(圆形)(可能取值butt(截头), round(圆形)或者square(正方形))【3】lineDash:(Array[number]类型)可选项,设置要素虚线样式。
默认值是undefined,即是实线。值越大,虚线越稀疏;值越小,虚线越密集。注意:IE10及以下版本不支持此功能。【4】lineJoin:(string|undefined类型)可选项,设置边界线连接方式。
默认值是round(环形)(可能取值bevel(斜角), round(环形)或者miter(斜接))【5】miterLimit:(number|undefined类型)可选项,设置要素的斜接限制。
默认值是10【6】width:(number|undefined类型)可选项,设置要素边界宽度。

22、ol.style.Image类:该类是设置矢量要素的图片样式(包含的子类有ol.style.Circle、ol.style.Icon、ol.style.RegularShape)。

 //形状image: new ol.style.Circle({
    radius: 17,fill: new ol.style.Fill({
    color: '#ffcc33'})})

22.1 构造函数:ol.style.Image(options)

参数说明:
options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】opacity:(number类型)可选项,设置透明度(取值范围0-1完全透明/完全不透明)。【2】rotateWithView:(boolean类型)可选项,设置是否旋转图片。【3】rotation:(number类型)可选项,设置旋转的角度。【4】scale:(number类型)可选项,设置比例尺。【5】snapToPixel:(boolean类型)可选项,设置单个像素是否被拍。

23、ol.style.Text类:该类是设置矢量要素的文字样式。

23.1 构造函数:ol.style.Text(opt_options)
参数说明:
opt_options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。【1】font:(string|undefined类型)可选项,设置CSS字体样式。
默认是10px,详情请参见:
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font【2】offsetX:(number|undefined类型)可选项,设置水平文本的值。
默认是0,用以抵消以像素为单位的值。【3】offsetY:(number|undefined类型)可选项,设置垂直文本的值。
默认是0,用以抵消以像素为单位的值。【4】scale:(number|undefined类型)可选项,设置比例尺。【5】rotateWithView:(boolean|undefined类型)可选项,设置是否旋转视图的文本。
默认是false【6】rotation:(number|undefined类型)可选项,设置旋转的弧度(正旋转顺时针)
默认值是0【7】text:(string|undefined类型)可选项,设置文本的内容。【8】textAlign:(string|undefined类型)可选项,设置文本对齐的模式。
默认值是'start'(可能取值: 'left', 'right', 'center', 'end' or 'start')【9】textBaseline:(string|undefined类型)可选项,设置文本基线。
默认值是'alphabetic'(可能取值:'bottom', 'top', 'middle', 'alphabetic', 'hanging', 'ideographic')【10】fill:(ol.style.Fill|undefined类型)可选项,设置填充风格。
如果没有提供,默认的是#333【11】stroke:(ol.style.Stroke|undefined类型)可选项,设置文本边线类型。

24、ol.geom.LineString类:该类是设置线矢量特性的呈现风格。

	 //创建一个线var Line = new ol.Feature({
    geometry: new ol.geom.LineString([[8208725.0, 3835304.0], [16055444.0, 4578883.0]])});

24.1 构造函数:ol.geom.LineString类(coordinates, opt_layout)

参数说明:
coordinates:(Array[ol.Coordinate]类型)可选项,设置坐标。
opt_layout:(ol.geom.GeometryLayout类型)可选项,设置布局。

25、ol.geom.Circle类:该类是设置圆矢量特性的呈现风格。

 //创建一个圆var Circle = new ol.Feature({
    geometry: new ol.geom.Circle([9871995.0, 4344069.0], 1000000)});

25.1 构造函数:ol.geom.Circle类(center, opt_radius, opt_layout)

参数说明:
center:(ol.Coordinate类型)可选项,设置中心。
opt_radius:(Array[ol.Coordinate]类型)可选项,设置半径。
opt_layout:(ol.geom.GeometryLayout类型)可选项,设置布局。

26、ol.geom.Polygon类:该类是设置一个多边形几何体类。

//创建一个圆
var Circle = new ol.geom.Circle([9871995.0, 4344069.0], 1000000);//根据圆获取多边形
var Square = new ol.Feature({
    geometry: new ol.geom.Polygon.fromCircle(Circle, 4, 150)
});//根据范围获取多边形
var Rectangle = new ol.Feature({
    geometry: new ol.geom.Polygon.fromExtent([8208725.0, 2035304.0, 12841418.0, 4068487.0])
});

26.1 构造函数:ol.geom.Polygon(coordinates, opt_layout)

参数说明:
coordinates:(Array类型-[ol.Coordinate])可选项,定义多边形的坐标。
opt_layout:(ol.geom.GeometryLayout类型)可选项,设置布局。

26.2 方法说明:


fromCircle(circle, opt_sides, opt_angle):该方法通过圆矢量特性创建一个多边形矢量特性的呈现风格。
该方法的返回值是一个Polygon的几何类型circle:(ol.geom.Circle类型)可选项,定义一个圆矢量特性。opt_sides:(number类型)可选项,设置多边形的边数。
默认值是32。正方形的边数为4。opt_angle:(number类型)可选项,设置第一个顶点的多边形角弧度。
默认值为0fromExtent(extent):该方法创建一个多边形矢量特性的呈现风格(使用XY的布局)。
该方法的返回值是一个Polygon的几何类型
extent:(ol.Extent类型)可选项,定义多边形的范围。

27、ol.interaction.Draw类:该类是实例化地图交互绘制类对象。

27.1 构造函数:ol.interaction.Draw(options)

参数说明:
options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
【1】source:(ol.source.Vector|undefined类型)可选项,指定目标源的特性。【2】type:(ol.geom.GeometryType类型)可选项,指定绘图类型
(例如:'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon' , 'Circle')。【3】geometryFunction:(ol.DrawGeometryFunctionType|undefined类型)可选项,指定几何信息变更时调用函数。【4】maxPoints:(number|undefined类型)可选项,表示绘制单个要素(面和线)最多的点数限制。
默认没有限制。【5】minPoints:(number|undefined类型)可选项,表示绘制单个要素(面和线)需要的最少点数。
面默认为 3,线默认为 2【6】freehand:(boolean|undefined类型)可选项,表示拖拽鼠标就可以绘制图形的模式。
默认是false

27.2 方法说明:

createRegularPolygon(opt_sides, opt_angle):
该函数返回一个基于 Circle 绘制类型的 geometryFunction 函数(这种函数返回一个 geometry 对象)
接受两个参数,分别是边的数量(opt_sides)和 多边形的角度(opt_angle)
opt_sides:(ol.Extent类型)可选项,定义多边形的边数。
默认值为32。
opt_angle:(ol.Extent类型)可选项,定义多边形的角度。

27.3 绘制矩形说明:

给draw 增加 geometryFunction 参数和 maxPoints 参数。
原理就是捕捉鼠标点击的点,然后获取限制的两个点的坐标,用来初始化一个矩形框。function (coordinates, geometry)该方法是重写draw.js脚本中的geometryFunction方法
coordinates:(ol.Extent类型)可选项,定义多边形的边数。
默认值为32。
geometry:(ol.Extent类型)可选项,定义多边形的角度。

28、ol.proj.fromLonLat(地理坐标,投影坐标):将地理坐标转化为投影坐标

  • (coordinate,projection)

将坐标从经度/纬度转换为其他投影。

名称 类型 描述
coordinate 模组:ol / coordinate?Coordinate 坐标为经度和纬度,即经度为1且纬度为2nd的数组。
projection 模块:ol / proj?ProjectionLike 目标投影。默认值为Web Mercator,即“ EPSG:3857”。

返回值: 坐标投影到目标投影。

29、ol.animation.rotate类:

  • 已经弃用(建议使用ol.View的animate方法来代替)。
  • 该类是实现一个更新视图实现旋转功能的动画过渡效果。

29.1 构造函数:ol.animation.rotate(options)

  • 参数说明:
    • options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
      • 【1】rotation:(number|undefined类型)可选项,设置旋转值(弧度),通常用map.getView().getRotation()设置。
        如果没有定义,那么0。
      • 【2】anchor:(ol.Coordinate|undefined类型)可选项,设置旋转中心/锚。
        如果未指定的,视图的映射围绕中心旋转。
      • 【3】start:(number|undefined类型)可选项,设置动画的开始时间
        默认值是immediately(立即)。
      • 【4】duration:(number|undefined类型)可选项,设置动画的持续时间,以毫秒为单位。
        默认值是1000。
      • 【5】easing:(undefined|function类型)可选项,设置easing方法。可以使用ol.easing或一个自定义函数。
        默认是ol.easing.inAndOut。

30、ol.animation.pan类:

  • 已经弃用(建议使用ol.View的animate方法来代替)。
  • 该类是实现一个更新视图实现移动功能的动画过渡效果。

30.1 构造函数:ol.animation.pan(options)

  • 参数说明:
    • options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
      • 【1】source:(ol.Coordinate类型)必选项设置开始平移的位置,通常map.getView().getCenter()。
      • 【2】start:(number|undefined类型)可选项,设置动画的开始时间。
        默认值是immediately(立即)。
      • 【3】duration:(number|undefined类型)可选项,设置动画的持续时间,以毫秒为单位。
        默认值是1000。
      • 【4】easing:(undefined|function类型)可选项,设置easing方法。可以使用ol.easing或一个自定义函数。
        默认是ol.easing.inAndOut。

31、ol.animation.bounce类:

  • 已经弃用(建议使用ol.View的animate方法来代替)。
  • 该类是实现一个更新视图实现反弹功能的动画过渡效果。

31.1 构造函数:ol.animation.bounce(options)

  • 参数说明:
    • options:(Object类型)可选项,设置该对象其他属性,以键值对的形式设置。
      • 【1】rotation:(number|undefined类型)必选项,设置旋转值(弧度),通常map.getView().getRotation()。
        如果没有定义,那么0。
      • 【2】start:(number|undefined类型)可选项,设置动画的开始时间。
        默认值是immediately(立即)。
      • 【3】duration:(number|undefined类型)可选项,设置动画的持续时间,以毫秒为单位。
        默认值是1000。
      • 【4】easing:(undefined|function类型)可选项,设置easing方法。可以使用ol.easing或一个自定义函数。
        默认是ol.easing.inAndOut

32、ol.proj.transform (坐标,源,目标)

将坐标从源投影转换为目标投影。这将返回一个新坐标(并且不会修改原始坐标)。

名称 类型 描述
coordinate 模组:ol / coordinate?Coordinate 坐标。
source 模块:ol / proj?ProjectionLike 源投影状。
destination 模块:ol / proj?ProjectionLike 类似于目的地投影。

ol.proj.transform(coordinate, source, destination):
转换投影坐标系(返回一个新的投影坐标,但是不改变原始坐标)。

  • coordinate:(ol.Coordinate)必选项,地理坐标,即用经度和纬度组成的二维数组。
  • source:(ol.ProjectionLike)必选项,源投影坐标系
  • destination:(ol.ProjectionLike)必选项,目的投影坐标系