Internal function to create the mapping.
(self, func: Callable, switch: str)
| 899 | return self._create_mapping(highlight_function, "highlight") |
| 900 | |
| 901 | def _create_mapping(self, func: Callable, switch: str) -> TypeStyleMapping: |
| 902 | """Internal function to create the mapping.""" |
| 903 | mapping: TypeStyleMapping = {} |
| 904 | for feature in self.data["features"]: |
| 905 | content = func(feature) |
| 906 | if switch == "style": |
| 907 | for key, value in content.items(): |
| 908 | if isinstance(value, MacroElement): |
| 909 | # Make sure objects are rendered: |
| 910 | if value._parent is None: |
| 911 | value._parent = self.geojson_obj |
| 912 | value.render() |
| 913 | # Replace objects with their Javascript var names: |
| 914 | content[key] = "{{'" + value.get_name() + "'}}" |
| 915 | key = self._to_key(content) |
| 916 | feature_id = self.get_feature_id(feature) |
| 917 | mapping.setdefault(key, []).append(feature_id) # type: ignore |
| 918 | self._set_default_key(mapping) |
| 919 | return mapping |
| 920 | |
| 921 | def get_feature_id(self, feature: dict) -> Union[str, int]: |
| 922 | """Return a value identifying the feature.""" |
no test coverage detected