2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

Example on how to add a Polygon,Circle or Rectangle to a map #51

Open chulu1francis opened 3 years ago

chulu1francis commented 3 years ago

Trying to add a polygon to my map below is my code

 $center = new \dosamigos\leaflet\types\LatLng(['lat' => 37.7900,
          'lng' => -122.401]);
      $polygon = new dosamigos\leaflet\layers\Polygon(
              [
          'name' => 'poly',
          //'map' => 'map',
          'clientOptions' => [
              'color' => 'red'
          ]
      ]);
      $polygon->setLatLngs([
          new \dosamigos\leaflet\types\LatLng(['lat' => 37.786617, 'lng' => -122.404654]),
          new \dosamigos\leaflet\types\LatLng(['lat' => 37.797843, 'lng' => -122.407057]),
          new \dosamigos\leaflet\types\LatLng(['lat' => 37.798962, 'lng' => -122.398260]),
          new \dosamigos\leaflet\types\LatLng(['lat' => 37.794299, 'lng' => -122.395234]),
      ]);

 $leaflet->addLayer($marker)      // add the marker
                        ->addLayer($tileLayer)
                        ->addLayer($polygon);  // add the tile layer

echo $leaflet->widget(['options' => ['style' => 'min-height: 500px']]);

if i add a polygon to the leaflet, map is not showing but when i remove the polygon and just leave a marker the map is showing. Can someone assist with a working example of adding a polygon to the map using this extension.