Skip to content

Commit

Permalink
Refactor deck-line-layer example to simplify code.
Browse files Browse the repository at this point in the history
Remove unused imports and redundant type definitions, streamline tooltip logic, and destructure initial view state for cleaner syntax.
  • Loading branch information
MostafaGamalSayed committed Dec 28, 2024
1 parent 96148d8 commit e05df98
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions docs/examples/deck-line-layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
</template>

<script setup lang="ts">
import { MapViewState, PickingInfo } from "@deck.gl/core";
import {
MglMap,
MglDeckScatteredPlotLayer,
Expand All @@ -67,21 +66,7 @@ const DATA_URL = {
"https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/line/heathrow-flights.json",
};
type Airport = {
type: "major" | "mid" | "small";
name: string;
abbrev: string; // airport code
coordinates: [longitude: number, latitude: number];
};
type FlightPath = {
start: [longitude: number, latitude: number, altitude: number];
end: [longitude: number, latitude: number, altitude: number];
country: string;
name: string; // tail number
};
const INITIAL_VIEW_STATE: MapViewState = {
const INITIAL_VIEW_STATE = {
latitude: 47.65,
longitude: 7,
zoom: 4.5,
Expand All @@ -93,11 +78,11 @@ const INITIAL_VIEW_STATE: MapViewState = {
const MAP_STYLE =
"https://basemaps.cartocdn.com/gl/dark-matter-nolabels-gl-style/style.json";
function getTooltip({ object }: PickingInfo) {
function getTooltip({ object }) {
return (
object &&
`\
${(object as FlightPath).country || (object as Airport).abbrev || ""}
${object.country || object.abbrev || ""}
${object.name.indexOf("0x") >= 0 ? "" : object.name}`
);
}
Expand All @@ -107,11 +92,8 @@ const flightPaths = DATA_URL.FLIGHT_PATHS;
const lineWidth = 3;
const mapStyle = MAP_STYLE;
const center = [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude];
const zoom = INITIAL_VIEW_STATE.zoom;
const maxZoom = INITIAL_VIEW_STATE.maxZoom;
const pitch = INITIAL_VIEW_STATE.pitch;
const bearing = INITIAL_VIEW_STATE.bearing;
const { longitude, latitude, zoom, maxZoom, pitch, bearing } = INITIAL_VIEW_STATE;
const center = [longitude, latitude];
</script>

<style lang="scss">
Expand Down

0 comments on commit e05df98

Please sign in to comment.