{"action":"created","issue":{"url":"https://api.github.com/repos/openlayers/openlayers/issues/669","labels_url":"https://api.github.com/repos/openlayers/openlayers/issues/669/labels{/name}","comments_url":"https://api.github.com/repos/openlayers/openlayers/issues/669/comments","events_url":"https://api.github.com/repos/openlayers/openlayers/issues/669/events","html_url":"https://github.com/openlayers/openlayers/issues/669","id":6710933,"number":669,"title":"OpenLayers.Map.getSize returns (sometimes) null when map.div width or height is percentage while adding vector-Layers","user":{"login":"fastrde","id":1861723,"avatar_url":"https://avatars.githubusercontent.com/u/1861723?v=3","gravatar_id":"","url":"https://api.github.com/users/fastrde","html_url":"https://github.com/fastrde","followers_url":"https://api.github.com/users/fastrde/followers","following_url":"https://api.github.com/users/fastrde/following{/other_user}","gists_url":"https://api.github.com/users/fastrde/gists{/gist_id}","starred_url":"https://api.github.com/users/fastrde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fastrde/subscriptions","organizations_url":"https://api.github.com/users/fastrde/orgs","repos_url":"https://api.github.com/users/fastrde/repos","events_url":"https://api.github.com/users/fastrde/events{/privacy}","received_events_url":"https://api.github.com/users/fastrde/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2012-09-07T10:27:56Z","updated_at":"2015-07-15T11:20:10Z","closed_at":"2012-09-07T11:54:11Z","body":"the error looks like a timing issue. \nI try to explain it on a simple example...\n```javascript\n<html>\n<head>\n<style>\n  div#map{ width 100%; height: 100%; } //div#map width and height are percentage\n</style>\n</head>\n<body>\n<div id=\"map\"></div>\n<script>\n \n  var map = new OpenLayers.map(\"map\");\n  var v1    = new OpenLayers.Layer.Vector(\"v1\");\n  var v2    = new OpenLayers.Layer.Vector(\"v2\");\n  var v3    = new OpenLayers.Layer.Vector(\"v3\");\n  \n  var dump = clone(map); //function to clone(!) an object\n  console.log(dump); //cloned map doesn't have a size object\n  console.log(map); //TRAP: map has a size object in chrome devtools because the devtools shows the last state of the object.\n  map.addLayers([v1,v2,v3]); //here getSize is called internally and the error occured sometimes\n  map.setCenter(greatLocationToCenter);\n</script>\n</body>\n</html>\n\n\n```\nI cloned the map Object before map.addLayers is called and it doesn't have a map.size object when the error happens.\nLooks like the Browser (Chrome in my case) is not ready with calculating the pixel height and width at this moment. When you give static pixel values in css the error doesn't happen.\nI can't reproduce the error with firefox on the same machine.  Maybe firefox ist faster in calculating the height/width or the internal handling is different.\n\nHere are the Points where the error occured\n\nUncaught TypeError: Cannot read property 'w' of null in OpenLayers/Layer/Vector.js:400\n```javascript\n 391     setMap: function(map) {\n 392         OpenLayers.Layer.prototype.setMap.apply(this, arguments);\n 393 \n 394         if (!this.renderer) {\n 395             this.map.removeLayer(this);\n 396         } else {\n 397             this.renderer.map = this.map;\n 398 \n 399             var newSize = this.map.getSize(); // here getSize returns null because map.size is not initialized\n 400             newSize.w = newSize.w * this.ratio; //here happens the TypeError\n 401             newSize.h = newSize.h * this.ratio;\n 402             this.renderer.setSize(newSize);\n 403         }\n 404     },\n```\nUncaught TypeError: Cannot read property 'w' of null im OpenLayers/Map.js:1787\n```javascript\n1785     adjustZoom: function(zoom) {\n1786         var resolution, resolutions = this.baseLayer.resolutions,\n1787             maxResolution = this.getMaxExtent().getWidth() / this.size.w; //here this.size is null\n1788         if (this.getResolutionForZoom(zoom) > maxResolution) {\n1789             for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {\n1790                 if (resolutions[i] <= maxResolution) {\n1791                     zoom = i;\n1792                     break;\n1793                 }\n1794             }\n1795         }\n1796         return zoom;\n1797     },\n```\n"},"comment":{"url":"https://api.github.com/repos/openlayers/openlayers/issues/comments/121585522","html_url":"https://github.com/openlayers/openlayers/issues/669#issuecomment-121585522","issue_url":"https://api.github.com/repos/openlayers/openlayers/issues/669","id":121585522,"user":{"login":"printmypic","id":1032794,"avatar_url":"https://avatars.githubusercontent.com/u/1032794?v=3","gravatar_id":"","url":"https://api.github.com/users/printmypic","html_url":"https://github.com/printmypic","followers_url":"https://api.github.com/users/printmypic/followers","following_url":"https://api.github.com/users/printmypic/following{/other_user}","gists_url":"https://api.github.com/users/printmypic/gists{/gist_id}","starred_url":"https://api.github.com/users/printmypic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/printmypic/subscriptions","organizations_url":"https://api.github.com/users/printmypic/orgs","repos_url":"https://api.github.com/users/printmypic/repos","events_url":"https://api.github.com/users/printmypic/events{/privacy}","received_events_url":"https://api.github.com/users/printmypic/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T11:20:10Z","updated_at":"2015-07-15T11:20:10Z","body":"I have the same bug here version 3.7\r\nstrange when I open my app in incognito this problem is gone, maybe it related to cache stuff?"}}