Domanda

I wish that the map centers and zooms, properly when several markers are displayed.

    //import
    Yii::import('ext.egmap.*');

    //basic setup
    $gMap = new EGMap();
    $gMap->setWidth(953);
    $gMap->setHeight(552);
    $gMap->zoom = 16;
    $gMap->setCenter(38.257818,-7.992712);

    //setup info windows:
    $info_window_a = new EGMapInfoWindow('<div>I am a marker with custom image!</div>');


    //setup marker icon
    $icon = new EGMapMarkerImage("/images/experiences/iconLocal.png");
    $icon->setSize(30, 30);
    $icon->setAnchor(16, 16.5);
    $icon->setOrigin(0, 0);

    //setup markers
    $markerA = new EGMapMarker(38.257818, -7.992712, array('title' => 'Marker A - With Custom Image','icon'=>$icon));
    $markerA->addHtmlInfoWindow($info_window_a);
    $gMap->addMarker($markerA);

    $markerB = new EGMapMarker(38.257818, -7.99333, array('title' => 'Marker B - With Custom Image','icon'=>$icon));
    $markerB->addHtmlInfoWindow($info_window_a);
    $gMap->addMarker($markerB);

    //place them together - but I see no use for them at this time.
    $markers = array($markerA, $markerB);

    //try to map center those markers:
    $gMap->centerOnMarkers();

    //render
    $gMap->renderMap();

Result: I get no centered elements.

I'm I doing something wrong?

È stato utile?

Soluzione

You should use the centerAndZoomOnMarkers() function.

The first argument, $margin, let you define a scaling factor around the smallest bound.

$gMap->centerAndZoomOnMarkers(0.5);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top