Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IvoryGoogleMapBundle:渲染后如何访问Google地图对象_Javascript_Google Maps_Symfony_Twig - Fatal编程技术网

Javascript IvoryGoogleMapBundle:渲染后如何访问Google地图对象

Javascript IvoryGoogleMapBundle:渲染后如何访问Google地图对象,javascript,google-maps,symfony,twig,Javascript,Google Maps,Symfony,Twig,我在Symfony3项目中使用IvoryGoogleMapBundle来渲染地图。在控制器中配置$map对象并在我的小树枝文件中使用以下语句后 {{ ivory_google_map(map) }} {{ ivory_google_api([map]) }} 它产生了这样的东西 <div id="map_canvas" style="width: 100%;height: 100vh;"></div> <style type="test/css">

我在Symfony3项目中使用IvoryGoogleMapBundle来渲染地图。在控制器中配置
$map
对象并在我的小树枝文件中使用以下语句后

{{ ivory_google_map(map) }}
{{ ivory_google_api([map]) }}
它产生了这样的东西

<div id="map_canvas" style="width: 100%;height: 100vh;"></div>
<style type="test/css">
    #map_canvas {
    width: 100%;
    height: 100vh;
    }
</style>
<script type="text/javascript">
    function ivory_google_map_map58e92cb0aa95e139417147 () {
    map58e92cb0aa95e139417147_container = {
        "base": {
            "coordinates": [],
            "bounds": [],
            "points": [],
            "sizes": []
        },
        "map": null,
        "overlays": {
            "icons": [],
            "symbols": [],
            "icon_sequences": [],
            "circles": [],
            "encoded_polylines": [],
            "ground_overlays": [],
            "polygons": [],
            "polylines": [],
            "rectangles": [],
            "info_windows": [],
            "info_boxes": [],
            "marker_shapes": [],
            "markers": [],
            "marker_cluster": null
        },
        "layers": {
            "heatmap_layers": [],
            "kml_layers": []
        },
        "events": {
            "dom_events": [],
            "dom_events_once": [],
            "events": [],
            "events_once": []
        },
        "functions": []
    };
    map58e92cb0aa95e139417147_container.functions.info_windows_close = function () {};
    map58e92cb0aa95e139417147_container.functions.to_array = function (o) {
        var a = [];
        for (var k in o) {
            a.push(o[k]);
        }
        return a;
    };
    map58e92cb0aa95e139417147_container.base.coordinates.coordinate58e92cb0aaca1311661317 = coordinate58e92cb0aaca1311661317 = new google.maps.LatLng(40.416862923413, -3.7034607678652, true);
    map58e92cb0aa95e139417147_container.map = map58e92cb0aa95e139417147 = new google.maps.Map(document.getElementById("map_canvas"), {
        "fullscreenControl": true,
        "fullscreenControlOptions": {
        "position": google.maps.ControlPosition.RIGHT_TOP
    },
        "mapTypeId": google.maps.MapTypeId.HYBRID,
        "zoom": 5
    });
    map58e92cb0aa95e139417147.setCenter(coordinate58e92cb0aaca1311661317);

    }
</script>

<script type="text/javascript">
    function ivory_google_map_load () {
    google.load("maps", "3", {
        "other_params": "language=en&key=__MY_API_KEY__,
        "callback": ivory_google_map_init
    })
    };
    function ivory_google_map_init_source (src) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.async = true;
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
    };
    function ivory_google_map_init_requirement (c, r) {
    if (r()) {
        c();
    } else {
        var i = setInterval(function () {
            if (r()) {
                clearInterval(i);
                c();
            }
        }, 100);
    }
    };
    function ivory_google_map_init () {
    ivory_google_map_init_requirement(ivory_google_map_map58e92cb0aa95e139417147, function () {
        return typeof google.maps !== typeof undefined;
    });
    };
    ivory_google_map_init_source("https://www.google.com/jsapi?callback=ivory_google_map_load");
</script>

但是贴图容器对象在每个渲染上都有一个随机名称,所以。。。为了编写一些javascript来处理映射,我怎么能猜出这个名称呢?

这个库只有一个方法来指定变量名

就这么做

$map = new Map();
$map->setVariable('my_map');
我可以在javascript中访问该属性

my_map.getBounds().getNorthEast().lat();
轻松点

my_map.getBounds().getNorthEast().lat();