├── src ├── NeshanMap.css ├── setupTests.js ├── loaders │ └── neshan_map_loader.js ├── NeshanMap.js ├── index.js └── serviceWorker.js ├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── .gitignore ├── package.json └── README.md /src/NeshanMap.css: -------------------------------------------------------------------------------- 1 | @import url('https://static.neshan.org/sdk/leaflet/1.4.0/leaflet.css'); 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeshanMaps/react-neshan-map-leaflet/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeshanMaps/react-neshan-map-leaflet/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeshanMaps/react-neshan-map-leaflet/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/loaders/neshan_map_loader.js: -------------------------------------------------------------------------------- 1 | const BASE_URL = "https://static.neshan.org"; 2 | const DEFAULT_URL = `${BASE_URL}/sdk/leaflet/1.4.0/leaflet.js`; 3 | 4 | export default (props) => { 5 | const createScript = () => { 6 | const { onError, onLoad } = props; 7 | const script = document.createElement("script"); 8 | 9 | script.src = DEFAULT_URL; 10 | 11 | script.onload = () => { 12 | if (onLoad) onLoad(); 13 | return; 14 | }; 15 | 16 | script.onerror = () => { 17 | if (onError) onError(); 18 | return; 19 | }; 20 | 21 | document.body.appendChild(script); 22 | }; 23 | 24 | return createScript(); 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-neshan-map-leaflet", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.5.0", 8 | "@testing-library/user-event": "^7.2.1", 9 | "react": "^16.13.1", 10 | "react-dom": "^16.13.1", 11 | "react-scripts": "3.4.1" 12 | }, 13 | "scripts": { 14 | "start": "react-scripts start", 15 | "build": "react-scripts build", 16 | "test": "react-scripts test", 17 | "eject": "react-scripts eject" 18 | }, 19 | "eslintConfig": { 20 | "extends": "react-app" 21 | }, 22 | "browserslist": { 23 | "production": [ 24 | ">0.2%", 25 | "not dead", 26 | "not op_mini all" 27 | ], 28 | "development": [ 29 | "last 1 chrome version", 30 | "last 1 firefox version", 31 | "last 1 safari version" 32 | ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/NeshanMap.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef } from "react"; 2 | import neshan_map_loader from "./loaders/neshan_map_loader"; 3 | import "./NeshanMap.css"; 4 | 5 | const NeshanMap = (props) => { 6 | const { style, options, onInit } = props; 7 | const mapEl = useRef(null); 8 | 9 | const defaultStyle = { 10 | width: "600px", 11 | height: "450px", 12 | margin: 0, 13 | padding: 0, 14 | background: "#eee", 15 | }; 16 | 17 | const defaultOptions = { 18 | key: "YOUR_API_KEY", 19 | maptype: "dreamy", 20 | poi: true, 21 | traffic: false, 22 | center: [35.699739, 51.338097], 23 | zoom: 14, 24 | }; 25 | 26 | useEffect(() => { 27 | neshan_map_loader({ 28 | onLoad: () => { 29 | let map = new window.L.Map(mapEl.current, { ...defaultOptions, ...options }); 30 | if (onInit) onInit(window.L, map); 31 | }, 32 | onError: () => { 33 | console.error("Neshan Maps Error: This page didn't load Neshan Maps correctly"); 34 | }, 35 | }); 36 | }); 37 | return
; 38 | }; 39 | 40 | export default NeshanMap; 41 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import * as serviceWorker from "./serviceWorker"; 4 | import NeshanMap from "./NeshanMap"; 5 | 6 | ReactDOM.render( 7 | 8 | { 18 | let marker = L.marker([35.699739, 51.338097]) 19 | .addTo(myMap) 20 | .bindPopup("Hello world!
I am a popup."); 21 | myMap.on("click", function (e) { 22 | marker.setLatLng(e.latlng); 23 | }); 24 | 25 | L.circle([35.699739, 51.348097], { 26 | color: "red", 27 | fillColor: "#f03", 28 | fillOpacity: 0.5, 29 | radius: 500, 30 | }).addTo(myMap); 31 | }} 32 | /> 33 |
, 34 | document.getElementById("root") 35 | ); 36 | 37 | // If you want your app to work offline and load faster, you can change 38 | // unregister() to register() below. Note this comes with some pitfalls. 39 | // Learn more about service workers: https://bit.ly/CRA-PWA 40 | serviceWorker.unregister(); 41 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⚛️ React component for 🍃 Neshan Leaflet map. 2 | 3 | ### Developed by [Neshan Maps Platform](https://platform.neshan.org). 4 | #### [Neshan Maps React Component - Farsi/Persian Document](https://platform.neshan.org/react-component/). 5 | 6 | 7 | 8 | ## Getting started 9 | 10 | ### This version is deprecated. Check out the latest version [here](https://platform.neshan.org/react-component/). 11 | 12 | 13 | In the simple case you just need to add `options` prop to `NeshanMap` component and import [`NeshanLeaflet`](https://static.neshan.org/sdk/leaflet/1.4.0/leaflet.css) stylesheet. 14 | 15 | 16 | ```javascript 17 | import React from 'react'; 18 | import NeshanMap from 'react-neshan-map-leaflet' 19 | 20 | import './SimpleMap.css'; 21 | 22 | function SimpleMap() { 23 | return ( 24 | 34 | ); 35 | } 36 | 37 | export default SimpleMap; 38 | 39 | ``` 40 | 41 | ## Installation 42 | 43 | npm: 44 | ``` 45 | npm i react-neshan-map-leaflet 46 | ``` 47 | 48 | ## Features 49 | 50 | ### Neshan Maps API Loads on Demand 51 | 52 | There is no need to place a `