<commit_before>
from numpy import array
from traits.api import Instance, Bool, Int, Property, Float, DelegatesTo
from enable.viewport import Viewport
from enable.base import empty_rectangle, intersect_bounds
from enable.enable_traits import coordinate_trait

from mapping_canvas import MappingCanvas
from mapping_zoom import MappingZoomTool

class MappingViewport(Viewport):

    component = Instance(MappingCanvas)

    zoom_level = Int(0)

    geoposition = coordinate_trait
    latitude = Property(Float, depends_on='geoposition')
    longitude = Property(Float, depends_on='geoposition')

    tile_cache = DelegatesTo('component')
    min_level = Property(lambda self: self.tile_cache.min_level)
    max_level = Property(lambda self: self.tile_cache.max_level)

    zoom_tool = Instance(MappingZoomTool)

    enable_zoom = Bool(True)
    stay_inside = Bool(True)

    def __init__(self, **traits):
        # Skip parent constructor
        super(Viewport, self).__init__(**traits)
        self._update_component_view_bounds()
        self.zoom_tool = MappingZoomTool(self)
        if self.enable_zoom:
            self._enable_zoom_changed(False, True)
        return

    def _get_latitude(self):
        return self.geoposition[0]
    def _set_latitude(self, val):
        self.geoposition[0] = val 

    def _get_longitude(self):
        return self.geoposition[1]
    def _set_longitude(self, val):
        self.geoposition[1] = val 

    def _geoposition_changed(self, old, new):
        lat, lon = new 
        tilex, tiley = self._coord_to_tilenum(lat, lon, self.zoom_level)
        #self.request_redraw()
    
    def _zoom_level_changed(self):
        self.request_redraw()

    def _draw_mainlayer(self, gc, view_bounds=None, mode="normal"):

        # For now, ViewPort ignores the view_bounds that are passed in...<commit_msg>Update view position based on change in geo position, bounds, or zoom_level<commit_after>
from numpy import array
from traits.api import Instance, Bool, Int, Property, Float, DelegatesTo, on_trait_change
from enable.viewport import Viewport
from enable.base import empty_rectangle, intersect_bounds
from enable.enable_traits import coordinate_trait

from mapping_canvas import MappingCanvas
from mapping_zoom import MappingZoomTool

class MappingViewport(Viewport):

    component = Instance(MappingCanvas)

    zoom_level = Int(0)

    geoposition = coordinate_trait
    latitude = Property(Float, depends_on='geoposition')
    longitude = Property(Float, depends_on='geoposition')

    tile_cache = DelegatesTo('component')
    min_level = Property(lambda self: self.tile_cache.min_level)
    max_level = Property(lambda self: self.tile_cache.max_level)

    zoom_tool = Instance(MappingZoomTool)

    enable_zoom = Bool(True)
    stay_inside = Bool(True)

    def __init__(self, **traits):
        # Skip parent constructor
        super(Viewport, self).__init__(**traits)
        self._update_component_view_bounds()
        self.zoom_tool = MappingZoomTool(self)
        if self.enable_zoom:
            self._enable_zoom_changed(False, True)
        self._update_position(self, 'geoposition', None, (0., 0.))

    def _get_latitude(self):
        return self.geoposition[0]
    def _set_latitude(self, val):
        self.geoposition[0] = val 

    def _get_longitude(self):
        return self.geoposition[1]
    def _set_longitude(self, val):
        self.geoposition[1] = val 

    @on_trait_change('geoposition, bounds, bounds_items, zoom_level')
    def _update_position(self, object, name, old, new):
        # Update position
        lat, lon = self.geoposition
        x, y = self.component._WGS84_to_screen(lon, lat, self.zoom_level)
        w, h = self.view_bounds
        self.view_position = [x - w/2., y - h/2.]

    def _draw_mainlayer(self, gc, view_bounds=None, mode="normal"):

        # For now, ViewPort ignores the view_bounds that are passed in...
{'fraction_non_alphanumeric': 0.0896551724137931, 'fraction_numerical': 0.004086845466155811, 'mean_word_length': 3.6124852767962308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2855774', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1191, 'n_words': 287}