-
Notifications
You must be signed in to change notification settings - Fork 36
feat: Vector Tile Source Support #90
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
Merged
psrednicki
merged 9 commits into
Azure:master
from
ambientlight:feat/vector-tile-source
Apr 13, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0faf70a
base vector tile source support
ambientlight 98c560d
undo lint-staged edits
ambientlight be28359
fix: top level export added
ambientlight 614dee0
fix: handle VectorTileSource in useFeature
ambientlight b4bb108
fix: useFeature top level hooks, tile source provider is seperate file
ambientlight 853b35e
fix: vector tile source provider types, typedoc comments
ambientlight e2724ab
fix: remove unused imports
ambientlight 7dca5ed
fix: use imperative syntax for clarity
ambientlight 23c3f4a
feat: updated coverage
ambientlight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { renderHook } from '@testing-library/react-hooks' | ||
| import React, { useContext } from 'react' | ||
| import { Map } from 'azure-maps-control' | ||
| import { IAzureVectorTileSourceStatefulProviderProps } from "../types" | ||
| import { AzureMapsContext } from './AzureMapContext' | ||
| import { AzureMapVectorTileSourceProvider } from './AzureMapVectorTileSourceProvider' | ||
| import { AzureMapDataSourceContext } from '../contexts/AzureMapDataSourceContext' | ||
|
|
||
| const mapContextProps = { | ||
| mapRef: null, | ||
| isMapReady: false, | ||
| setMapReady: jest.fn(), | ||
| removeMapRef: jest.fn(), | ||
| setMapRef: jest.fn() | ||
| } | ||
| const mapRef = new Map('fake', {}) | ||
|
|
||
| const useContextConsumer = () => { | ||
| const dataSourceContext = useContext(AzureMapDataSourceContext) | ||
| return dataSourceContext | ||
| } | ||
|
|
||
| const wrapWithVectorTileSourceContext = (props: IAzureVectorTileSourceStatefulProviderProps) => ({ | ||
| children | ||
| }: { | ||
| children?: any | ||
| }) => { | ||
| return ( | ||
| <AzureMapsContext.Provider | ||
| value={{ | ||
| ...mapContextProps, | ||
| mapRef | ||
| }} | ||
| > | ||
| <AzureMapVectorTileSourceProvider {...{ ...props }}>{children}</AzureMapVectorTileSourceProvider> | ||
| </AzureMapsContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| describe('AzureMapVectorTileSourceProvider tests', () => { | ||
| it('should create data source with passed id and options', () => { | ||
| const { result } = renderHook(() => useContextConsumer(), { | ||
| wrapper: wrapWithVectorTileSourceContext({ id: 'id', options: { minZoom: 0, maxZoom: 12 } }) | ||
| }) | ||
|
|
||
| expect(result.current.dataSourceRef?.getId()).toEqual('id') | ||
| expect(result.current.dataSourceRef?.getOptions()).toEqual({ minZoom: 0, maxZoom: 12 }) | ||
| }) | ||
|
|
||
| it('should add data source to the map ref on mount', () => { | ||
| mapRef.sources.add = jest.fn() | ||
| const { result } = renderHook(() => useContextConsumer(), { | ||
| wrapper: wrapWithVectorTileSourceContext({ id: 'id' }) | ||
| }) | ||
| expect(mapRef.sources.add).toHaveBeenCalledWith(result.current.dataSourceRef) | ||
| }) | ||
|
|
||
| it('should add event to data source', () => { | ||
| mapRef.events.add = jest.fn() | ||
| renderHook(() => useContextConsumer(), { | ||
| wrapper: wrapWithVectorTileSourceContext({ id: 'id', events: { sourceadded: (source) => {} } }) | ||
| }) | ||
| expect(mapRef.events.add).toHaveBeenCalledWith( | ||
| 'sourceadded', | ||
| expect.any(Object), | ||
| expect.any(Function) | ||
| ) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import atlas from 'azure-maps-control' | ||
| import React, { useContext, useState } from 'react' | ||
| import { useCheckRef } from '../hooks/useCheckRef' | ||
| import { DataSourceType, IAzureMapsContextProps, IAzureMapSourceEventType, IAzureVectorTileSourceStatefulProviderProps, MapType } from '../types' | ||
| import { AzureMapDataSourceRawProvider as Provider } from './AzureMapDataSourceContext' | ||
| import { AzureMapsContext } from './AzureMapContext' | ||
|
|
||
| /** | ||
| * @param id datasource identifier | ||
| * @param children layer providers representing datasource layers | ||
| * @param options vector tile datasource options: see atlas.VectorTileSourceOptions | ||
| * @param events a object containing sourceadded, sourceremoved event handlers | ||
| */ | ||
| const AzureMapVectorTileSourceStatefulProvider = ({ | ||
| id, | ||
| children, | ||
| options, | ||
| events = {}, | ||
| }: IAzureVectorTileSourceStatefulProviderProps) => { | ||
| const [dataSourceRef] = useState<atlas.source.VectorTileSource>(new atlas.source.VectorTileSource(id, options)) | ||
| const { mapRef } = useContext<IAzureMapsContextProps>(AzureMapsContext) | ||
| useCheckRef<MapType, DataSourceType>(mapRef, dataSourceRef, (mref, dref) => { | ||
| for (const eventType in events) { | ||
| const handler = events[eventType as IAzureMapSourceEventType] as (e: atlas.source.Source) => void | undefined | ||
| if(handler) { | ||
| mref.events.add(eventType as IAzureMapSourceEventType, dref, handler) | ||
| } | ||
| } | ||
| mref.sources.add(dref) | ||
| }) | ||
|
|
||
| return ( | ||
| <Provider | ||
| value={{ | ||
| dataSourceRef, | ||
| }} | ||
| > | ||
| {mapRef && children} | ||
| </Provider> | ||
| ) | ||
| } | ||
|
|
||
| export { AzureMapVectorTileSourceStatefulProvider as AzureMapVectorTileSourceProvider } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.