def create_node_feature(node, popup_template, default_style, indicators): """Create a feature representing a node. Arguments: node -- Node object (see graph.py) popup_template -- template for the contents of the popup default_style -- style values to use for properties which have no indicator indicators -- specifications of style properties based on properties of the node """ style = union_dict(default_style, apply_indicators(indicators, node.properties)) return Feature( node.id, 'node', Geometry('Point', [node.lon, node.lat]), style['color'], style['size'], create_node_popup(node, popup_template), subdict(node.properties, _node_feature_properties), )
def make_geojson_feature(feature): """Create a GeoJSON object for a feature.""" popup = None if feature.popup: popup = { 'id': feature.popup.id, 'size': feature.popup.size, 'content': feature.popup.content, 'closable': feature.popup.closable } return { 'type': 'Feature', 'id': feature.id, 'geometry': { 'type': feature.geometry.type, 'coordinates': feature.geometry.coordinates }, 'properties': union_dict( { 'type': feature.type, 'color': feature.color, 'size': feature.size, 'popup': popup }, feature.properties) }
def make_feature(source_coords, target_coords, data): style = union_dict(default_style, apply_indicators(indicators, data)) popup = create_edge_popup(data, popup_template) return Feature( data['id'], 'edge', Geometry('LineString', [source_coords, target_coords]), style['color'], style['size'], popup, )
def apply_indicators(indicators, properties): """Apply a list of indicators to a list of properties.""" applicator = partial(apply_indicator, properties=properties) return union_dict(*[applicator(i) for i in indicators])