javascript - Zooming an OpenLayers3 map to cover multiple vector layers -



javascript - Zooming an OpenLayers3 map to cover multiple vector layers -

i have openlayers3 map consisting of osm tile layer , 1 or more vector layers. can zoom map single layer using

vector.addeventlistener("change", function() { map.getview().fitextent(vectorsource.getextent(), map.getsize()); });

and works. however, if seek zoom cover multiple layers using next in loop adds layers

vector.addeventlistener("change", function () { if (bounds == null) { bounds = vectorsource.getextent(); } else { bounds = bounds.extend(vectorsource.getextent()); } map.getview().fitextent(bounds, map.getsize()); });

with bounds beingness declared outside loop, maps single layer go on work. however, more 1 layer, code in else block give error "undefined not function".

according documentation getextent() returns extent object , the extent object has extend method, i'm not sure why errors.

answering own question worked out. using extend wrongly. right code is:

vector.addeventlistener("change", function () { if (bounds == null) { bounds = vectorsource.getextent(); } else { bounds = ol.extent.extend(bounds, vectorsource.getextent()); } map.getview().fitextent(bounds, map.getsize()); });

javascript openlayers openlayers-3

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -