(self, data_source, output_file)
| 110 | |
| 111 | |
| 112 | def convert(self, data_source, output_file): |
| 113 | codes = map(lambda g: g.properties[self.config['code_field']], data_source.geometries) |
| 114 | main_codes = copy.copy(codes) |
| 115 | self.map.insets = [] |
| 116 | envelope = [] |
| 117 | for inset in self.insets: |
| 118 | insetBbox = self.renderMapInset(data_source, inset['codes'], inset['left'], inset['top'], inset['width']) |
| 119 | insetHeight = (insetBbox[3] - insetBbox[1]) * (inset['width'] / (insetBbox[2] - insetBbox[0])) |
| 120 | self.map.insets.append({ |
| 121 | "bbox": [{"x": insetBbox[0], "y": -insetBbox[3]}, {"x": insetBbox[2], "y": -insetBbox[1]}], |
| 122 | "left": inset['left'], |
| 123 | "top": inset['top'], |
| 124 | "width": inset['width'], |
| 125 | "height": insetHeight |
| 126 | }) |
| 127 | envelope.append( |
| 128 | shapely.geometry.box( |
| 129 | inset['left'], inset['top'], inset['left'] + inset['width'], inset['top'] + insetHeight |
| 130 | ) |
| 131 | ) |
| 132 | for code in inset['codes']: |
| 133 | main_codes.remove(code) |
| 134 | |
| 135 | insetBbox = self.renderMapInset(data_source, main_codes, self.left, self.top, self.width) |
| 136 | insetHeight = (insetBbox[3] - insetBbox[1]) * (self.width / (insetBbox[2] - insetBbox[0])) |
| 137 | envelope.append( shapely.geometry.box( self.left, self.top, self.left + self.width, self.top + insetHeight ) ) |
| 138 | mapBbox = shapely.geometry.MultiPolygon( envelope ).bounds |
| 139 | |
| 140 | self.map.width = mapBbox[2] + mapBbox[0] |
| 141 | self.map.height = mapBbox[3] + mapBbox[1] |
| 142 | self.map.insets.append({ |
| 143 | "bbox": [{"x": insetBbox[0], "y": -insetBbox[3]}, {"x": insetBbox[2], "y": -insetBbox[1]}], |
| 144 | "left": self.left, |
| 145 | "top": self.top, |
| 146 | "width": self.width, |
| 147 | "height": insetHeight |
| 148 | }) |
| 149 | self.map.projection = {"type": self.projection, "centralMeridian": float(self.longitude0)} |
| 150 | |
| 151 | open(output_file, 'w').write( self.map.getJSCode() ) |
| 152 | |
| 153 | if self.for_each is not None: |
| 154 | for code in codes: |
| 155 | childConfig = copy.deepcopy(self.for_each) |
| 156 | for param in ('input_file', 'output_file', 'where', 'name'): |
| 157 | childConfig[param] = childConfig[param].replace('{{code}}', code.lower()) |
| 158 | converter = Converter(childConfig) |
| 159 | converter.convert(childConfig['output_file']) |
| 160 | |
| 161 | def renderMapInset(self, data_source, codes, left, top, width): |
| 162 | envelope = [] |
no test coverage detected