Closed aliciahogue closed 3 years ago
Perhaps related to above issue... drawing circles on the map are getting messed up... The initial value from the event json seems correct but once it is synced down its all messed up and disappears from the map ( due to coords being mutated in projection handling ) Oddly enough, if I set the projection on the source to 3857 via the prop then the circles are visible but polygons are not.
Hello @aliciahogue , I definitely can reproduce coordinates mess with circles. But with other geometries I don't see any problems.
Let me fix circles related issue and I will make a demo to clarify issue.
Thanks for report!
Take a look to this https://codesandbox.io/s/vuelayers-v012x-yfhnp?file=/src/main.js This demo uses circle proj patch. Feel free to fork it and reproduce your issue with polygon coordinates.
Projections in VueLayers:
vl-view
has projection
property. In this projection map view will be rendered, this projection is used in underlying ol/View
instance. And this projection will be in all other components in resolvedViewProjection
field. All instances of ol/Feature
, ol/geom/*
objects will use this projection.
dataProjection
default projection for all GeoJSON encoded data (features, geometries, coordinates). But it can be overwritten by the components with projection
property (vl-source-*, vl-geoloc).
So resolvedDataProjection
resolves like: projection prop || global data projection || self defined default data projection || resolved view projection
.
Vector sources use EPSG:4326
projection by default -> they get resolvedDataProjection = EPSG:4326
. So to add/remove GeoJSON features through vl-source-vector
methods or properties this resolved data projection should be used.
Tile/Image sources use EPSG:3857
projection by default -> they get resolvedDataProjection = EPSG:3857
.
Thank you!! I will see if I can reproduce. I believe the issue was caused because I was using EPSG:3857 for both view and data projection because most of my data comes from geoserver so I pass the projection in the request and would just reproject to/from 4326 for the few other sections that used database storage directly. I have already begun moving to using 4326 by default but will fork and reproduce the issue I had for you either way!
Ok, I see what the problem was/is now.. Since I was declaring the data projection as 3857, prior to upgrading to to RC10 things worked as I expected them too when adding to synced features array or when calling source.addFeatures ( without the "true" param )
Here is my issue reproduced. Not such a big deal now that I know the difference and have already started moving things to be in 4326 by default as the data is stored that way anyways... but logically speaking, if we pass a value other then 4326 for default data projection, I would think that things should work out of the box when passing data via addFeatures or syncing from the featues array but probably not a common use case and likely a lot more work for you so I am happy to adjust accordingly lol. I appreciate all the work you do!!
https://codesandbox.io/s/vuelayers-v012x-forked-rcs9t?file=/src/App.vue
Now I got it.
After RC5 I add EPSG:4326
as default value for projection
prop of vl-source-vector
(there was another issue with using different projections on vector sources inside one map). This is my mistake, because it now always redefines global data projection.
I will make a patch.
Then if all your vector layers will be in EPSG:4326
you need to define global dataProjection
:
Vue.use(VueLayers, { dataProjection: 'EPSG:4326' })
// or
<vl-map data-projection="EPSG:4326">...</vl-map>
or only for some sources (global data projection EPSG:3857
):
// switch data projection only for this source
<vl-source-vector projection="EPSG:4326" />
// now this.$refs.source.addFeatures() and 'features' prop will use EPSG:4326 for GeoJSON encode/decode
Sooo... up until now, I was only providing a data projection on the map component as 3857.. After updating to rc10 though a lot of my layers were showing empty... digging into things, it seems that when calling source.addFeatures(features) from the vuelayers component I need to pass "true" to the viewProj variable to make things work ( even though data and view projections are both now set to 3857 )
Vue.use(VueLayers, { dataProjection: 'EPSG:3857', viewProjection: 'EPSG:3857' });
on vl-source-vector there is a projection prop set to "EPSG:4326" which I assume is a default value because I am not passing it. The data for this source is set to this
dataProjection:"EPSG:3857" format:Object idents:Object (empty) rev:3 viewProjection:"EPSG:3857"
and the resolved values are
resolvedDataProjection:"EPSG:4326" resolvedViewProjection:"EPSG:3857"
----- I am sure it is a related issue, but synced feature values are coming back messed up for newly added features or by setting
<vl-source-vector :features.sync="features" ref="drawSource" ident="draw-target"
---- existing feature added with source.addFeatures(features, true) { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [ -21.226395373808817, 40.84891159355459 ], [ -38.62873912380883, 32.54887608816858 ], [ -29.22444224880882, 22.839201345730274 ], [ -17.622879748808817, 28.074139653268162 ], [ -21.226395373808817, 40.84891159355459 ] ] ] }, "properties": { "id": "7346", "label": "" }, "id": "7346" }, --- NEWLY drawn feature { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [ -1790459.9717941268, -71.4223730666448 ], [ -2993884.5451159426, 0 ], [ -1203423.5945639722, 0 ], [ -1790459.9717941268, -71.4223730666448 ] ] ] }, "properties": { "id": "14388", "label": "" }, "id": "14388" } ]