Skip to content

Commit

Permalink
docs: Update comments in the code for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
YuChunTsao committed Nov 5, 2023
1 parent 91e68c2 commit ab68138
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/maplibre-gl-overview-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Box {
public source: GeoJSONSource | undefined
public feature: GeoJSON.Feature | undefined

// Below variables user can change the value
// You can modify these variables to customize the behavior
public sourceName: string = 'maplibre-gl-overview-map-box-source'
public outlineLayerId: string = 'maplibre-gl-overview-map-box-outline-layer'
public fillLayerId: string = 'maplibre-gl-overview-map-box-fill-layer'
// Allow user can use mapbox style to set complex style.
// Allow users to use Maplibre Style Spec for setting complex styles.
public fillStyle: object = {
'fill-color': 'red',
'fill-opacity': 0.1
Expand Down Expand Up @@ -83,6 +83,7 @@ class OverviewMapControl implements IControl {
private overviewOnTouchMove: Listener | undefined

constructor(options?: Options) {
// If users set options, they will overwrite the default values.
if (options) {
Object.assign(this.options, options)
Object.assign(this.box, this.options.box)
Expand All @@ -101,11 +102,11 @@ class OverviewMapControl implements IControl {
}

initGlobalEvent() {
// If users release the mouse button and move outside the overview map container, it will trigger an event to update the map's status.
document.addEventListener('mouseup', this.detectMouseUpOutside.bind(this))
}

detectMouseUpOutside() {
// If user mouse up and out of overview map container, update overview map and parent map center.
if (this.isDragging) {
if (this.overviewMap === undefined) {
throw new Error('The overview map object is undefined')
Expand Down Expand Up @@ -304,7 +305,7 @@ class OverviewMapControl implements IControl {

this.isOverBox = features.length > 0

// Update cursor style when hover the box layer.
// Update the cursor style when hovering over the box layer
this.updateCursor()

if (this.isDragging) {
Expand All @@ -314,11 +315,11 @@ class OverviewMapControl implements IControl {
this.currentPoint.lat - this.previousPoint.lat
)

// update box center
// Update the center of the box
let newLng = this.box.center.lng + offset.lng
let newLat = this.box.center.lat + offset.lat

// Avoid set invalid value for LngLat
// Avoid setting invalid values for LngLat
if (newLat > MAX_LAT) newLat = MAX_LAT
if (newLat < -MAX_LAT) newLat = -MAX_LAT
this.box.center = new LngLat(newLng, newLat)
Expand Down Expand Up @@ -368,8 +369,8 @@ class OverviewMapControl implements IControl {
let parentMapZoom = this.parentMap.getZoom()
let overviewMapZoom = this.overviewMap.getZoom()

// Use the latitude of overview map to calculate resolution in different zoom level.
// Use the same latitude, so we can know the ratio between two map.
// Use the latitude of the overview map to calculate resolution in different zoom levels.
// Use the same latitude, so we can determine the ratio between the two maps
let parentMapResolution = this.calculateResolution(
overviewMapLat,
parentMapZoom
Expand Down

0 comments on commit ab68138

Please sign in to comment.