[关闭]
@salen 2018-08-08T08:07:43.000000Z 字数 4478 阅读 447

智能轮挡项目所用 openlayer api 说明

未分类


安装依赖

  1. npm install ol -S
  2. cnpm innstall ol -S
  3. // 所用版本 v4.6.5

ol/map

  1. import Map from 'ol/map'
  2. 地图类
  3. this.map = new Map({
  4. target: "map", // id选择器
  5. layers: [ // 图层数组,来自ol/layer下的实例
  6. this.cycleOsmLayer,
  7. this.routeLayer
  8. ],
  9. view: this.view, // 视图
  10. })
  11. // methods
  12. this.map.setCenter(center) // 设置地图中心点
  13. this.map.addLayer(this.defaultOsmLayer) // 添加图层
  14. this.map.removeLayer(this.defaultOsmLayer) // 移除图层
  15. this.map.addControl(this.scaleLineControl) // 添加控件
  16. this.map.getControls() // 获取所有控件
  17. this.map.removeControl(control) // 移除控件
  18. this.map.addOverlay(sparklePoint) // 添加覆盖物
  19. this.map.getOverlayById(id) // 通过id获取覆盖物
  20. this.map.removeOverlay(sparklePoint) // 移除覆盖物
  21. this.map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
  22. }, {hitTolerance: 2}) // 循环指定位置的图形与图层,一般配合事件使用,hitTolerance 点击偏差覆盖范围
  23. // events
  24. this.map.on("click", function(evt){})

http://openlayers.org/en/v4.6.5/apidoc/ol.Map.html

ol/view

  1. import View from "ol/view"
  2. 视图类
  3. this.view = new View({
  4. center: this.center, // 地图中心点
  5. zoom: this.zoom, // 初始缩放比例
  6. maxZoom: 21, // 最大缩放
  7. minZoom: 4, // 最小缩放
  8. // projection: "EPSG:4326", // 地图坐标类型
  9. })
  10. // methods
  11. this.view.setZoom(this.nowZoom) // 设置视图缩放
  12. this.view.getZoom() // 获取当前视图缩放
  13. this.view.animate({
  14. center: [108.7610005,34.4365652],
  15. zoom: 18,
  16. duration: 2000,
  17. }) // 移动视图
  18. // events
  19. this.view.on("change:resolution", evt => {}) // 缩放视图事件

http://openlayers.org/en/v4.6.5/apidoc/ol.View.html

ol/layer/tile

  1. import Tile from "ol/layer/tile"
  2. 瓦片图层类
  3. this.defaultOsmLayer = new Tile({
  4. source: new OSM(), // 远程瓦片地图
  5. zIndex: 0, // 图层层级
  6. })

http://openlayers.org/en/v4.6.5/apidoc/ol.layer.Tile.html

ol/source/osm

  1. import OSM from "ol/source/osm"
  2. 公共路网图类
  3. new OSM({url: 'https://{a-c}.tile.thunderforest.com/transport/{z}/{x}/{y}@2x.png?apikey=6170aad10dfd42a38d4d8c709a536f38'})

http://openlayers.org/en/v4.6.5/apidoc/ol.source.OSM.html

ol/source/xyz

  1. import XYZ from "ol/source/xyz"
  2. XYZ图类
  3. let gaodeSatelMapLayer = new Tile({
  4. source: new XYZ({
  5. url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&sty le=6&x={x}&y={y}&z={z}",
  6. }),
  7. })

http://openlayers.org/en/v4.6.5/apidoc/ol.source.XYZ.html

ol/layer/vector

  1. import LVector from 'ol/layer/vector'
  2. 自定义矢量图层类
  3. this.pointLayer = new LVector({
  4. source: this.pointSource,
  5. zIndex: 8,
  6. })

http://openlayers.org/en/v4.6.5/apidoc/ol.layer.Vector.html

ol/source/vector

  1. import SVector from 'ol/source/vector'
  2. 自定义矢量资源类
  3. this.pointSource = new SVector({
  4. features: this.pointMarkers
  5. })
  6. // methods
  7. this.pointSource.clear() // 清空资源内的图形
  8. this.pointSource.addFeatures(this.pointMarkers) // 添加图形到资源

http://openlayers.org/en/v4.6.5/apidoc/ol.source.Vector.html

ol/feature

  1. import Feature from 'ol/feature'
  2. 自定义图形类
  3. new Feature({
  4. id: pointItem.id,
  5. status: pointItem.status,
  6. latLng: pointItem.latLng,
  7. apronNo: pointItem.apronNo,
  8. modelNo: pointItem.modelNo,
  9. name: 'aircraft_point',
  10. info: pointItem.info,
  11. geometry: new Point(pointItem.latLng)
  12. })
  13. // methods
  14. item.setStyle(new Style({
  15. image: this.pinIcon(item.values_.status),
  16. text: new Text({
  17. font: 'bold 10px "Open Sans", "Arial Unicode MS", "sans-serif"',
  18. fill: new Fill({
  19. color: '#666'
  20. }),
  21. text: item.values_.info,
  22. offsetY: -25,
  23. })
  24. })) // 设置图形样式

http://openlayers.org/en/v4.6.5/apidoc/ol.Feature.html

ol/style/style

  1. import Style from 'ol/style/style'
  2. 样式类

http://openlayers.org/en/v4.6.5/apidoc/ol.style.Style.html

ol/style/text

  1. import Text from 'ol/style/text'
  2. 文字样式类

http://openlayers.org/en/v4.6.5/apidoc/ol.style.Text.html

ol/style/fill

  1. import Fill from 'ol/style/fill'
  2. 填充样式类

http://openlayers.org/en/v4.6.5/apidoc/ol.style.Fill.html

ol/style/stroke

  1. import Stroke from 'ol/style/stroke'
  2. 描边类

http://openlayers.org/en/v4.6.5/apidoc/ol.style.Stroke.html

ol/style/icon

  1. import Icon from "ol/style/icon"
  2. 图标样式类
  3. new Icon({
  4. crossOrigin: "anonymous",
  5. src: src, // 图片地址
  6. rotation: rotation, // 旋转角度
  7. scale: scale, // 缩放比例
  8. anchor: anchor, // 锚点
  9. })

http://openlayers.org/en/v4.6.5/apidoc/ol.style.Icon.html

ol/geom/point

  1. import Point from 'ol/geom/point'
  2. 点类
  3. new Point(pointItem.latLng)

http://openlayers.org/en/v4.6.5/apidoc/ol.geom.Point.html

ol/geom/linestring

  1. import LineString from 'ol/geom/linestring'
  2. 线类
  3. new LineString([0,0])
  4. // methods
  5. this.gpsRouteLine.setCoordinates(path)

http://openlayers.org/en/v4.6.5/apidoc/ol.geom.LineString.html

ol/geom/polygon

  1. import Polygon from 'ol/geom/polygon'
  2. 多边形类
  3. new Polygon([railArr])

http://openlayers.org/en/v4.6.5/apidoc/ol.geom.Polygon.html

ol/proj

  1. import proj from 'ol/proj'
  2. 工具类
  3. proj.fromLonLat(coordinate, opt_projection) // 将EPSG:4326坐标转为EPSG:3857坐标
  4. proj.transform(info.latLng, 'EPSG:3857', 'EPSG:4326') // 将EPSG:3857坐标转为EPSG:4326坐标

http://openlayers.org/en/v4.6.5/apidoc/ol.proj.html

ol/overlay

  1. import Overlay from 'ol/overlay'
  2. 覆盖物类
  3. var point_div = document.createElement('div')
  4. point_div.className="css_animation"
  5. var point_overlay = new Overlay({
  6. id: id, // 覆盖物id
  7. position: coordinate, // 坐标位置
  8. element: point_div, // 覆盖物元素
  9. positioning: 'center-center', // 覆盖物锚点
  10. stopEvent: false, // 是否阻止事件传递
  11. })
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注