-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add COG support for MapLibre #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <script setup lang="ts"> | ||
| import { onMounted, ref } from 'vue' | ||
| import { createMapFromContext } from '@geospatial-sdk/maplibre' | ||
| import { type MapContext } from '@geospatial-sdk/core' | ||
|
|
||
| const mapRoot = ref<HTMLElement>() | ||
|
|
||
| onMounted(async () => { | ||
| const context: MapContext = { | ||
| layers: [ | ||
| { | ||
| type: 'xyz', | ||
| url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' | ||
| }, | ||
| { | ||
| type: 'geotiff', | ||
| url: 'https://labs.geomatico.es/maplibre-cog-protocol/data/image.tif', | ||
| } | ||
| ], | ||
| view: { | ||
| center: [1.83369, 41.5937], | ||
| zoom: 14 | ||
| } | ||
| } | ||
|
|
||
| await createMapFromContext(context, { | ||
| container: mapRoot.value as HTMLElement | ||
| }) | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div ref="mapRoot" class="w-full h-full"></div> | ||
| </template> | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ import { | |
| ViewByZoomAndCenter, | ||
| } from "@geospatial-sdk/core"; | ||
|
|
||
| import { LayerSpecification, Map, MapOptions } from "maplibre-gl"; | ||
| import { addProtocol, LayerSpecification, Map, MapOptions } from "maplibre-gl"; | ||
| import { cogProtocol } from "@geomatico/maplibre-cog-protocol"; | ||
| import { FeatureCollection, Geometry } from "geojson"; | ||
| import { | ||
| OgcApiEndpoint, | ||
|
|
@@ -22,6 +23,8 @@ import { | |
| PartialStyleSpecification, | ||
| } from "../maplibre.models.js"; | ||
|
|
||
| let cogProtocolRegistered = false; | ||
|
|
||
| const featureCollection: FeatureCollection<Geometry | null> = { | ||
| type: "FeatureCollection", | ||
| features: [], | ||
|
|
@@ -153,6 +156,36 @@ export async function createLayer( | |
| ], | ||
| }; | ||
| } | ||
| case "geotiff": { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the string "geotiff" in many occasion, it would be nice to have a variables instead. Also true for the other types, because a string is more prone to errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many |
||
| if (!cogProtocolRegistered) { | ||
| addProtocol("cog", cogProtocol); | ||
| cogProtocolRegistered = true; | ||
| } | ||
| const sourceId = layerId; | ||
| return { | ||
| sources: { | ||
| [sourceId]: { | ||
| type: "raster", | ||
| url: `cog://${layerModel.url}`, | ||
| tileSize: 256, | ||
| }, | ||
| }, | ||
| layers: [ | ||
| { | ||
| id: layerId, | ||
| type: "raster", | ||
| source: sourceId, | ||
| paint: { | ||
| "raster-opacity": layerModel.opacity ?? 1, | ||
| }, | ||
| layout: { | ||
| visibility: layerModel.visibility === false ? "none" : "visible", | ||
| }, | ||
| metadata, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| case "wmts": { | ||
| console.warn(`WMTS layers are not yet supported in Maplibre`, layerModel); | ||
| return null; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cogbeing addressed asgeotiff(as defined inMapContextLayerGeotifffrompackages/core/lib/model/map-context.ts) is misleading and could lead to think that any geotif would work, and not just cog. So unless all geotiff works, including non-cloud-optimized, then I would advice renaming the typecogand also all the internal terminology that refers to "geotiff".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also surprised, @jahow why did you choose this keyword ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it works with plain geotiffs in OL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can throw an error in MapLibre if it doesn't support non-COG geotiff