@salen
2018-08-08T08:07:43.000000Z
字数 4478
阅读 490
未分类
npm install ol -S 或cnpm innstall ol -S// 所用版本 v4.6.5
import Map from 'ol/map'地图类this.map = new Map({target: "map", // id选择器layers: [ // 图层数组,来自ol/layer下的实例this.cycleOsmLayer,this.routeLayer],view: this.view, // 视图})// methodsthis.map.setCenter(center) // 设置地图中心点this.map.addLayer(this.defaultOsmLayer) // 添加图层this.map.removeLayer(this.defaultOsmLayer) // 移除图层this.map.addControl(this.scaleLineControl) // 添加控件this.map.getControls() // 获取所有控件this.map.removeControl(control) // 移除控件this.map.addOverlay(sparklePoint) // 添加覆盖物this.map.getOverlayById(id) // 通过id获取覆盖物this.map.removeOverlay(sparklePoint) // 移除覆盖物this.map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {}, {hitTolerance: 2}) // 循环指定位置的图形与图层,一般配合事件使用,hitTolerance 点击偏差覆盖范围// eventsthis.map.on("click", function(evt){})
http://openlayers.org/en/v4.6.5/apidoc/ol.Map.html
import View from "ol/view"视图类this.view = new View({center: this.center, // 地图中心点zoom: this.zoom, // 初始缩放比例maxZoom: 21, // 最大缩放minZoom: 4, // 最小缩放// projection: "EPSG:4326", // 地图坐标类型})// methodsthis.view.setZoom(this.nowZoom) // 设置视图缩放this.view.getZoom() // 获取当前视图缩放this.view.animate({center: [108.7610005,34.4365652],zoom: 18,duration: 2000,}) // 移动视图// eventsthis.view.on("change:resolution", evt => {}) // 缩放视图事件
http://openlayers.org/en/v4.6.5/apidoc/ol.View.html
import Tile from "ol/layer/tile"瓦片图层类this.defaultOsmLayer = new Tile({source: new OSM(), // 远程瓦片地图zIndex: 0, // 图层层级})
http://openlayers.org/en/v4.6.5/apidoc/ol.layer.Tile.html
import OSM from "ol/source/osm"公共路网图类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
import XYZ from "ol/source/xyz"XYZ图类let gaodeSatelMapLayer = new Tile({source: new XYZ({url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&sty le=6&x={x}&y={y}&z={z}",}),})
http://openlayers.org/en/v4.6.5/apidoc/ol.source.XYZ.html
import LVector from 'ol/layer/vector'自定义矢量图层类this.pointLayer = new LVector({source: this.pointSource,zIndex: 8,})
http://openlayers.org/en/v4.6.5/apidoc/ol.layer.Vector.html
import SVector from 'ol/source/vector'自定义矢量资源类this.pointSource = new SVector({features: this.pointMarkers})// methodsthis.pointSource.clear() // 清空资源内的图形this.pointSource.addFeatures(this.pointMarkers) // 添加图形到资源
http://openlayers.org/en/v4.6.5/apidoc/ol.source.Vector.html
import Feature from 'ol/feature'自定义图形类new Feature({id: pointItem.id,status: pointItem.status,latLng: pointItem.latLng,apronNo: pointItem.apronNo,modelNo: pointItem.modelNo,name: 'aircraft_point',info: pointItem.info,geometry: new Point(pointItem.latLng)})// methodsitem.setStyle(new Style({image: this.pinIcon(item.values_.status),text: new Text({font: 'bold 10px "Open Sans", "Arial Unicode MS", "sans-serif"',fill: new Fill({color: '#666'}),text: item.values_.info,offsetY: -25,})})) // 设置图形样式
http://openlayers.org/en/v4.6.5/apidoc/ol.Feature.html
import Style from 'ol/style/style'样式类
http://openlayers.org/en/v4.6.5/apidoc/ol.style.Style.html
import Text from 'ol/style/text'文字样式类
http://openlayers.org/en/v4.6.5/apidoc/ol.style.Text.html
import Fill from 'ol/style/fill'填充样式类
http://openlayers.org/en/v4.6.5/apidoc/ol.style.Fill.html
import Stroke from 'ol/style/stroke'描边类
http://openlayers.org/en/v4.6.5/apidoc/ol.style.Stroke.html
import Icon from "ol/style/icon"图标样式类new Icon({crossOrigin: "anonymous",src: src, // 图片地址rotation: rotation, // 旋转角度scale: scale, // 缩放比例anchor: anchor, // 锚点})
http://openlayers.org/en/v4.6.5/apidoc/ol.style.Icon.html
import Point from 'ol/geom/point'点类new Point(pointItem.latLng)
http://openlayers.org/en/v4.6.5/apidoc/ol.geom.Point.html
import LineString from 'ol/geom/linestring'线类new LineString([0,0])// methodsthis.gpsRouteLine.setCoordinates(path)
http://openlayers.org/en/v4.6.5/apidoc/ol.geom.LineString.html
import Polygon from 'ol/geom/polygon'多边形类new Polygon([railArr])
http://openlayers.org/en/v4.6.5/apidoc/ol.geom.Polygon.html
import proj from 'ol/proj'工具类proj.fromLonLat(coordinate, opt_projection) // 将EPSG:4326坐标转为EPSG:3857坐标proj.transform(info.latLng, 'EPSG:3857', 'EPSG:4326') // 将EPSG:3857坐标转为EPSG:4326坐标
http://openlayers.org/en/v4.6.5/apidoc/ol.proj.html
import Overlay from 'ol/overlay'覆盖物类var point_div = document.createElement('div')point_div.className="css_animation"var point_overlay = new Overlay({id: id, // 覆盖物idposition: coordinate, // 坐标位置element: point_div, // 覆盖物元素positioning: 'center-center', // 覆盖物锚点stopEvent: false, // 是否阻止事件传递})