├── .gitignore ├── .travis.yml ├── README.md ├── bower.json ├── demo └── src │ ├── GeometryCircle.js │ ├── GeometryPolygons.js │ ├── MarkerIcon.js │ ├── MarkerLabel.js │ ├── Markers.js │ ├── Popups.js │ ├── SimpleMap.js │ └── index.js ├── nwb.config.js ├── package.json ├── src ├── Circle.js ├── CircleMarker.js ├── DivIcon.js ├── GeoJSON.js ├── Icon.js ├── Map.js ├── MapComponent.js ├── Marker.js ├── Polygon.js ├── Polyline.js ├── Popup.js ├── Rectangle.js ├── Ruler.js ├── Wkt.js └── index.js └── tests ├── .eslintrc └── index-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | /demo/dist 3 | /es6 4 | /lib 5 | /node_modules 6 | /umd 7 | npm-debug.log 8 | .idea 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | node_js: 5 | - 4.2.6 6 | 7 | cache: 8 | directories: 9 | - node_modules 10 | 11 | before_install: 12 | - npm install codecov.io coveralls 13 | - npm install nwb -g 14 | 15 | after_success: 16 | - cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js 17 | - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js 18 | 19 | branches: 20 | only: 21 | - master 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React component [Maps API 2GIS](https://github.com/2gis/mapsapi) 2 | 3 | :construction: WARNING: This package is no longer supported. Please use https://github.com/2gis/mapsapi instead. :construction: 4 | 5 | ## Installation 6 | 7 | For installation use command `npm install 2gis-maps-react 2gis-maps` 8 | 9 | [build-badge]: https://travis-ci.org/2gis/2gis-maps-react.svg?branch=master 10 | [build]: https://travis-ci.org/2gis/2gis-maps-react 11 | 12 | [npm-badge]: https://img.shields.io/npm/v/2gis-maps-react.svg?style=flat-square 13 | [npm]: https://www.npmjs.org/package/2gis-maps-react 14 | 15 | [coveralls-badge]: https://coveralls.io/repos/github/2gis/2gismaps-react/badge.svg?branch=master 16 | [coveralls]: https://coveralls.io/github/2gis/2gismaps-react?branch=master 17 | 18 | 19 | ## Getting started 20 | 21 | ##### Demo 22 | 23 | [Demo](http://2gis.github.io/2gis-maps-react/#simple-map) 24 | [Source code of the demo](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/SimpleMap.js) 25 | 26 | ##### Creation of simple map. [Api referense.](http://api.2gis.ru/doc/maps/manual/map/) 27 | 28 | A map is a basic component. 29 | For creating the map you need to specify center point, zoom level and size of dom element. 30 | 31 | ```jsx 32 | 37 | ``` 38 | 39 | ##### Creation of popup inside the map. [Api referense.](http://api.2gis.ru/doc/maps/examples/popups/) 40 | 41 | A simple popup. 42 | For setting of maxWidth, minWith and maxHeight use prop sprawling. [Demo](http://2gis.github.io/2gis-maps-react/#popups) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/Popups.js) 43 | 44 | ```jsx 45 | 50 | 53 | The content for popup 54 |

Can be HTML

55 |
56 |
57 | ``` 58 | 59 | ##### Creation of Markers and Popups on Markers. [Api referense.](http://api.2gis.ru/doc/maps/examples/markers/) 60 | 61 | Simple Marker 62 | 63 | ```jsx 64 | 69 | 72 | 73 | ``` 74 | 75 | Static and draggable markers. 76 | Popups on Markers. [Demo](http://2gis.github.io/2gis-maps-react/#markers-simple) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/Markers.js) 77 | 78 | ```jsx 79 | 84 | 89 | 92 | 93 | The content for popup 94 |

Can be HTML

95 |
96 |
97 |
98 | ``` 99 | 100 | Marker with icon and html icon. [Demo](http://2gis.github.io/2gis-maps-react/#markers-icon) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/MarkerIcon.js) 101 | 102 | ```jsx 103 | 108 | 111 | 115 | 116 | 117 | 120 | 123 |

Can be HTML

124 |
125 |
126 |
127 | ``` 128 | 129 | Marker with label and static label. [Demo](http://2gis.github.io/2gis-maps-react/#markers-label) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/MarkerLabel.js) 130 | 131 | ```jsx 132 | 137 | 141 | 142 | 146 | 147 | ``` 148 | 149 | ##### Creating of vector objects. [Api referense.](http://api.2gis.ru/doc/maps/examples/geometries/) 150 | 151 | Circle and Circle Marker. [Demo](http://2gis.github.io/2gis-maps-react/#geometry-circle) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/GeometryCircle.js) 152 | 153 | ```jsx 154 | 159 | My radius doesn't change when zooming.
He in pixels.'} 162 | radius={50} 163 | /> 164 | 165 | My radius changes when zooming.
He in meters'} 168 | radius={200} 169 | /> 170 |
171 | ``` 172 | 173 | Polygon, Polyline and Rectangle. [Demo](http://2gis.github.io/2gis-maps-react/#geometry-polygon) [Source code](https://github.com/2gis/2gis-maps-react/blob/master/demo/src/GeometryPolygons.js) 174 | 175 | ```jsx 176 | 181 | 187 | 188 | 197 | 198 | 206 | 207 | ``` 208 | 209 | ### Events 210 | 211 | For binding 2gis-mapsapi events use props similar to `onEvent` where Event is 2gis-mapsapi event with a capital first character. 212 | 213 | ### Components 214 | 215 | #### Map 216 | 217 | Required props 218 | 219 | |Prop name |Dynamic|Description | Data example | 220 | |-----------------|:-----:|-----------------------------------------|--------------| 221 | | center | ✓ |Center position of map |[54.98, 82.89]| 222 | | zoom | ✓ |Zoom level of map |15 | 223 | 224 | Optional props 225 | 226 | |Prop name |Dynamic|Description | Data example |Default value| 227 | |-----------------|:-----:|-----------------------------------------|--------------------------------- |:-----------:| 228 | | minZoom | ✘ |Minimal zoom level |10 | null | 229 | | maxZoom | ✘ |Maximal zoom level |20 | null | 230 | |maxBounds | ✘ |Bounds of map |[ [54.98, 82.89], [54.98, 82.89] ]| null | 231 | | style | ✓ |CSS style of map container |{width: "500px", height: "500px"} | null | 232 | |geoclicker | ✘ |Show popup on click about place on map |true | false | 233 | |projectDetector | ✘ |Load current user project |true | false | 234 | |zoomControl | ✘ |Show zoom control button |false | true | 235 | |fullscreenControl| ✘ |Show fullscreen control button |false | true | 236 | |preferCanvas | ✘ |Use canvas element for rendering geometry|false | true | 237 | |touchZoom | ✘ |Zooming when touch (on mobile) |false | true | 238 | |scrollWheelZoom | ✘ |Zooming when scrolling |false | true | 239 | |doubleClickZoom | ✘ |Zooming when double click |false | true | 240 | |dragging | ✘ |Dragging map |false | true | 241 | 242 | #### Popup 243 | 244 | Can be bound to Marker, Map, Polygon, Polyline, Rectangle. 245 | 246 | Required props 247 | 248 | |Prop name|Dynamic|Description | Data example | 249 | |---------|:-----:|---------------------------------------------------------|--------------| 250 | | pos | ✓ |Position on map (not use if popup inside another element)|[54.98, 82.89]| 251 | 252 | Optional props 253 | 254 | |Prop name|Dynamic|Description | Data example |Default value| 255 | |---------|:-----:|-------------------------------|--------------|:-----------:| 256 | |className| ✘ |Class name of popup dom element|example-string| - | 257 | |maxWidth | ✘ |Max width of popup | 150 | 300 | 258 | |minWidth | ✘ |Min width of popup | 150 | 50 | 259 | |maxHeight| ✘ |Max height of popup | 150 | null | 260 | |sprawling| ✘ |Popup width on map width | true | false | 261 | 262 | #### Marker 263 | 264 | Required props 265 | 266 | |Prop name|Dynamic|Description | Data example | 267 | |---------|:-----:|---------------|--------------| 268 | | pos | ✓ |Position on map|[54.98, 82.89]| 269 | 270 | Optional props 271 | 272 | |Prop name |Dynamic|Description | Data example |Default value| 273 | |-----------|:-----:|-------------------------------------------|--------------|:-----------:| 274 | | label | ✓ |Text of marker label |[54.98, 82.89]| - | 275 | |staticLabel| ✓ |Text of marker label. Label will be static.|[54.98, 82.89]| - | 276 | | draggable | ✓ |Marker is draggable | true | false | 277 | | clickable | ✓ |Marker is clickable | false | true | 278 | 279 | #### Icon 280 | 281 | Can be inside Marker. 282 | 283 | Required props 284 | 285 | |Prop name|Dynamic|Description | Data example | 286 | |---------|:-----:|------------|---------------------------------------------| 287 | | iconUrl | ✓ |Url of icon |http://maps.api.2gis.ru/2.0/example_logo.png | 288 | | iconSize| ✓ |Size of icon|[48, 48] | 289 | 290 | #### DivIcon 291 | 292 | Can be inside Marker. 293 | 294 | Required props 295 | 296 | |Prop name |Dynamic|Description | Data example |Default value| 297 | |-----------------------|:-----:|------------|---------------------------------------------|:-----------:| 298 | | iconSize | ✓ |Size of icon|[48, 48] | - | 299 | |dangerouslySetInnerHTML| ✓ | Inner html |http://maps.api.2gis.ru/2.0/example_logo.png | - | 300 | 301 | #### Ruler 302 | 303 | Required props 304 | 305 | |Prop name|Dynamic|Description | Data example | 306 | |---------|:-----:|----------------|-----------------------------------------------------------| 307 | | points | ✓ |Points of ruler |[ [54.9827,82.8958], [54.9837,82.8968], [54.9837,82.8938] ]| 308 | 309 | #### Polyline 310 | 311 | Required props 312 | 313 | |Prop name|Dynamic|Description | Data example | 314 | |---------|:-----:|----------------|-----------------------------------------------------------| 315 | | points | ✓ |Points of line |[ [54.9827,82.8958], [54.9837,82.8968], [54.9837,82.8938] ]| 316 | 317 | Optional props 318 | 319 | |Prop name|Dynamic|Description | Data example |Default value| 320 | |---------|:-----:|----------------|--------------------------------|:-----------:| 321 | | label | ✓ |Text of label |example-string | - | 322 | | style | ✓ |Style of line |{color: '#FF0000'} | - | 323 | 324 | #### Polygon 325 | 326 | Required props 327 | 328 | |Prop name|Dynamic|Description | Data example | 329 | |---------|:-----:|------------------|-----------------------------------------------------------| 330 | | points | ✓ |Points of polygon |[ [54.9827,82.8958], [54.9837,82.8968], [54.9837,82.8938] ]| 331 | 332 | Optional props 333 | 334 | |Prop name|Dynamic|Description | Data example |Default value| 335 | |---------|:-----:|----------------|-----------------------|:-----------:| 336 | | label | ✓ |Text of label |example-string | - | 337 | | style | ✓ |Style of line |{color: '#FF0000'} | - | 338 | 339 | #### Rectangle 340 | 341 | Required props 342 | 343 | |Prop name|Dynamic|Description | Data example | 344 | |---------|:-----:|--------------------|----------------------------------------| 345 | | bounds | ✓ |Bounds of rectangle |[ [54.9827,82.8958], [54.9837,82.8968] ]| 346 | 347 | Optional props 348 | 349 | |Prop name|Dynamic|Description | Data example |Default value| 350 | |---------|:-----:|----------------|-----------------------|:-----------:| 351 | | label | ✓ |Text of label |example-string | - | 352 | | style | ✓ |Style of line |{color: '#FF0000'} | - | 353 | 354 | #### Circle 355 | 356 | Required props 357 | 358 | |Prop name|Dynamic|Description | Data example | 359 | |---------|:-----:|-----------------------|-------------------| 360 | | pos | ✓ |Position on map | [54.9827,82.8958] | 361 | | radius | ✓ |Circle radius in meters| 300 | 362 | 363 | Optional props 364 | 365 | |Prop name|Dynamic|Description | Data example |Default value| 366 | |---------|:-----:|----------------|-----------------------|:-----------:| 367 | | label | ✓ |Text of label |example-string | - | 368 | | style | ✓ |Style of line |{color: '#FF0000'} | - | 369 | 370 | #### CircleMarker 371 | 372 | Required props 373 | 374 | |Prop name|Dynamic|Description | Data example | 375 | |---------|:-----:|-----------------------|-------------------| 376 | | pos | ✓ |Position on map | [54.9827,82.8958] | 377 | 378 | Optional props 379 | 380 | |Prop name|Dynamic|Description | Data example |Default value| 381 | |---------|:-----:|-----------------------|-----------------------|:-----------:| 382 | | radius | ✓ |Circle radius in pixels| 300 | 10 | 383 | | label | ✓ |Text of label |example-string | - | 384 | | style | ✓ |Style of line |{color: '#FF0000'} | - | 385 | 386 | #### Wkt 387 | 388 | Required props 389 | 390 | |Prop name|Dynamic|Description | Data example | 391 | |---------|:-----:|-----------------------|-------------------------------------------------------------| 392 | | data | ✓ |Wkt data string | POLYGON((82.9155.04, 82.91 55.04, 82.91 55.04, 82.9155.04)) | 393 | 394 | Optional props 395 | 396 | |Prop name|Dynamic|Description | Data example |Default value| 397 | |---------|:-----:|-----------------------|-------------------|:-----------:| 398 | | style | ✓ |Style of objeck | {color: '#FF0000'}| - | 399 | 400 | #### GeoJSON 401 | 402 | Required props 403 | 404 | |Prop name|Dynamic|Description | Data example | 405 | |---------|:-----:|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| 406 | | data | ✓ |GeoJSON data object | { "type": "Feature", "properties": { "address": "г. Новосибирск, пл. Карла Маркса, 7" }, "geometry": { "type": "Point", "coordinates": [82.8974, 54.9801] } }; | 407 | 408 | Optional props 409 | 410 | | Prop name |Dynamic|Description | Data example |Default value | 411 | |-------------|:-----:|---------------------------------|-------------------|:--------------------------:| 412 | |pointToLayer | ✓ |Function for render point | function() {} |Will be render simple Marker| 413 | |onEachFeature| ✓ |Function running on every element| function() {} | - | 414 | | filter | ✓ |Function for filter objects | function() {} | - | 415 | | style | ✓ |Style of object | {color: '#FF0000'}| - | 416 | 417 | ## Demo Development Server 418 | 419 | * `npm start` will run a development server with the component's demo app at [http://localhost:3000](http://localhost:3000) with hot module reloading. 420 | 421 | ## Building 422 | 423 | * `npm run build` will build the component for publishing to npm and also bundle the demo app. 424 | 425 | * `npm run clean` will delete built resources. 426 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "2gis-maps-react", 3 | "version": "0.0.3", 4 | "description": "2GIS Maps API React component", 5 | "main": "lib/index.js", 6 | "license": "MIT", 7 | "ignore": [], 8 | "authors": [], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/2gis/2gis-maps-react.git" 12 | }, 13 | "dependencies": {}, 14 | "devDependencies": { 15 | "2gis/mapsapi": "^2.2.6", 16 | "insin/nwb": "0.9.x", 17 | "reactjs/react-bower": "^15.2.1" 18 | }, 19 | "keywords": [ 20 | "2gis", 21 | "map", 22 | "api", 23 | "react-component", 24 | "web-components" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /demo/src/GeometryCircle.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { Map, CircleMarker, Circle } from '../../src/' 3 | 4 | export default class GeometryCircle extends Component { 5 | state = { 6 | zoom: 17, 7 | center: [54.9827, 82.8958], 8 | geometry: [], 9 | pos: [54.9827, 82.8958], 10 | radius: 100, 11 | type: false // If is false then Circle, if is true then Circle Marker. 12 | }; 13 | 14 | onChangePos = e => { 15 | this.setState({ 16 | pos: e.target.value.split(',') 17 | }); 18 | }; 19 | 20 | onChangeRadius = e => { 21 | this.setState({ 22 | radius: e.target.value 23 | }); 24 | }; 25 | 26 | onChangeCircleType = e => { 27 | if (e.target.value) { 28 | this.setState({ 29 | type: false 30 | }); 31 | } 32 | }; 33 | 34 | onChangeCircleMarkerType = e => { 35 | if (e.target.value) { 36 | this.setState({ 37 | type: true 38 | }); 39 | } 40 | }; 41 | 42 | addElement = e => { 43 | let geometry = this.state.geometry; 44 | const pos = this.state.pos; 45 | const radius = this.state.radius; 46 | 47 | if (this.state.type) { 48 | geometry.push( 49 | 58 | ); 59 | } 60 | else { 61 | geometry.push( 62 | 68 | ); 69 | } 70 | this.setState({ 71 | geometry: geometry 72 | }); 73 | }; 74 | 75 | deleteElement = e => { 76 | let geometry = this.state.geometry; 77 | geometry.pop(); 78 | this.setState({ 79 | geometry: geometry 80 | }); 81 | }; 82 | 83 | render() { 84 | return ( 85 |
86 | 87 | 88 |
89 | 90 | 91 | 92 |
93 | 94 |
95 | 96 |
97 | 98 |
99 | 100 | 105 | { this.state.geometry } 106 | 107 |
108 | ); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /demo/src/GeometryPolygons.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { Map, Polygon, Rectangle , Polyline} from '../../src/' 3 | 4 | export default class GeometryPolygons extends Component { 5 | state = { 6 | zoom: 17, 7 | center: [54.9827, 82.8958], 8 | polygons: [], 9 | points: [ 10 | [54.9827,82.8958], 11 | [54.9837,82.8968], 12 | [54.9837,82.8938] 13 | ], 14 | type: 0 // If is 0 then Line, if is 1 then Polygon, if is 2 then Rectangle. 15 | }; 16 | 17 | onChangePoints = e => { 18 | this.setState({ 19 | points: JSON.parse(e.target.value) 20 | }); 21 | }; 22 | 23 | onChangeLine = e => { 24 | if (e.target.value) { 25 | this.setState({ 26 | type: 0 27 | }); 28 | } 29 | }; 30 | 31 | onChangePolygon = e => { 32 | if (e.target.value) { 33 | this.setState({ 34 | type: 1 35 | }); 36 | } 37 | }; 38 | 39 | onChangeRectangle = e => { 40 | if (e.target.value) { 41 | this.setState({ 42 | type: 2 43 | }); 44 | } 45 | }; 46 | 47 | addElement = e => { 48 | let polygons = this.state.polygons; 49 | const points = this.state.points; 50 | 51 | switch (this.state.type) { 52 | case 0: 53 | polygons.push( 54 | 59 | ); 60 | break; 61 | case 1: 62 | polygons.push( 63 | 71 | ); 72 | break; 73 | case 2: 74 | polygons.push( 75 | 83 | ); 84 | break; 85 | } 86 | 87 | if (this.state.type) { 88 | 89 | } 90 | else { 91 | 92 | } 93 | this.setState({ 94 | polygons: polygons 95 | }); 96 | }; 97 | 98 | deleteElement = e => { 99 | let polygons = this.state.polygons; 100 | polygons.pop(); 101 | this.setState({ 102 | polygons: polygons 103 | }); 104 | }; 105 | 106 | render() { 107 | return ( 108 |
109 |
110 | 111 |