2amigos / yii2-leaflet-extension

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

using polygon and geojson #25

Closed giulianomandotti closed 8 years ago

giulianomandotti commented 8 years ago

great work done guys! i'm quite new about yii2, so can you provide me a simple example to draw a polygon as you've done for marker? the same question for using a geojson file many thnks

giulianomandotti commented 8 years ago

update: ok! i found how to create polygon. how to let appears a data value when click on my polygon area? the other item about geojson remain open thanks

giulianomandotti commented 8 years ago

Toni gave me the solution for my issue in GeoJson data-format.

$tileLayer = new \dosamigos\leaflet\layers\TileLayer(
    [
        'urlTemplate' => 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg',
        'clientOptions' => [
            'attribution' => 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' .
                '<img src="http://developer.mapquest.com/content/osm/mq_logo.png">, ' .
                '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>',
            'subdomains' => ['1', '2', '3', '4'],
        ],
    ]
);

$leaflet = new \dosamigos\leaflet\LeafLet(
    [
        'center' => new LatLng(['lng' => 9.26864901087531, 'lat' => 45.12308769981501]), // set the center
        'tileLayer' => $tileLayer,
        'zoom' => 13
    ]
);
$testGeo = new \dosamigos\leaflet\layers\GeoJson(
    [
        'data' => [
            'type' => 'FeatureCollection',
            'crs' => [
                'type' => 'name',
                'properties' => ['name' => 'urn:ogc:def:crs:OGC:1.3:CRS84'],
            ],
            'features' => [
                [
                    'type' => 'Feature',
                    'properties' => [
                        'Name' => 'Belgioioso',
                        'Description' => '',
                    ],
                    'geometry' => [
                        'type' => 'Polygon',
                        'coordinates' => [
                            [
                                [9.26864901087531, 45.12308769981501, 0],
                                [9.27091132545678, 45.1228843195322, 0],
                                [9.273147345750852, 45.1227529705758, 0],
                                [9.27553751500714, 45.1227022209724, 0],
                                [9.27619771007609, 45.1227456346192, 0],
                                [9.26864901087531, 45.12308769981501, 0]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
);
$layerGroup = new \dosamigos\leaflet\layers\LayerGroup();
$layerGroup->addLayer($testGeo);
$leaflet->addLayerGroup($layerGroup);
$map1 = \dosamigos\leaflet\widgets\Map::widget(
    [
        'leafLet' => $leaflet,
        'height' => '600',

    ]
);
echo $map1;