-
Notifications
You must be signed in to change notification settings - Fork 20
added new baselayer with various styling #70
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: master
Are you sure you want to change the base?
Changes from 5 commits
ecd930b
685e5fe
080c68e
e983ae9
51d6547
74c1ff0
3bc2ba7
5bd45d7
9d53e71
b8e203b
b958d1a
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,6 @@ | ||
| REACT_APP_MAPBOX_STYLE_ACCESS_TOKEN=pk.eyJ1Ijoic2hpdmFtLXNvbmkiLCJhIjoiY2t3OTFhdTFiMDR0OTJucWxhdG13bnk0dSJ9.eV9aMwxPXkIDz9DkUe5HdA | ||
| REACT_APP_MAPBOX_LIGHT_STYLE=https://api.mapbox.com/styles/v1/shivam-soni/ckvb1lz88098p16s55aog1tvv/tiles/256/{z}/{x}/{y} | ||
| REACT_APP_MAPBOX_DARK_STYLE=https://api.mapbox.com/styles/v1/shivam-soni/ckvb1pult2aon14mt5de2lc79/tiles/256/{z}/{x}/{y} | ||
| REACT_APP_MAPBOX_SATELLITE_STYLE=https://api.mapbox.com/styles/v1/shivam-soni/ckvb1rchjc1ut14s7lsi66s3g/tiles/256/{z}/{x}/{y} | ||
| REACT_APP_MAPBOX_STREETS_STYLE=https://api.mapbox.com/styles/v1/shivam-soni/ckvb1sp6h4svu15t5h7snxwgc/tiles/256/{z}/{x}/{y} | ||
| REACT_APP_MAPBOX_GREEN_STYLE=https://api.mapbox.com/styles/v1/shivam-soni/ckvb1tksh05ts14mxll1ykm7s/tiles/256/{z}/{x}/{y} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
| /build | ||
|
||
|
|
||
| #lambda | ||
| /lambda | ||
|
|
@@ -23,7 +23,7 @@ | |
| .env.test.local | ||
| .env.production.local | ||
| .env | ||
| .env.development | ||
| .env.development | ||
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| let source = {}; | ||
| export let source = {}; | ||
|
|
||
| export const setSource = mapSource => { | ||
| source = mapSource; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| import React, { useEffect } from 'react'; | ||
| import olMain from './ol/main'; | ||
| import 'ol/ol.css'; | ||
| import { URL_SHAPE, URL_TILES, URL_COLORS, URL_OPACITY } from 'config'; | ||
| import { | ||
| URL_SHAPE, | ||
| URL_TILES, | ||
| URL_COLORS, | ||
| URL_OPACITY, | ||
| URL_BASE_LAYER, | ||
| URL_UPDATE_PUSH, | ||
| } from 'config'; | ||
| import { useQueryParam, StringParam } from 'use-query-params'; | ||
| import { usePrevious } from 'react-use'; | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
|
|
@@ -10,30 +17,47 @@ import { handleLocationButton } from 'utils'; | |
| import { setSource } from '../../api/map-data'; | ||
| import { FOOTER_ICON } from 'config'; | ||
|
|
||
| import { getBaseMapUrl } from 'utils'; | ||
|
|
||
|
|
||
| export default function OlInit() { | ||
| const [shape] = useQueryParam(URL_SHAPE, StringParam); | ||
| const [tiles] = useQueryParam(URL_TILES, StringParam); | ||
| const [colors] = useQueryParam(URL_COLORS, StringParam); | ||
| const [opacity] = useQueryParam(URL_OPACITY, StringParam); | ||
|
|
||
| const [baseLayer, onChangeBaseLayer] = useQueryParam( | ||
| URL_BASE_LAYER, | ||
| StringParam | ||
| ); | ||
|
|
||
|
|
||
| const prevTiles = usePrevious(tiles); | ||
| const prevShape = usePrevious(shape); | ||
| const prevBaseLayer = usePrevious(baseLayer); | ||
|
|
||
| useEffect(() => { | ||
| const olInstances = olMain({ shape, tiles, colors, opacity }); | ||
| const olInstances = olMain({ shape, tiles, colors, opacity, baseLayer }); | ||
| setSource(olInstances.map.getLayers().getArray()[0].values_.source); | ||
|
|
||
| if (olInstances.rasterSource && shape && prevTiles !== tiles) { | ||
| olInstances.rasterSource.setUrl(tiles); | ||
| olInstances.rasterSource.refresh(); | ||
| } | ||
|
|
||
| if (olInstances.baseMapSource && baseLayer && prevBaseLayer !== baseLayer) { | ||
| // console.log(`prevBaseLayer`, prevBaseLayer, baseLayer); | ||
|
||
| olInstances.baseMapSource.setUrl(getBaseMapUrl(baseLayer)); | ||
| olInstances.baseMapSource.refresh(); | ||
| } | ||
|
|
||
| if (olInstances.shapeSource && shape && prevShape !== shape) { | ||
| olInstances.shapeSource.setUrl(shape); | ||
| olInstances.shapeSource.refresh(); | ||
|
|
||
| olInstances.shapeSource.on('change', () => { | ||
| let shapeExtentArray = olInstances.shapeSource.getExtent(); | ||
|
|
||
| if ( | ||
| shapeExtentArray && | ||
| !shapeExtentArray.includes(Infinity) && | ||
|
|
@@ -53,7 +77,16 @@ export default function OlInit() { | |
| if (olInstances.rasterSource) { | ||
| olInstances.rasterSource.refresh(); | ||
| } | ||
| }, [shape, tiles, colors, opacity, prevTiles, prevShape]); | ||
| }, [ | ||
| shape, | ||
| tiles, | ||
| colors, | ||
| opacity, | ||
| prevTiles, | ||
| prevShape, | ||
| baseLayer, | ||
| prevBaseLayer, | ||
| ]); | ||
|
|
||
| return ( | ||
| <> | ||
|
|
@@ -65,7 +98,7 @@ export default function OlInit() { | |
| </button> | ||
| </div> | ||
| </div> | ||
| <div id="popup" class="ol-popup"> | ||
| <div id="popup" className="ol-popup"> | ||
| <div className="powered"> | ||
| Powered by{' '} | ||
| <a href="http://blueskyhq.in/" target="_blank" rel="noreferrer"> | ||
|
|
@@ -80,9 +113,46 @@ export default function OlInit() { | |
| Mapbox | ||
| </a> | ||
| </div> | ||
| <div className="button-block"> | ||
| <button | ||
| className="toggle" | ||
| onClick={e => onChangeBaseLayer('light', URL_UPDATE_PUSH)} | ||
| > | ||
| light | ||
| </button> | ||
| <button | ||
| className="toggle" | ||
| onClick={e => onChangeBaseLayer('dark', URL_UPDATE_PUSH)} | ||
| > | ||
| dark | ||
| </button> | ||
| <button | ||
| className="toggle" | ||
| onClick={e => onChangeBaseLayer('satelight', URL_UPDATE_PUSH)} | ||
| > | ||
| satelight | ||
| </button> | ||
| <button | ||
| className="toggle" | ||
| onClick={e => onChangeBaseLayer('street', URL_UPDATE_PUSH)} | ||
| > | ||
| street | ||
| </button> | ||
| <button | ||
| className="toggle" | ||
| onClick={e => onChangeBaseLayer('green', URL_UPDATE_PUSH)} | ||
| > | ||
| green | ||
| </button> | ||
|
||
| </div> | ||
| <div className="badges"> | ||
| {FOOTER_ICON.map(footer => ( | ||
| <a href={footer.url} target="_blank" rel="noreferrer"> | ||
| <a | ||
| key={footer.label} | ||
| href={footer.url} | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| > | ||
| <img src={footer.img} alt={footer.label} /> | ||
| </a> | ||
| ))} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import XYZ from 'ol/source/XYZ'; | ||
| import { Tile as TileLayer } from 'ol/layer'; | ||
|
|
||
| export function baseMapLayerLoader(url) { | ||
| // console.log(`url`, url); | ||
|
||
| const baseMapSource = new XYZ({ | ||
| url, | ||
| }); | ||
|
|
||
| const baseMapLayer = new TileLayer({ | ||
| className: true, | ||
| preload: Infinity, | ||
| source: baseMapSource, | ||
| }); | ||
|
|
||
| return { baseMapSource, baseMapLayer }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| import { Vector as VectorLayer } from 'ol/layer'; | ||
| import { Vector as VectorSource } from 'ol/source'; | ||
| import { TopoJSON } from 'ol/format'; | ||
|
|
||
| import { getVectorContext } from 'ol/render'; | ||
| import { Fill, Style, Stroke } from 'ol/style'; | ||
|
|
||
| /** | ||
| * @param {*} rasterLayer = Raster layer map instance generated from OL map init | ||
| */ | ||
| export default function clipRasterLayer({ rasterLayer, shape }) { | ||
| //Create cliping layer from topojson | ||
| // console.log(`shape`, shape); | ||
|
||
| const shapeSource = new VectorSource({ | ||
| url: shape, | ||
| format: new TopoJSON(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,15 @@ | ||
| import Map from 'ol/Map'; | ||
| import XYZ from 'ol/source/XYZ'; | ||
| import { Tile as TileLayer } from 'ol/layer'; | ||
| import View from 'ol/View'; | ||
| import { BASEMAP_LIGHT_STYLE } from 'config'; | ||
|
|
||
| export default function initMap({ rasterLayer, clipLayer, boundaryLayer }) { | ||
| export default function initMap({ | ||
| rasterLayer, | ||
| clipLayer, | ||
| boundaryLayer, | ||
| baseMapLayer, | ||
| }) { | ||
| return new Map({ | ||
| target: 'map', | ||
| view: new View({ center: [0, 0], zoom: 0 }), | ||
| layers: [ | ||
| new TileLayer({ | ||
| className: true, | ||
| preload: Infinity, | ||
| source: new XYZ({ | ||
| url: BASEMAP_LIGHT_STYLE, | ||
| }), | ||
| }), | ||
| clipLayer, | ||
| rasterLayer, | ||
| boundaryLayer, | ||
| ], | ||
| layers: [baseMapLayer, clipLayer, rasterLayer, boundaryLayer], | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,24 @@ import { | |
| getRgbColorsArray, | ||
| addSearchControl, | ||
| setMap, | ||
| getBaseMapUrl, | ||
| } from 'utils'; | ||
|
|
||
| import { baseMapLayerLoader } from './base-layer'; | ||
|
|
||
| let map = null; | ||
| let rasterSource = null; | ||
| let rasterColorSource = null; | ||
| let rasterLayer = null; | ||
| let shapeSource = null; | ||
| let baseMapSource = null; | ||
| let baseMapLayer = null; | ||
|
|
||
| export default function olMain({ shape, tiles, colors, opacity }) { | ||
| export default function olMain({ shape, tiles, colors, opacity, baseLayer }) { | ||
| const spectrumColor = getColorsArray(colors); | ||
|
|
||
| const url = getBaseMapUrl(baseLayer); | ||
|
|
||
| const rgbColorsArray = getRgbColorsArray( | ||
| spectrumColor.length >= 2 ? spectrumColor : ['#000000', '#ffffff'] | ||
| ); | ||
|
|
@@ -24,7 +32,14 @@ export default function olMain({ shape, tiles, colors, opacity }) { | |
| }); | ||
|
|
||
| if (map) | ||
| return { map, rasterLayer, rasterSource, shapeSource, rasterColorSource }; | ||
| return { | ||
| map, | ||
| rasterLayer, | ||
| rasterSource, | ||
| shapeSource, | ||
| rasterColorSource, | ||
| baseMapSource, | ||
| }; | ||
|
|
||
| const loadRaster = loadRasterLayer({ | ||
| rasterSource, | ||
|
|
@@ -44,9 +59,23 @@ export default function olMain({ shape, tiles, colors, opacity }) { | |
| const boundaryLayer = clipRaster.boundaryLayer; | ||
| shapeSource = clipRaster.shapeSource; | ||
|
|
||
| map = initMap({ rasterLayer, clipLayer, boundaryLayer }); | ||
| let baseMapLayerLoaded = baseMapLayerLoader(url); | ||
| // console.log(`baseMapLayerLoaded`, baseMapLayerLoaded); | ||
| baseMapLayer = baseMapLayerLoaded.baseMapLayer; | ||
| // console.log(`baseMapLayer`, baseMapLayer); | ||
| baseMapSource = baseMapLayerLoaded.baseMapSource; | ||
| // console.log(`baseMapSource`, baseMapSource); | ||
|
||
|
|
||
| map = initMap({ rasterLayer, clipLayer, boundaryLayer, baseMapLayer }); | ||
| setMap(map); | ||
| addSearchControl(map); | ||
| dragMap(map); | ||
| return { map, rasterSource, rasterLayer, shapeSource, rasterColorSource }; | ||
| return { | ||
| map, | ||
| rasterSource, | ||
| rasterLayer, | ||
| shapeSource, | ||
| rasterColorSource, | ||
| baseMapSource, | ||
| }; | ||
| } | ||
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.
This must not be part of the code