mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
* add README for installing /app [#244]
This commit is contained in:
4
app/README.md
Normal file
4
app/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Install
|
||||||
|
|
||||||
|
* First go to the `/js` directory in the root of the PMTiles repository and `npm install`
|
||||||
|
* `npm run dev` to start the app on port 3000
|
||||||
@@ -59,6 +59,7 @@ function App() {
|
|||||||
|
|
||||||
let [errorDisplay, setErrorDisplay] = useState<string | undefined>();
|
let [errorDisplay, setErrorDisplay] = useState<string | undefined>();
|
||||||
let [file, setFile] = useState<PMTiles | undefined>();
|
let [file, setFile] = useState<PMTiles | undefined>();
|
||||||
|
let [mapHashPassed, setMapHashPassed] = useState<boolean>(false);
|
||||||
|
|
||||||
// initial load
|
// initial load
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -67,6 +68,9 @@ function App() {
|
|||||||
let initialValue = new PMTiles(loadUrl);
|
let initialValue = new PMTiles(loadUrl);
|
||||||
setFile(initialValue);
|
setFile(initialValue);
|
||||||
}
|
}
|
||||||
|
if (location.hash.includes("map")) {
|
||||||
|
setMapHashPassed(true);
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -110,7 +114,11 @@ function App() {
|
|||||||
</GithubA>
|
</GithubA>
|
||||||
</GithubLink>
|
</GithubLink>
|
||||||
</Header>
|
</Header>
|
||||||
{file ? <Loader file={file} /> : <Start setFile={setFile} />}
|
{file ? (
|
||||||
|
<Loader file={file} mapHashPassed={mapHashPassed} />
|
||||||
|
) : (
|
||||||
|
<Start setFile={setFile} />
|
||||||
|
)}
|
||||||
<DialogPrimitive.Root open={errorDisplay !== undefined}>
|
<DialogPrimitive.Root open={errorDisplay !== undefined}>
|
||||||
<DialogPrimitive.Portal>
|
<DialogPrimitive.Portal>
|
||||||
<StyledOverlay />
|
<StyledOverlay />
|
||||||
|
|||||||
@@ -70,12 +70,14 @@ const ToolbarLink = StyledLink;
|
|||||||
const ToolbarToggleGroup = StyledToggleGroup;
|
const ToolbarToggleGroup = StyledToggleGroup;
|
||||||
const ToolbarToggleItem = StyledToggleItem;
|
const ToolbarToggleItem = StyledToggleItem;
|
||||||
|
|
||||||
function Loader(props: { file: PMTiles }) {
|
function Loader(props: { file: PMTiles; mapHashPassed: boolean }) {
|
||||||
let [tab, setTab] = useState("maplibre");
|
let [tab, setTab] = useState("maplibre");
|
||||||
|
|
||||||
let view;
|
let view;
|
||||||
if (tab === "maplibre") {
|
if (tab === "maplibre") {
|
||||||
view = <MaplibreMap file={props.file} />;
|
view = (
|
||||||
|
<MaplibreMap file={props.file} mapHashPassed={props.mapHashPassed} />
|
||||||
|
);
|
||||||
} else if (tab === "inspector") {
|
} else if (tab === "inspector") {
|
||||||
view = <Inspector file={props.file} />;
|
view = <Inspector file={props.file} />;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ const vectorStyle = async (file: PMTiles): Promise<any> => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function MaplibreMap(props: { file: PMTiles }) {
|
function MaplibreMap(props: { file: PMTiles; mapHashPassed: boolean }) {
|
||||||
let mapContainerRef = useRef<HTMLDivElement>(null);
|
let mapContainerRef = useRef<HTMLDivElement>(null);
|
||||||
let [hamburgerOpen, setHamburgerOpen] = useState<boolean>(true);
|
let [hamburgerOpen, setHamburgerOpen] = useState<boolean>(true);
|
||||||
let [showAttributes, setShowAttributes] = useState<boolean>(false);
|
let [showAttributes, setShowAttributes] = useState<boolean>(false);
|
||||||
@@ -437,11 +437,7 @@ function MaplibreMap(props: { file: PMTiles }) {
|
|||||||
if (mapRef.current) {
|
if (mapRef.current) {
|
||||||
let map = mapRef.current;
|
let map = mapRef.current;
|
||||||
let header = await props.file.getHeader();
|
let header = await props.file.getHeader();
|
||||||
if (
|
if (!props.mapHashPassed) {
|
||||||
map.getCenter().lng === INITIAL_LNG &&
|
|
||||||
map.getCenter().lat == INITIAL_LAT &&
|
|
||||||
map.getZoom() === INITIAL_ZOOM
|
|
||||||
) {
|
|
||||||
// the map hash was not passed, so auto-detect the initial viewport based on metadata
|
// the map hash was not passed, so auto-detect the initial viewport based on metadata
|
||||||
map.fitBounds(
|
map.fitBounds(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user