Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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 使用传单中的弹出窗口将整数更改为字符串值_Javascript_Leaflet - Fatal编程技术网

Javascript 使用传单中的弹出窗口将整数更改为字符串值

Javascript 使用传单中的弹出窗口将整数更改为字符串值,javascript,leaflet,Javascript,Leaflet,带有点的geojson文件具有整数值,需要在弹出窗口中将其转换为字符串值,以便用户可读。尝试使用该函数,但无法使其正常工作。有没有任何建议来更正此代码或以其他方式解决此问题 function weekday(feature, layer){ switch (feature.properties.ID){ case 1: return 'Monday'; case 2: return 'Tuesday'; case 3: return

带有点的geojson文件具有整数值,需要在弹出窗口中将其转换为字符串值,以便用户可读。尝试使用该函数,但无法使其正常工作。有没有任何建议来更正此代码或以其他方式解决此问题

   function weekday(feature, layer){
    switch (feature.properties.ID){
        case 1: return 'Monday';
        case 2: return 'Tuesday';
        case 3: return 'Wednesday';
        case 4: return 'Thursday';
        case 5: return 'Friday';
    }
   }

   $.getJSON("../data/abc123/data.geojson", function(json) {

   geoLayer = L.geoJson(json, {

    onEachFeature: function(feature, layer) {
      var popupText =
        "Data: <b>GPS log</b>" +
        "<br><b>Startingpoint</b>: " + feature.properties.X + 
        "<br><b>Endpoint</b>: " + feature.properties.Y +
        "<br><b>Weekday</b>: " + (feature.properties.ID, weekday)

      layer.bindPopup(popupText, {
        closeButton: true,
        offset: L.point(0, -20)
      });
      layer.on('click', function() {
        layer.openPopup();
      });
    },
功能工作日(功能、图层){
开关(feature.properties.ID){
案例1:返回“星期一”;
案例2:返回“星期二”;
案例3:返回“星期三”;
案例4:返回“星期四”;
案例5:返回“星期五”;
}
}
$.getJSON(“../data/abc123/data.geojson”,函数(json){
geoLayer=L.geoJson(json{
onEachFeature:功能(功能,图层){
var超文本=
“数据:GPS日志”+
“
起始点:”+feature.properties.X+ “
端点:”+feature.properties.Y+
工作日:+(feature.properties.ID,工作日) layer.bindPopup(弹出文本{ 关闭按钮:对, 偏移量:L点(0,-20) }); layer.on('单击',函数()){ layer.openPopup(); }); },
geojson文件的一部分

{ “类型”:“FeatureCollection”, “名称”:“数据”, “crs”:{“类型”:“名称”,“属性”:{“名称”:“urn:ogc:def:crs:ogc:1.3:CRS84”}, “特点”:[ {“类型”:“特征”,“属性”:{“X”:“诺尔科平”,“B”:60208,“Y”:“诺尔科平”,“代码”:“60208A”,“ID”:2,“名称”:“奥斯卡”,“荷载1”:0,“荷载2”:4},“几何”:{“类型”:“点”,“坐标”:[16.150801,58.608192]}


单击cirlceMarker时,弹出窗口应以字符串值显示工作日,而不是以数字显示工作日。但在本例中,我得到完整的函数工作日代码显示在弹出窗口中。

您没有正确调用函数:

weekday(feature.properties.ID)
由于您已经将ID作为参数传递,因此不需要整个功能,也不需要参数中的图层,您可以按如下方式定义函数:

function weekday(ID){
    switch (ID){
        case 1: return 'Monday';
        case 2: return 'Tuesday';
        case 3: return 'Wednesday';
        case 4: return 'Thursday';
        case 5: return 'Friday';
   }
}

您没有正确调用函数:

weekday(feature.properties.ID)
由于您已经将ID作为参数传递,因此不需要整个功能,也不需要参数中的图层,您可以按如下方式定义函数:

function weekday(ID){
    switch (ID){
        case 1: return 'Monday';
        case 2: return 'Tuesday';
        case 3: return 'Wednesday';
        case 4: return 'Thursday';
        case 5: return 'Friday';
   }
}