1212from .models .sources import GeoTIFFSource , VectorSource
1313from .models .view import View
1414from .styles import FlatStyle , default_style
15+ from .models .formats import Format , GeoJSON , KML , GPX
1516
1617
1718class GeoTIFFTileLayer (LayerLike ):
@@ -33,13 +34,55 @@ def to_map(self, *args, **kwargs) -> Map:
3334 return m
3435
3536
36- #class VectorLayer(LayerLike): ...
37+ # class VectorLayer(LayerLike): ...
3738
38- #class GPXLayer(VectorLayer): ...
39+ # class GPXLayer(VectorLayer): ...
3940
40- #class GeoJSONLayer(VectorLayer): ...
41+ # class GeoJSONLayer(VectorLayer): ...
4142
42- #class TopoJSONLayer(VectorLayer): ...
43+ # class TopoJSONLayer(VectorLayer): ...
44+
45+
46+ class Vector (LayerLike ):
47+ def __init__ (
48+ self ,
49+ data : str | dict ,
50+ id : str = None ,
51+ style = default_style (),
52+ fit_bounds : bool = True ,
53+ format : Format = None ,
54+ webgl : bool = True ,
55+ ** kwargs ,
56+ ) -> None :
57+ source = (
58+ VectorSource (url = data )
59+ if isinstance (data , str )
60+ else VectorSource (geojson = data )
61+ )
62+ if not format and source .url :
63+ url = source .url .lower ()
64+ if url .endswith (".kml" ):
65+ format = KML ()
66+ elif url .endswith (".gpx" ):
67+ format = GPX ()
68+
69+ source .format = format or GeoJSON ()
70+ Layer = WebGLVectorLayer if webgl else VectorLayer
71+ self ._model = Layer (
72+ source = source , id = id , fit_bounds = fit_bounds , style = style , ** kwargs
73+ )
74+
75+ def explore (self , tooltip : bool = True , ** kwargs ) -> Map | MapWidget :
76+ m = Map (** kwargs )
77+ m .add_layer (self ._model )
78+ if tooltip :
79+ m .add_default_tooltip ()
80+
81+ return m
82+
83+ @property
84+ def model (self ) -> VectorLayer | WebGLVectorLayer :
85+ return self ._model
4386
4487
4588# TODO: Move to VectorLayer
0 commit comments