ghettovoice / vuelayers

Web map Vue components with the power of OpenLayers
https://vuelayers.github.io/
MIT License
681 stars 230 forks source link

v12rc14 -- currentExtentDataProj / viewProj NaN #378

Closed aliciahogue closed 3 years ago

aliciahogue commented 3 years ago

See attached image for what I mean. Initial extent of layer is set at [-199.999988540844,-25.00904999895826,199.999988540844,105.051128514163]

$layer.getSource().getExtent() returns proper value of [-20037507.067161832,-558316.5538040891,20037507.067161832,20037508.000000015]

rsz_screenshot_from_2020-10-20_11-13-10

ghettovoice commented 3 years ago

If you run this code:

import { transformExtent } from 'ol/proj'

console.log(transformExtent([-199.999988540844,-25.00904999895826,199.999988540844,105.051128514163], 'EPSG:4326', 'EPSG:3857'))

you will get exactly same result.

I guess this is because max world bounds for EPSG:4326 is [-180, -90, 180, 90]. And here [-20037507.067161832,-558316.5538040891,20037507.067161832,20037508.000000015] the value in EPSG:3857 20037507.067161832 is equal to 179.999988540844 in EPSG:4326. So $layer.getSource().getExtent() shows current valid extent that bound all your features. Sure it's X axis values can't be out of [-180, 180] or [-20037507.067161832, 20037507.067161832] because there is no features that can have coordinates out of this intervals.

Why you try to set extent longitude not belonging to [-180, 180] bounds?

aliciahogue commented 3 years ago

Because my layer ( the green outline ) crosses the dateline and if I set the extent to be clipped at the dateline then it is cut off on the edge while the world keeps wrapping. I can try this again, perhaps it was a bug that I was seeing. I understand what you are saying though, and never did the conversion of what openlayers was giving me to see that the output was clipped at 179

ghettovoice commented 3 years ago

Ok. I see 2 possible solutions to workaround longitude out of [-180, 180]:

  1. shift left/right extent X coordinates by world width, for EPSG:3246 extent[0] + 360, extent[2] + 360.
  2. define custom projection, very similar to EPSG:4326 but centered on the dateline (example for EPSG:3857 https://stackoverflow.com/a/60793984).

I also just noticed that you have extent latitude out of [-90,90] too. I guess solutions above can work for it too.