Set manual scales in PyQGIS for standalone application

المشرف العام

Administrator
طاقم الإدارة
I am trying to figure out how to set the zoom scales to match those meant for OpenStreetMaps and Google Maps, etc., as I am using OSM for a basemap. I've looked all over the internet and can't seem to find any support for this particular goal.

I have an XML document (scales.xml) with all of the scales needed, but I just can't figure out how to implement it:

I've tried reworking some of the code from thr QuickMapServices plugin, but I get no results from it:

def _load_scales_list(self): scales_filename = os.path.join(self.plugin_dir, 'scales.xml') scales_list = [] xml_root = ET.parse(scales_filename).getroot() for scale_el in xml_root.findall('scale'): scales_list.append(scale_el.get('value')) return scales_listdef scales_list(self): if not self._scales_list: self._scales_list = self._load_scales_list() return self._scales_listdef set_nearest_scale(self): #get current scale curr_scale = self.mapCanvas().scale() #find nearest nearest_scale = sys.maxint for scale_str in self.scales_list: scale = scale_str.split(':')[1] scale_int = int(scale) if abs(scale_int-curr_scale) < abs(nearest_scale - curr_scale): nearest_scale = scale_int #set new scale if nearest_scale != sys.maxint: self.mapCanvas().zoomScale(nearest_scale)This code neither throws an error nor does anything at all. Any ideas as to how I can get this working in a standalone window?



أكثر...
 
أعلى