简体   繁体   English

地图平移或缩放时,OpenLayers 3矢量层失去样式

[英]OpenLayers 3 Vector Layer loses styling when map pans or zooms

UPDATE UPDATE

I tried adding the files into a Snippet or JSFiddle to make it available to people to edit, but JSFiddle is banned and I cannot upload text files into a Snippet. 我尝试将文件添加到Snippet或JSFiddle中以使其可供人们编辑,但是JSFiddle被禁止,并且我无法将文本文件上传到Snippet中。 Unless there's a better way to do it, here's the public repo for the files. 除非有更好的方法,否则这是文件的公共回购

Hi, everyone! 嗨,大家好!

I'm working on switching from OpenLayers 2 to OpenLayers 3 and supplementing my reading of by trying some things out on my own. 我正在努力从OpenLayers 2切换到OpenLayers 3,并通过自己尝试一些方法来补充我的阅读内容。 There's a project that I'm building here that should be fairly simple: take form inputs and use them as parameters for building a vector layer. 我在这里构建的一个项目应该非常简单:采用表单输入并将其用作构建矢量层的参数。 The interface works as intended, save for one problem. 该界面按预期工作,除了一个问题。

Whenever I pan the map or zoom it, the vector layer seems to disappear. 每当平移地图或缩放地图时,矢量层似乎都消失了。 I can't for the life of me imagine what's going on. 我无法终生想象发生了什么事。 Anyone able to help me figure out what I can do to keep the layer in place? 有人能帮助我弄清楚如何使图层保持在适当位置吗?

Thanks! 谢谢!

Dheeraj Dheeraj

The answer was in line 77 here . 答案在这里的第77行。 It turns out that for whatever reason, I misunderstood falsiness in JavaScript and my style-builder function was erring on undefined styles. 事实证明,无论出于何种原因,我都误解了JavaScript的虚假性,并且我的样式生成器函数在未定义的样式上犯了错误。 Who knew? 谁知道? The rest of the code works, though!!! 其余的代码都可以工作,但是!!!

Big thanks to @ahocevar for being willing to help! 非常感谢@ahocevar愿意提供帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM