Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

README.md 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. LeafLet Extension for Yii2
  2. ==========================
  3. [![Latest Version](https://img.shields.io/github/tag/2amigos/yii2-leaflet-extension.svg?style=flat-square&label=release)](https://github.com/2amigos/yii2-leaflet-extension/tags)
  4. [![Software License](https://img.shields.io/badge/license-BSD-brightgreen.svg?style=flat-square)](LICENSE.md)
  5. [![Build Status](https://img.shields.io/travis/2amigos/yii2-leaflet-extension/master.svg?style=flat-square)](https://travis-ci.org/2amigos/yii2-leaflet-extension)
  6. [![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/2amigos/yii2-leaflet-extension.svg?style=flat-square)](https://scrutinizer-ci.com/g/2amigos/yii2-leaflet-extension/code-structure)
  7. [![Total Downloads](https://img.shields.io/packagist/dt/2amigos/yii2-leaflet-extension.svg?style=flat-square)](https://packagist.org/packages/2amigos/yii2-leaflet-extension)
  8. Extension library to display interactive maps with [LeafletJs](http://leafletjs.com/)
  9. Installation
  10. ------------
  11. The preferred way to install this extension is through
  12. [composer](http://getcomposer.org/download/). This requires the
  13. [`composer-asset-plugin`](https://github.com/francoispluchino/composer-asset-plugin),
  14. which is also a dependency for yii2 – so if you have yii2 installed, you are
  15. most likely already set.
  16. Either run
  17. ```
  18. composer require 2amigos/yii2-leaflet-extension:~1.0
  19. ```
  20. or add
  21. ```json
  22. "2amigos/yii2-leaflet-extension" : "~1.0"
  23. ```
  24. to the require section of your application's `composer.json` file.
  25. Usage
  26. -----
  27. One of the things to take into account when working with [LeafletJs](http://leafletjs.com/) is that we need a Tile
  28. Provider. Is very important, if we fail to provide a Tile Provider Url, the map will display plain, without any maps at
  29. all.
  30. The following example, is making use of [MapQuest](http://developer.mapquest.com/):
  31. ```
  32. // first lets setup the center of our map
  33. $center = new dosamigos\leaflet\types\LatLng(['lat' => 51.508, 'lng' => -0.11]);
  34. // now lets create a marker that we are going to place on our map
  35. $marker = new \dosamigos\leaflet\layers\Marker(['latLng' => $center, 'popupContent' => 'Hi!']);
  36. // The Tile Layer (very important)
  37. $tileLayer = new \dosamigos\leaflet\layers\TileLayer([
  38. 'urlTemplate' => 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg',
  39. 'clientOptions' => [
  40. 'attribution' => 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' .
  41. '<img src="http://developer.mapquest.com/content/osm/mq_logo.png">, ' .
  42. 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
  43. 'subdomains' => '1234'
  44. ]
  45. ]);
  46. // now our component and we are going to configure it
  47. $leaflet = new \dosamigos\leaflet\LeafLet([
  48. 'center' => $center, // set the center
  49. ]);
  50. // Different layers can be added to our map using the `addLayer` function.
  51. $leaflet->addLayer($marker) // add the marker
  52. ->addLayer($tileLayer); // add the tile layer
  53. // finally render the widget
  54. echo \dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leaflet]);
  55. // we could also do
  56. // echo $leaflet->widget();
  57. ```
  58. Testing
  59. -------
  60. To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do
  61. the following (assuming you have `composer` installed on your computer):
  62. ```bash
  63. $ composer install --no-interaction --prefer-source --dev
  64. ```
  65. Once all required libraries are installed then do:
  66. ```bash
  67. $ vendor/bin/phpunit
  68. ```
  69. Further Information
  70. -------------------
  71. For further information regarding the multiple settings of LeafLetJS library please visit
  72. [its API reference](http://leafletjs.com/reference.html)
  73. Contributing
  74. ------------
  75. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
  76. Credits
  77. -------
  78. - [Antonio Ramirez](https://github.com/tonydspaniard)
  79. - [All Contributors](../../contributors)
  80. License
  81. -------
  82. The BSD License (BSD). Please see [License File](LICENSE.md) for more information.
  83. > [![2amigOS!](http://www.gravatar.com/avatar/55363394d72945ff7ed312556ec041e0.png)](http://www.2amigos.us)
  84. <i>Web development has never been so fun!</i>
  85. [www.2amigos.us](http://www.2amigos.us)