diff --git a/home/App.tsx b/home/App.tsx index e9ae043..aa4954f 100644 --- a/home/App.tsx +++ b/home/App.tsx @@ -5,6 +5,7 @@ import DynamicRoute from "./DynamicRoute"; import Polygons from "./Polygons"; import Element from "./Element"; import RouteInfo from './RouteInfo' +import MapElement from './MapElement' declare global { interface Window { @@ -17,6 +18,7 @@ const App = () => { <> + diff --git a/home/Home.tsx b/home/Home.tsx index 49f5b7d..1b4678a 100644 --- a/home/Home.tsx +++ b/home/Home.tsx @@ -8,7 +8,7 @@ import GitHubButton from 'react-github-btn'; import ScrollDown from "./components/ScrollDown"; const code = ` - + ` const SHome = styled(Section)` @@ -17,6 +17,10 @@ const SHome = styled(Section)` align-items: center; `; +const SGettingStarted = styled.div` + margin-top: 1em; +` + const Home = () => { return ( @@ -24,9 +28,20 @@ const Home = () => {

react-mapycz

Easy-to-use integration of Mapy.cz into React using Mapy.cz API.

Star + + Getting started +

Install library and peer dependencies

+ + npm i react-mapycz react-dom@16.13.1 react@16.13.1 + +

or

+ + yarn add react-mapycz react-dom@16.13.1 react@16.13.1 + +
- + { {code}
- +
) } -export default Home; \ No newline at end of file +export default Home; diff --git a/home/MapElement.tsx b/home/MapElement.tsx new file mode 100644 index 0000000..83d110e --- /dev/null +++ b/home/MapElement.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import styled from "styled-components"; +import {Map} from "../src"; +import {githubGist} from "react-syntax-highlighter/dist/esm/styles/hljs"; +import SyntaxHighlighter from "react-syntax-highlighter"; +import Section from "./components/Section"; +import ScrollDown from "./components/ScrollDown"; + +const SMapElement = styled(Section)` + display: flex; + justify-content: space-evenly; + align-items: center; +`; + +const MapElement = () => { + const code = ` + + ` + return ( + +
+

Map

+

Map is a main element of react-mapycz library.

+

Available properties:

+
    +
  • center: optional Center coords
  • +
  • width: optional Element width, defaults to 100%
  • +
  • height: optional Element height, defaults to 300px
  • +
  • zoom: optional Default map zoom, defaults to 13
  • +
  • minZoom: optional Minimal map zoom, defaults to 1
  • +
  • maxZoom: optional Max map zoom, defaults to 21
  • +
  • baseLayers: optional Map layers, array of values from BaseLayers
  • +
+
+
+ + + {code} + +
+ +
+ ) +} + +export default MapElement; diff --git a/src/Map.tsx b/src/Map.tsx index 08db793..b4c13a8 100644 --- a/src/Map.tsx +++ b/src/Map.tsx @@ -9,7 +9,7 @@ export const MapContext = createContext(null) export type MapEventListener = (e: MapEvent, coordinates: Coordinates) => void export interface MapProps { - center: { lat: number, lng: number }; + center?: { lat: number, lng: number }; width?: string; height?: string; zoom?: number; @@ -31,8 +31,8 @@ const StyledMap = styled.div` ` const handleEventListener = (e: MapEvent, sMap: unknown, onEvent: MapEventListener) => { - const coordinates = (e?.data?.event) - ? window.SMap.Coords.fromEvent(e.data.event, sMap) + const coordinates = (e?.data?.event) + ? window.SMap.Coords.fromEvent(e.data.event, sMap) : null; onEvent(e, coordinates) } @@ -44,7 +44,7 @@ const Map = (props: MapProps) => { useEffect(() => { if (!map && mapNode) { - const centerCoords = window.SMap.Coords.fromWGS84(center.lng, center.lat); + const centerCoords = center ? window.SMap.Coords.fromWGS84(center.lng, center.lat) : undefined; const sMap = new window.SMap(mapNode.current, centerCoords, zoom); const l = sMap.addDefaultLayer(BaseLayers.TURIST_NEW); l.enable(); @@ -61,7 +61,7 @@ const Map = (props: MapProps) => { }, []); useEffect(() => { - if (map) { + if (map && center) { const centerCoords = window.SMap.Coords.fromWGS84(center.lng, center.lat); map.setCenter(centerCoords, animateCenterZoom); }