您的代码需要一些更改才能显示地图,您正在使用
<script type="text/javascript" src="http://apis.mapmyindia.com/v2.0/mapApi/licKey=4d29cecd1c6f9f97247b82e18b637093&platform=aspx"></script>
将上面的行更改为
<script src="https://apis.mapmyindia.com/advancedmaps/v1/4d29cecd1c6f9f97247b82e18b637093/map_load?v=0.1">
用于初始化 MapMyIndia 地图。您正在使用
var map = $("#MapDiv");
map.MireoMap();
更改该代码
var map=new MapmyIndia.Map("MapDiv",{ center:[30.7333, 76.7794], zoomControl: true, hybrid:true, search:true, location:true});
以上单行代码能够获取 MapmyIndia 地图并将显示到您的容器元素中。
现在来到标记绘图代码:
var _X = '76.652826';
var _Y = '10.78716';
var pt = new Point(_X, _Y);
map.MireoMap("addMarker", HTMLHelper.mapMarker("https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png", 100, 100), pt);
在这里您正在创建 Point 无需为标记绘图创建点,因为 MapmyIndia API 能够使用 lat lng 绘制标记
更改标记创建代码
var _X = '76.652826';
var _Y = '10.78716';
var markerIcon = L.icon({
iconUrl: 'https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png',
iconSize: [100, 100], // size of the icon
iconAnchor: [50, 100] // point of the icon which will correspond to marker's location
});
new L.marker([_X,_Y], {icon: markerIcon}).addTo(map);
现在你的答案是如何创建多个标记。有多种方法可以做到这一点,
1)这个非常简单,一一创建标记并添加到地图中
var _X = '76.652826';
var _Y = '10.78716';
var markerIcon = L.icon({
iconUrl: 'https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png',
iconSize: [100, 100],
iconAnchor: [50, 100]});
new L.marker([_X,_Y], {icon: markerIcon}).addTo(map);
_X = '76.602826';
_Y = '10.70716';
markerIcon = L.icon({
iconUrl: 'https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png',
iconSize: [100, 100],
iconAnchor: [50, 100]});
new L.marker([_X,_Y], {icon: markerIcon}).addTo(map);
2)或者您可以运行 for 循环创建多个标记并添加到地图
var markerLatLngs = [
[30.7333, 76.7794],
[30.7233, 76.7694],
[30.7133, 76.7594]
];
var markerIcon = L.icon({
iconUrl: 'https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png',
iconSize: [100, 100],
iconAnchor: [50, 100]});
for (var i = 0; i < markerLatLngs.length; i++) {
new L.marker([markerLatLngs[i][0], markerLatLngs[i][1]], {icon: markerIcon}).addTo(map);
}
3)如果您有大量标记,这一点非常重要。创建一个图层组并将所有标记添加到该组并将该组添加到地图。
var markerLatLngs = [
[30.7333, 76.7794],
[30.7233, 76.7694],
[30.7133, 76.7594]
];
var markerIcon = L.icon({
iconUrl: 'https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/81591c98d66921ed45c6fbab36601942/medium.png',
iconSize: [100, 100],
iconAnchor: [50, 100]});
var markerGroup = new L.featureGroup(); //Create a group for markers
for (var i = 0; i < markerLatLngs.length; i++) {
var marker= new L.marker([markerLatLngs[i][0], markerLatLngs[i][1]], {icon: markerIcon});
markerGroup.addLayer(marker); //add marker into group
}
markerGroup.addTo(map); // add Group of markers to map