Skip to content

Commit

Permalink
Fix renderer property usage
Browse files Browse the repository at this point in the history
Update `renderer` option usage according to the new OpenLayers version:
re-create ol instance with Map or WebGLMap ctor.

#113
  • Loading branch information
ghettovoice committed Dec 23, 2018
1 parent 630fd49 commit ed9ed92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/component/map/map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import VectorLayer from 'ol/layer/Vector'
import Collection from 'ol/Collection'
import Map from 'ol/Map'
import WebGLMap from 'ol/WebGLMap'
import VectorSource from 'ol/source/Vector'
import View from 'ol/View'
import { merge as mergeObs } from 'rxjs/observable'
Expand Down Expand Up @@ -83,8 +84,9 @@
* @default ['canvas', 'webgl']
*/
renderer: {
type: [String, Array],
default: () => [RENDERER_TYPE.CANVAS, RENDERER_TYPE.WEBGL],
type: String,
default: RENDERER_TYPE.CANVAS,
validator: value => Object.values(RENDERER_TYPE).includes(value),
},
/**
* Root element `tabindex` attribute value. Value should be provided to allow keyboard events on map.
Expand All @@ -103,6 +105,15 @@
}
const computed = {
mapCtor () {
switch (this.renderer) {
case RENDERER_TYPE.WEBGL:
return WebGLMap
case RENDERER_TYPE.CANVAS:
default:
return Map
}
},
}
const methods = {
Expand All @@ -111,7 +122,8 @@
* @protected
*/
createOlObject () {
const map = new Map({
/* eslint-disable-next-line new-cap */
const map = new this.mapCtor({
loadTilesWhileAnimating: this.loadTilesWhileAnimating,
loadTilesWhileInteracting: this.loadTilesWhileInteracting,
pixelRatio: this.pixelRatio,
Expand All @@ -124,9 +136,8 @@
view: this._view,
})
map.set('dataProjection', this.dataProjection)
this._defaultOverlay.setMap(map)
console.log(map)
return map
},
/**
Expand Down Expand Up @@ -345,6 +356,7 @@
'loadTilesWhileInteracting',
'moveTolerance',
'pixelRatio',
'renderer',
], () => olCmp.methods.scheduleRecreate),
controls (value) {
if (value === false) {
Expand Down
2 changes: 1 addition & 1 deletion test/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>

<vl-map data-projection="EPSG:4326" ref="map" v-if="showMap">
<vl-map ref="map" v-if="showMap" data-projection="EPSG:4326" renderer="webgl">
<vl-view :center.sync="center" :rotation.sync="rotation" :zoom.sync="zoom" ident="view" ref="view" />

<vl-graticule :show-labels="true" v-if="graticule">
Expand Down

0 comments on commit ed9ed92

Please sign in to comment.