Skip to content

Commit

Permalink
vl-view: work with coordinates in provided projection
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Jan 5, 2018
1 parent ccfd394 commit 1e3ac15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
8 changes: 4 additions & 4 deletions docs/api/map/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
props: [
{
name: 'center',
description: `<p>The center coordinate of the map view in <strong>EPSG:4326</strong> projection.</p>`,
description: `<p>The center coordinate of the view in the view projection.</p>`,
type: 'number[]',
required: false,
sync: true,
Expand All @@ -29,7 +29,7 @@ export default {
},
{
name: 'extent',
description: `<p>The extent that constrains the center defined in in <b>EPSG:4326</b> projection,
description: `<p>The extent that constrains the center defined in the view projection,
in other words, center cannot be set outside this extent.</p>`,
type: 'array',
required: false,
Expand Down Expand Up @@ -149,7 +149,7 @@ export default {
{
name: 'animate',
description: `<p>
Animates the view. The view's <b>center</b> (coordinates in <b>EPSG:4326</b> projection),
Animates the view. The view's <b>center</b> (coordinates in the view projection),
<b>zoom</b> (or <b>resolution</b>), and <b>rotation</b> can be animated for smooth transitions between view states.
</p>
<p>
Expand Down Expand Up @@ -192,7 +192,7 @@ export default {
arguments: [
{
name: 'geometryOrExtent',
description: `<p>The geometry or extent to fit the view to. Coordinates should be in <b>EPSG:4326</b> projection.</p>`,
description: `<p>The geometry or extent to fit the view to. Coordinates should be in the view projection.</p>`,
optional: false,
type: 'GeoJSONFeature, ol.Extent',
},
Expand Down
35 changes: 14 additions & 21 deletions src/components/map/view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
import Vue from 'vue'
import View from 'ol/view'
import { isEqual, isPlainObject, noop, get } from 'lodash/fp'
import { isEqual, isPlainObject, noop, isFunction } from 'lodash/fp'
import { Observable } from 'rxjs/Observable'
import { merge as mergeObs } from 'rxjs/observable/merge'
import { distinctUntilKeyChanged } from 'rxjs/operator/distinctUntilKeyChanged'
Expand All @@ -20,7 +20,6 @@
MAX_ZOOM,
EPSG_3857,
ZOOM_FACTOR,
projHelper,
geoJsonHelper,
observableFromOlChangeEvent,
olCmp,
Expand All @@ -32,7 +31,7 @@
*/
const props = /** @lends module:map/view# */{
/**
* The center coordinate of the map view in **EPSG:4326** projection.
* The center coordinate of the view in the view projection.
* @type {number[]}
* @default [0, 0]
* @vueSync
Expand All @@ -51,7 +50,7 @@
default: true,
},
/**
* The extent that constrains the center defined in in **EPSG:4326** projection,
* The extent that constrains the center defined in the view projection,
* in other words, center cannot be set outside this extent.
* @default undefined
*/
Expand Down Expand Up @@ -158,13 +157,11 @@
animate (...args) {
assert.hasView(this)
let cb = args.reverse().find(x => typeof x === 'function') || noop
args.forEach(opts => {
let center = get('center', opts)
if (Array.isArray(center) && center.length) {
opts.center = projHelper.fromLonLat(center, this.projection)
}
})
let cb = noop
if (isFunction(args[args.length - 1])) {
cb = args[args.length - 1]
args = args.slice(0, args.length - 1)
}
return new Promise(
resolve => this.$view.animate(...args, complete => {
Expand All @@ -179,12 +176,10 @@
*/
createOlObject () {
return new View({
center: projHelper.fromLonLat(this.center, this.projection),
center: this.center,
constrainRotation: this.constrainRotation,
enableRotation: this.enableRotation,
extent: this.extent
? projHelper.extentFromLonLat(this.extent, this.projection)
: undefined,
extent: this.extent,
maxResolution: this.maxResolution,
minResolution: this.minResolution,
maxZoom: this.maxZoom,
Expand All @@ -206,13 +201,11 @@
fit (geometryOrExtent, options = {}) {
assert.hasView(this)
// transform to GeoJSON, vl-feature to ol.Feature
// transform from GeoJSON, vl-feature to ol.Feature
if (isPlainObject(geometryOrExtent)) {
geometryOrExtent = geoJsonHelper.readGeometry(geometryOrExtent, this.$view.getProjection())
geometryOrExtent = geoJsonHelper.readGeometry(geometryOrExtent, this.$view.getProjection(), this.projection)
} else if (geometryOrExtent instanceof Vue) {
geometryOrExtent = geometryOrExtent.$geometry
} else if (Array.isArray(geometryOrExtent)) {
geometryOrExtent = projHelper.extentFromLonLat(geometryOrExtent, this.$view.getProjection())
}
let cb = options.callback || noop
Expand Down Expand Up @@ -255,7 +248,7 @@
const watch = {
center (value) {
if (this.$view && !isEqual(value, this::getCenter())) {
this.$view.setCenter(projHelper.fromLonLat(value, this.$view.getProjection()))
this.$view.setCenter(value)
}
},
resolution (value) {
Expand Down Expand Up @@ -362,6 +355,6 @@
}
function getCenter () {
return projHelper.toLonLat(this.$view.getCenter(), this.$view.getProjection())
return this.$view.getCenter()
}
</script>
2 changes: 1 addition & 1 deletion test/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
data () {
return {
zoom: 13,
center: [-80.0307892780456, 43.456341754866685],
center: proj.transform([-80.0307892780456, 43.456341754866685], 'EPSG:4326', 'EPSG:3857'),
rotation: 0,
points: [],
pointsLayer: true,
Expand Down

0 comments on commit 1e3ac15

Please sign in to comment.