├── .babelrc ├── .github └── workflows │ └── release.yml ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── mapir.css └── stackblitz.png ├── components ├── MapirRaster.js └── MarkerComponent.js ├── demo ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── mapir.js ├── package-lock.json ├── package.json └── rollup.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "test": { 4 | "presets": [["@babel/preset-env"], "@babel/preset-react"] 5 | } 6 | }, 7 | "presets": [ 8 | [ 9 | "@babel/preset-env", 10 | { 11 | "modules": false 12 | } 13 | ], 14 | "@babel/preset-react" 15 | ], 16 | "ignore": ["node_modules/**"], 17 | "plugins": ["@babel/plugin-transform-runtime"] 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | release: 8 | name: Release 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 🛎️ 12 | uses: actions/checkout@v2 13 | - name: Setup Node.js 14 | uses: actions/setup-node@v1 15 | with: 16 | node-version: 14 17 | - name: Bundle 📦 18 | run: | 19 | npm install 20 | npm run build 21 | - name: Install and Build 🔧 22 | run: | 23 | npm install 24 | npm run build 25 | working-directory: demo 26 | - name: Deploy 🚀 27 | uses: JamesIves/github-pages-deploy-action@3.7.1 28 | with: 29 | GITHUB_TOKEN: ${{ secrets.GH_ACTIONS }} 30 | BRANCH: gh-pages # The branch the action should deploy to. 31 | FOLDER: demo/build # The folder the action should deploy. 32 | CLEAN: true # Automatically remove deleted files from the deploy branch 33 | - name: Publish 📤 34 | uses: JS-DevTools/npm-publish@v1 35 | with: 36 | token: ${{ secrets.NPM_TOKEN }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | dist/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Shiveh Software Co. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MapirReactComponent 2 | 3 | [![npm version](https://badge.fury.io/js/mapir-react-component.svg)](https://www.npmjs.com/package/mapir-react-component) 4 | 5 | ![Map.ir](https://map.ir/css/images/mapir-logo.png) React wrapper for mapbox-gl-js. Expose a bunch of component meant to be simple to use for React. 6 | 7 | ## Get API Key 8 | 9 | 🔑 You should first get api key from [Map.ir](https://corp.map.ir/registration/) 10 | 11 | ## Installation 12 | 13 | ``` 14 | npm i mapir-react-component 15 | ``` 16 | 17 | ## Quick start 18 | 19 | ### Import module 20 | 21 | ```jsx 22 | import Mapir from 'mapir-react-component'; 23 | import 'mapir-react-component/dist/index.css'; 24 | ``` 25 | 26 | ### Set API Key 27 | 28 | ```jsx 29 | const Map = Mapir.setToken({ 30 | transformRequest: (url) => { 31 | return { 32 | url: url, 33 | headers: { 34 | 'x-api-key': 'Your_API_KEY', //Mapir api key 35 | 'Mapir-SDK': 'reactjs', 36 | }, 37 | }; 38 | }, 39 | }); 40 | ``` 41 | 42 | ### Generate Component 43 | 44 | ```jsx 45 | render () { 46 | return ( 47 | 51 | ) 52 | } 53 | ``` 54 | 55 | [![Edit mapir-react](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/objective-ganguly-st4od?fontsize=14) 56 | 57 | [![Edit stackblitz](./assets/stackblitz.png)](https://react-fgwfsq.stackblitz.io) 58 | 59 | 📖 [English Documentation](https://github.com/map-ir/mapir-react-component/wiki/Documentation) 60 | 61 | 📖 [Persian Documentation](https://support.map.ir/developers/components/reactjs/) 62 | -------------------------------------------------------------------------------- /assets/mapir.css: -------------------------------------------------------------------------------- 1 | .mapboxgl-canvas { 2 | position: relative !important; 3 | } 4 | 5 | .mapboxgl-ctrl { 6 | display: block !important; 7 | } 8 | 9 | a.mapboxgl-ctrl-logo.mapboxgl-compact { 10 | width: 80px !important; 11 | } 12 | .mapboxgl-ctrl.mapboxgl-ctrl-attrib.mapboxgl-attrib-empty:nth-child(2){ 13 | display: none !important; 14 | } 15 | 16 | .mapboxgl-compact { 17 | display: block; 18 | } 19 | 20 | .mapboxgl-compact:nth-child(2) { 21 | display: none; 22 | } 23 | 24 | .mapboxgl-ctrl-attrib-inner:after { 25 | content: "© Map © Openstreetmap"; 26 | } 27 | 28 | 29 | a.mapboxgl-ctrl-logo { 30 | background-position: center; 31 | background-repeat: no-repeat; 32 | background-size: contain; 33 | opacity: .85; 34 | bottom: 5px; 35 | position: relative; 36 | margin: 0 0 -3px -3px !important; 37 | display: block; 38 | cursor: pointer; 39 | background-image:url(https://map.ir/css/images/mapir-logo.svg) !important; 40 | } 41 | -------------------------------------------------------------------------------- /assets/stackblitz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/map-ir/mapir-react-component/5847e9037385cfe5642577ff191283c8ad3a35d1/assets/stackblitz.png -------------------------------------------------------------------------------- /components/MapirRaster.js: -------------------------------------------------------------------------------- 1 | // function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } 2 | 3 | import React from 'react'; 4 | import { Source } from 'react-mapbox-gl'; 5 | 6 | class MapirRaster extends React.Component { 7 | constructor(props) { 8 | super(props); 9 | } 10 | 11 | componentDidMount() { 12 | fetch(`https://map.ir/vector/load?x-api-key=${this.props.apiKey}`, { 13 | method: 'POST', 14 | }) 15 | .then(function (res) {}) 16 | .catch(function (err) {}); 17 | } 18 | 19 | render() { 20 | return ( 21 | 32 | ); 33 | // return React.createElement(Source, _extends({}, this.props, { 34 | // id: "source_id", 35 | // tileJsonSource: { 36 | // "type": "raster", 37 | // "tiles": [ 38 | // `https://map.ir/vector/mobile/1.0.0/Shiveh:Shiveh@EPSG:3857@png/{z}/{x}/{y}.png?x-api-key=${this.props.apiKey}`, 39 | // ], 40 | // "tileSize": 512 41 | // } 42 | // })); 43 | } 44 | } 45 | 46 | export default MapirRaster; 47 | -------------------------------------------------------------------------------- /components/MarkerComponent.js: -------------------------------------------------------------------------------- 1 | // function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } 2 | 3 | import React, { Component } from 'react'; 4 | import { Marker } from 'react-mapbox-gl'; 5 | 6 | export default class MarkerComponent extends Component { 7 | constructor(props) { 8 | super(props); 9 | } 10 | 11 | render() { 12 | return ( 13 | 18 | 25 | 26 | ); 27 | // return React.createElement(Marker, _extends({}, this.props, { 28 | // coordinates:this.props.coordinates || [51.420470, 35.729054], 29 | // anchor:this.props.anchor || "bottom" 30 | // }, 31 | // ),React.createElement('img',{ 32 | // style:{width:'3rem'}, 33 | // src: this.props.Image || "https://map.ir/css/images/marker-default-red.svg" 34 | // })); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demo/.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 | -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "/mapir-react-component-demo", 6 | "dependencies": { 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "4.0.3", 13 | "web-vitals": "^1.1.2", 14 | "mapir-react-component": "file:.." 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /demo/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/map-ir/mapir-react-component/5847e9037385cfe5642577ff191283c8ad3a35d1/demo/public/favicon.ico -------------------------------------------------------------------------------- /demo/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 | -------------------------------------------------------------------------------- /demo/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/map-ir/mapir-react-component/5847e9037385cfe5642577ff191283c8ad3a35d1/demo/public/logo192.png -------------------------------------------------------------------------------- /demo/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/map-ir/mapir-react-component/5847e9037385cfe5642577ff191283c8ad3a35d1/demo/public/logo512.png -------------------------------------------------------------------------------- /demo/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 | -------------------------------------------------------------------------------- /demo/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /demo/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/src/App.js: -------------------------------------------------------------------------------- 1 | import Mapir from 'mapir-react-component'; 2 | import 'mapir-react-component/dist/index.css'; 3 | import './App.css'; 4 | 5 | const apiKey = 6 | 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjVkMjhhOGY5YzRlMzBlZmM3NTFhYjRkYWQ1Y2QyMDczNzllMTViM2ZjOTg3MzljYzIxNTYyYjYwNWRkMzc2YmFlZmIxNWZhY2ZlYjUyNmYwIn0.eyJhdWQiOiI2OTgwIiwianRpIjoiNWQyOGE4ZjljNGUzMGVmYzc1MWFiNGRhZDVjZDIwNzM3OWUxNWIzZmM5ODczOWNjMjE1NjJiNjA1ZGQzNzZiYWVmYjE1ZmFjZmViNTI2ZjAiLCJpYXQiOjE1NzU5NTYyNzUsIm5iZiI6MTU3NTk1NjI3NSwiZXhwIjoxNTc4NDYxODc1LCJzdWIiOiIiLCJzY29wZXMiOlsiYmFzaWMiXX0.Fx_r1Rguxm3Gtp_RDGxSbjhm67w-f_tldO0AHAyr1-L9JkGKgnaVBNWv4_x1qdjk6I6biCXAKpB5jafrUsp8bRS11pz2Tg0G80vaGb891_XF97pT-WGVV3J_H447tiC5JHj7ZSRodOsiVc8EblsX2BmxgewKyHYqs-6YGHYrVro_-xzNRl8EoXzDZtV34HqUWA0IQ5nqhVW39eIWzu6dmySKfSFoLRcOL9-8qC8p2jk9_siki9k3RBt5NVJyl8rOPHASy6yuqABWyeZZV5N8qELqiipP-Ka_zjc0DgrxwSE1AdvxdNDhZO7x7v72X0eM3oWvFMpwGqI5pRzIOpASiw'; 7 | const Map = Mapir.setToken({ 8 | transformRequest: (url) => { 9 | return { 10 | url: url, 11 | headers: { 12 | 'x-api-key': apiKey, //Mapir api key 13 | 'Mapir-SDK': 'reactjs', 14 | }, 15 | }; 16 | }, 17 | }); 18 | 19 | function App() { 20 | return ( 21 |
22 | 23 | 24 | 25 | 26 |
27 | ); 28 | } 29 | 30 | export default App; 31 | -------------------------------------------------------------------------------- /demo/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /demo/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /demo/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /demo/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demo/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /demo/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'; 6 | -------------------------------------------------------------------------------- /mapir.js: -------------------------------------------------------------------------------- 1 | // function _extends() { 2 | // _extends = 3 | // Object.assign || 4 | // function (target) { 5 | // for (var i = 1; i < arguments.length; i++) { 6 | // var source = arguments[i]; 7 | // for (var key in source) { 8 | // if (Object.prototype.hasOwnProperty.call(source, key)) { 9 | // target[key] = source[key]; 10 | // } 11 | // } 12 | // } 13 | // return target; 14 | // }; 15 | // return _extends.apply(this, arguments); 16 | // } 17 | 18 | import React from 'react'; 19 | import ReactMapboxGl, { 20 | Layer, 21 | Feature, 22 | GeoJSONLayer, 23 | Source, 24 | Image, 25 | ZoomControl, 26 | ScaleControl, 27 | RotationControl, 28 | Popup, 29 | Cluster, 30 | } from 'react-mapbox-gl'; 31 | import MapirRaster from './components/MapirRaster.js'; 32 | import MarkerComponent from './components/MarkerComponent.js'; 33 | import { 34 | setRTLTextPlugin, 35 | GeolocateControl, 36 | AttributionControl, 37 | } from 'mapbox-gl'; 38 | import DrawControl from 'react-mapbox-gl-draw'; 39 | import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'; 40 | import 'mapbox-gl/dist/mapbox-gl.css'; 41 | import './assets/mapir.css'; 42 | 43 | setRTLTextPlugin( 44 | 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js' 45 | ); 46 | 47 | class Mapir extends React.Component { 48 | constructor(props) { 49 | super(props); 50 | this.setAttribution = this.setAttribution.bind(this); 51 | } 52 | 53 | componentDidMount() { 54 | fetch(`https://map.ir/vector/load?x-api-key=${this.props.apiKey}`, { 55 | method: 'POST', 56 | }) 57 | .then(function (res) {}) 58 | .catch(function (err) {}); 59 | } 60 | 61 | setAttribution(map) { 62 | if (this.props?.onStyleLoad) this.props.onStyleLoad(); 63 | if (this.props.userLocation) { 64 | map.addControl( 65 | new GeolocateControl({ 66 | positionOptions: { 67 | enableHighAccuracy: false, 68 | timeout: 5000, 69 | maximumAge: 10000, 70 | }, 71 | trackUserLocation: true, 72 | }) 73 | ); 74 | } 75 | const getElement = document.getElementsByClassName('mapboxgl-ctrl-logo'); 76 | // getElement[0].href = 'http://map.ir'; 77 | map.addControl(new AttributionControl({ compact: true })); 78 | } 79 | 80 | render() { 81 | const Map = this.props.Map; 82 | const onStyleLoadProp = this.props.onStyleLoad 83 | 84 | return ( 85 | { 101 | this.setAttribution(map); 102 | if(onStyleLoadProp) onStyleLoadProp(map); 103 | }} 104 | /> 105 | ); 106 | 107 | // return React.createElement( 108 | // Map, 109 | // _extends({}, this.props, { 110 | // style: 111 | // this.props.style || 112 | // `https://map.ir/vector/styles/main/mapir-xyz-style.json`, 113 | // minZoom: this.props.minZoom || 12, 114 | // center: this.props.center || [51.42047, 35.729054], 115 | // tms: true, 116 | // containerStyle: this.props.containerStyle || { 117 | // height: '100vh', 118 | // width: '100vw', 119 | // }, 120 | 121 | // onStyleLoad: (map) => this.setAttribution(map), 122 | // }) 123 | // ); 124 | } 125 | } 126 | 127 | Mapir.Layer = Layer; 128 | Mapir.Feature = Feature; 129 | Mapir.Raster = MapirRaster; 130 | Mapir.Source = Source; 131 | Mapir.GeoJSONLayer = GeoJSONLayer; 132 | Mapir.Image = Image; 133 | Mapir.ZoomControl = ZoomControl; 134 | Mapir.ScaleControl = ScaleControl; 135 | Mapir.RotationControl = RotationControl; 136 | Mapir.Popup = Popup; 137 | Mapir.Marker = MarkerComponent; 138 | Mapir.Cluster = Cluster; 139 | Mapir.setToken = ReactMapboxGl; 140 | Mapir.DrawControl = DrawControl; 141 | 142 | export default Mapir; 143 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "mapir-react-component@2.0.7", 3 | "_id": "mapir-react-component@2.0.7", 4 | "_inBundle": false, 5 | "_integrity": "sha512-xh1IY2laBWHlbKy08ohmHSGvknSHvLi10wIxVKvUKlSq2TCaqiSXdErGsAFJ3I3YcDMPiwGmA+dhjOOJtMI2sA==", 6 | "_location": "/mapir-react-component", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "version", 10 | "registry": true, 11 | "raw": "mapir-react-component@2.0.7", 12 | "name": "mapir-react-component", 13 | "escapedName": "mapir-react-component", 14 | "rawSpec": "2.0.7", 15 | "saveSpec": null, 16 | "fetchSpec": "2.0.7" 17 | }, 18 | "_requiredBy": [ 19 | "#USER", 20 | "/" 21 | ], 22 | "_resolved": "https://registry.npmjs.org/mapir-react-component/-/mapir-react-component-2.0.7.tgz", 23 | "_shasum": "a0a8e12de4f4964c025b8ab134a3711c4d33e3e7", 24 | "_spec": "mapir-react-component@2.0.7", 25 | "_where": "/Users/reyhane/Documents/Shiveh/demo", 26 | "author": { 27 | "name": "reyhane masumi", 28 | "email": "r.masumi94@gmail.com" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/map-ir/mapir-react-component/issues" 32 | }, 33 | "bundleDependencies": false, 34 | "dependencies": { 35 | "@mapbox/mapbox-gl-draw": "^1.3.0", 36 | "mapbox-gl": "^1.13.1", 37 | "react-mapbox-gl": "^5.1.1", 38 | "react-mapbox-gl-draw": "^2.0.4" 39 | }, 40 | "deprecated": false, 41 | "description": " ", 42 | "devDependencies": { 43 | "@babel/core": "^7.15.5", 44 | "@babel/plugin-transform-runtime": "^7.15.0", 45 | "@babel/preset-env": "^7.15.6", 46 | "@babel/preset-react": "^7.14.5", 47 | "@rollup/plugin-babel": "^5.3.0", 48 | "@rollup/plugin-commonjs": "^20.0.0", 49 | "@rollup/plugin-node-resolve": "^13.0.4", 50 | "autoprefixer": "^10.3.4", 51 | "cross-env": "^7.0.3", 52 | "eslint": "^7.32.0", 53 | "eslint-config-airbnb": "^18.2.1", 54 | "eslint-plugin-import": "^2.24.2", 55 | "eslint-plugin-jsx-a11y": "^6.4.1", 56 | "eslint-plugin-react": "^7.26.0", 57 | "istanbul": "^0.4.5", 58 | "rollup": "^2.56.3", 59 | "rollup-plugin-filesize": "^9.1.1", 60 | "rollup-plugin-peer-deps-external": "^2.2.4", 61 | "rollup-plugin-postcss": "^4.0.1", 62 | "postcss": "^8.3.6" 63 | }, 64 | "peerDependencies": { 65 | "react": "^17.0.2", 66 | "react-dom": "^17.0.2" 67 | }, 68 | "homepage": "https://github.com/map-ir/mapir-react-component#readme", 69 | "keywords": [ 70 | "mapir", 71 | "react", 72 | "npm", 73 | "module", 74 | "node", 75 | "javascript" 76 | ], 77 | "license": "MIT", 78 | "main": "dist/index.cjs.js", 79 | "module": "dist/index.esm.js", 80 | "browser": "dist/index.js", 81 | "style": "dist/index.css", 82 | "files": [ 83 | "dist" 84 | ], 85 | "name": "mapir-react-component", 86 | "presets": [ 87 | "es2015", 88 | "react" 89 | ], 90 | "repository": { 91 | "type": "git", 92 | "url": "git+https://github.com/map-ir/mapir-react-component.git" 93 | }, 94 | "scripts": { 95 | "build": "rollup -c", 96 | "lint": "eslint src test" 97 | }, 98 | "version": "2.0.7" 99 | } 100 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from '@rollup/plugin-babel'; 2 | import resolve from '@rollup/plugin-node-resolve'; 3 | import commonjs from '@rollup/plugin-commonjs'; 4 | import postcss from 'rollup-plugin-postcss'; 5 | import filesize from 'rollup-plugin-filesize'; 6 | import autoprefixer from 'autoprefixer'; 7 | 8 | import pkg from './package.json'; 9 | 10 | const INPUT_FILE_PATH = 'mapir.js'; 11 | const OUTPUT_NAME = 'dist'; 12 | 13 | const GLOBALS = { 14 | react: 'React', 15 | 'react-dom': 'ReactDOM', 16 | 'prop-types': 'PropTypes', 17 | }; 18 | 19 | const PLUGINS = [ 20 | postcss({ 21 | extract: true, 22 | plugins: [autoprefixer], 23 | }), 24 | babel({ 25 | babelHelpers: 'runtime', 26 | exclude: 'node_modules/**', 27 | }), 28 | resolve({ 29 | browser: true, 30 | resolveOnly: [/^(?!react$)/, /^(?!react-dom$)/, /^(?!prop-types)/], 31 | }), 32 | commonjs(), 33 | filesize(), 34 | ]; 35 | 36 | const EXTERNAL = ['react', 'react-dom', 'prop-types']; 37 | 38 | // https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers 39 | const CJS_AND_ES_EXTERNALS = EXTERNAL.concat(/@babel\/runtime/); 40 | 41 | const OUTPUT_DATA = [ 42 | { 43 | file: pkg.browser, 44 | format: 'umd', 45 | }, 46 | { 47 | file: pkg.main, 48 | format: 'cjs', 49 | }, 50 | { 51 | file: pkg.module, 52 | format: 'es', 53 | }, 54 | ]; 55 | 56 | const config = OUTPUT_DATA.map(({ file, format }) => ({ 57 | input: INPUT_FILE_PATH, 58 | output: { 59 | file, 60 | format, 61 | name: OUTPUT_NAME, 62 | globals: GLOBALS, 63 | }, 64 | external: ['cjs', 'es'].includes(format) ? CJS_AND_ES_EXTERNALS : EXTERNAL, 65 | plugins: PLUGINS, 66 | })); 67 | 68 | export default config; 69 | --------------------------------------------------------------------------------