如何在传单地图上绘制标记

时间:2016-09-01 09:45:48

标签: javascript c# leaflet leaflet.markercluster

enter image description here我能够以json格式从数据库中获取数据,目前我可以在控制台中看到数据,所以我的问题是如何绘制我检索到的lat long中的标记使用这个ajax调用。

我如何获得功能成功的标记

$(document).ready(function () {

        $(function () {
            var pData1 = [];
            var jsonData = JSON.stringify({ pData1: pData1 });
           // var jsonArray = JSON.parse(JSON.stringify(jsonData));
            $.ajax({
                type: "POST",
                url: "map.aspx/getCityPopulation2",
                data: jsonData,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,

            });
            function OnSuccess(response) {
                console.log(response.d)
            }

1 个答案:

答案 0 :(得分:0)

最简单的方法是使循环迭代标记并将它们添加到地图

这里有一个工作示例http://codepen.io/hkadyanji/pen/BLyYYY

//select the div that holds the map object
var mymap = document.querySelector("#map")

// ... initialize the leaflet map as expected -> such as adding a tile layer

//a function to add the markers to the map
//you will call this function passing the resulting array from
//the ajax call as the parameter

function addToMap(locationArray){

   //iterates through the array object called from the server
   [].forEach.call(locationArray, function(location){

       var marker = L.marker([location.lat, location.lng]).addTo(mymap);

      //you can even add a custom popup for the individual marker
      //marker.bindPopup("custom pop up content goes here").openPopup();
    }
 }