javascript - Openlayers 3 with new ol.Vector returns [Infinity, Infinity, -Infinity, -Infinity] -
i have search form call solr index, filled geolocations:
jquery('.form-submit', element).click(function (e) { e.preventdefault(); search(); }); function search() { usebbox = false; combinedextent = ol.extent.createempty(); data.map.getlayers().foreach(function (layer, index, array) { if (layer.getsource() instanceof ol.source.vector) { var source = layer.getsource().getsource(); var url = data.opt.urls[source.get('machinename')]; var newsource = new ol.source.vector({ loader: getloader(data, url), format: new ol.format.geojson(), strategy: ol.loadingstrategy.bbox, reloadonzoomchange: true, reloadonextentchange: true }); newsource.set('machinename', source.get('machinename')); var newcluster = new ol.source.cluster({ source: newsource, distance: 200 }); layer.setsource(newcluster); } }); } function getloader(data, url) { return function (extent, resolution, projection) { var bbox = ol.proj.transformextent(extent, data.map.getview().getprojection(), 'epsg:4326'); var params = {}; if (data.opt.paramforwarding) { var get_params = location.search.substring(location.search.indexof('?') + 1).split('&'); jquery.each(get_params, function (i, val) { if (val.length) { var param = val.split('='); params[decodeuricomponent(param[0])] = (param[1] !== undefined) ? decodeuricomponent(param[1].replace(/\+/g, ' ')) : ''; } }) } if (usebbox == true) { params.bbox = bbox.join(','); params.zoom = data.map.getview().getzoom(); } var searchquery = jquery('#input-search-address').val(); if (searchquery != 'undefined' && searchquery != null) { url = url.substr(0, url.lastindexof("/") + 1); url = url + searchquery; } jquery(document).trigger('openlayers.bbox_pre_loading', [{ 'url': url, 'params': params, 'data': data }]); var = this; jquery.ajax({ url: url, data: params, success: function (responsdata) { var features = that.getfeaturesinextent(extent); jquery(features).each(function (i, f) { that.removefeature(f); }); var format = new ol.format.geojson(); var features = format.readfeatures(responsdata, {featureprojection: projection}); that.addfeatures(features); that._loadingfeatures = false; if (!ol.extent.isempty(that.getextent())) { combinedextent = ol.extent.extend(combinedextent, that.getextent()); if (usebbox == false) { usebbox = true; } } } }); }; } basically, fetches 3 layers, each containing number of markers. i'ld autozoom map based on markers. therefore i'm looking extent. combinedextent contain correct extents...
... when add data.map.getview().fit(combinedextent, data.map.getsize()) inside getloader function, it's not working. looks 1 extent plotted on map.
whenever try log combinedextent in search() function, weird error...
google told me had wait until getstate() of newsource ready, didn't work out... so, i'm looking solution. guess use of ajax return in getloader...


Comments
Post a Comment