def test_best_srs_no_preferred(self, preferred): supported = SupportedSRS([SRS(4326), SRS(25832)], None) assert supported.best_srs(SRS(4326)) == SRS(4326) assert supported.best_srs(SRS(4258)) == SRS(4326) assert supported.best_srs(SRS(25832)) == SRS(25832) assert supported.best_srs(SRS(25831)) == SRS(25832) assert supported.best_srs(SRS(3857)) == SRS(25832)
def test_best_srs(self, preferred): supported = SupportedSRS([SRS(4326), SRS(25832)], preferred) assert supported.best_srs(SRS(4326)) == SRS(4326) assert supported.best_srs(SRS(4258)) == SRS(4326) assert supported.best_srs(SRS(25832)) == SRS(25832) assert supported.best_srs(SRS(25831)) == SRS(25832) assert supported.best_srs(SRS(3857)) == SRS(25832) supported = SupportedSRS( [SRS(4326), SRS(31467), SRS(25831)], preferred) assert supported.best_srs(SRS(3857)) == SRS(25831) assert supported.best_srs(SRS(25831)) == SRS(25831)
class SRSConditional(MapLayer): supports_meta_tiles = True def __init__(self, layers, extent, opacity=None, preferred_srs=None): MapLayer.__init__(self) self.srs_map = {} self.res_range = merge_layer_res_ranges([l[0] for l in layers]) supported_srs = [] for layer, srs in layers: supported_srs.append(srs) self.srs_map[srs] = layer self.supported_srs = SupportedSRS(supported_srs, preferred_srs) self.extent = extent self.opacity = opacity def get_map(self, query): self.check_res_range(query) layer = self._select_layer(query.srs) return layer.get_map(query) def _select_layer(self, query_srs): srs = self.supported_srs.best_srs(query_srs) return self.srs_map[srs]