Is there any way to center map at the center between markers? Making its center between markers, talking into account that markers is loaded from remote dataSource
?
Asked
Active
Viewed 907 times
0

Unheilig
- 16,196
- 193
- 68
- 98

Ahmad Abu Saa
- 718
- 6
- 12
1 Answers
5
This can be done based on the example here found here: http://www.kendoui.io/kendo-ui/dataviz/map/how-to/zoom-on-area.html
The code is as follows
<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>

John Bowyer
- 1,213
- 1
- 15
- 26
-
It is pretty disheartening to have valid answers down voted. It seems like this as a comment would suffice. Anyway I updated the answer with the code as requested. – John Bowyer Apr 16 '16 at 00:41