【问题标题】:Center Kendo Map between markers标记之间的中心剑道地图
【发布时间】:2015-07-01 12:05:57
【问题描述】:

有没有办法让地图在标记之间的中心居中?在标记之间设置中心,考虑到标记是从远程dataSource 加载的?

【问题讨论】:

    标签: kendo-ui kendo-map


    【解决方案1】:

    这可以根据此处找到的示例来完成:http://www.kendoui.io/kendo-ui/dataviz/map/how-to/zoom-on-area.html

    代码如下

    <button id="center">Center on markers</button>
    <div id="map"></div>
    <script>
        var markers = [
        {"latlng":[30.2675,-97.7409], "name": "Zevo Toys"},
        {"latlng": [30.2707,-97.7490],"name": "Foo Bars"},
        {"latlng": [30.2705,-97.7409],"name": "Mainway Toys"},
        {"latlng": [30.2686,-97.7494], "name": "Acme Toys"}];
    
        $("#map").kendoMap({
            layers: [{
                type: "tile",
                urlTemplate: "http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png",
                subdomains: ["a", "b", "c"],
                attribution: "© <a href='http://osm.org/copyright'>OpenStreetMap contributors</a>."
            }, {
                type: "marker",
                dataSource: {
                    data: markers
                },
                locationField: "latlng",
                titleField: "name"
            }]
        });
    
        function centerMap() {
            var map = $("#map").getKendoMap();
            var layer = map.layers[1];
            var markers = layer.items;
            var extent;
    
            for (var i = 0; i < markers.length; i++) {
                var loc = markers[i].location();
    
                if (!extent) {
                    extent = new kendo.dataviz.map.Extent(loc, loc);
                } else {
                    extent.include(loc);
                }
            }
    
            map.extent(extent);
        }
    
        $("#center").click(centerMap);
    </script>
    

    【讨论】:

    • 有效答案被否决真是令人沮丧。看起来这作为评论就足够了。无论如何,我按照要求用代码更新了答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多