Comments (4)
Hi,
Just checked this with v3.15.1, and v3.16.0. The headers are set correctly, however, as you guessed it right, the propertychange
event isn't firing, thus the problem isn't on your end. No matter, if I set the property with set
, or setProperties
. An ugly temporal workaround would be setting the updater to listen for every change
event.
from mastering_openlayers3.
Well, I'm glad I'm not the only one. I was going crazy trying to figure this out. Still, it doesn't make any sense. Thanks for checking.
from mastering_openlayers3.
Fixed.
In the buildHeaders method, I set a breakpoint at this.set('headers', headers);
and inspected the value of this.getProperties('headers')
.
To my surprise the headers were already populated. So of course the propertyChange
event won't get fired; headers === this.getProperties('headers')
returns true
.
So I just added the line,
this.setProperties({'headers': {}});
before
this.set('headers', headers);
Checks good with v3.11.0, v3.12.0 and v3.16.0.
If you think of a more appropriate solution, I'd be interested in hearing about it.
from mastering_openlayers3.
Okay, so first of all, thanks for your help with the debugging. Your findings leaded to the solution.
The case is, there is a "new" logic in OL3, which prevents the setters from running, when the new value equals to the old one.
What the old code did:
var headers = this.get('headers') || {};
So what did it grab? The pointer to the headers
object, which is stored in the layer. Now, if we look at the updating logic:
for (var i = 0; i < features.length; i += 1) {
var attributes = features[i].getProperties();
for (var j in attributes) {
if (typeof attributes[j] !== 'object' && !(j in headers)) {
headers[j] = 'string';
}
}
}
we can see, that the code updates the headers
object in place. Thus, in the end, when OL3 checks, if the stored headers
object equals to our updated object, it finds, the two objects are essentially the same, as they are both pointers to the same object, which was updated in place.
The last piece of the puzzle: why the list wasn't populated when buildHeaders
was called the first time? Because, a headers
object was already provided on layer construction:
map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM(),
name: 'OpenStreetMap'
}),
new ol.layer.Vector({
source: new ol.source.Vector({
format: new ol.format.GeoJSON({
defaultDataProjection: 'EPSG:4326'
}),
url: '../../res/world_countries.geojson'
}),
name: 'World Countries',
headers: {
pop_est: 'integer',
gdp_md_est: 'integer'
}
})
],
You can see my solution to this issue at 72dd869, I just messed up the issue number.
from mastering_openlayers3.
Related Issues (14)
- Book Question HOT 2
- css button.active typo? HOT 1
- Uncaught TypeError: this.scrollTo is not a function HOT 7
- dynamic forms HOT 3
- Can't get WMS button work HOT 2
- API availability HOT 3
- categorized colors are invalid (sometimes) HOT 1
- ch05_draw handleEvents question HOT 2
- ch05_measure question HOT 2
- ch03_fileapi question HOT 1
- ch03_layertree question HOT 2
- How to draw geometry on preexisting layers? HOT 1
- styleGraduated missing typeof HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mastering_openlayers3.