Mapbox JS,来自URL的GeoJSON featureCollection对象只添加了一个标记
Mapbox JS, GeoJSON featureCollection object from URL only adds one marker
此映射,http://lastablaslift.es/explorador/,正在通过csv2geojson插件加载一个本地CSV文件,以添加一些带有弹出窗口的标记。
我们正试图将一个URL端点组合在一起,以从mysql DB而不是CSV中获取geoJSON。
这个地图,http://lastablaslift.es/explorador/map_test.php,是相同的,但使用了我们URL中的geoJSON。
我们似乎已经得到了返回正确格式GeoJSON的URL,但正如您所看到的,只有"features"数组中的第一个对象在map_test.php 上呈现
我正在将两个geoJSON对象记录到控制台中,当我比较它们时,它们在我看来是一样的。也没有报告相关的错误,那么我们URL中的geoJSON有什么问题?
请参阅这个JSFiddle示例。我认为会有与function change() {}
相关的问题,您将其放置在$.getJSON成功函数中。试着把它放在外面。,您的map_jsonurl.jssholud是这样的
(function() {
var image = new Image();
image.onload = function() {
if (image.width > 0) {
document.documentElement.className += (document.documentElement.className != '') ? ' images-on' : 'images-on';
}
};
image.src = '/img/px.png';
}());
//toggle the filter menu
/*$("#f_tog").on("click", function(){
$("#filters").slideToggle();
$("#f_tog span").toggle();
});*/
// load the map data
$.getJSON("//civicliftmapeurope.azurewebsites.net/api/Listing", function(data) {
//initialize the map
var map = L.mapbox.map('map', 'ptw111.lgof8gop')
.setView([40.5023056, -3.6704803], 14);
//center marker on click
map.markerLayer.on('click', function(e) {
map.panTo(e.layer.getLatLng());
});
// Add custom popups to each using our custom feature properties
map.featureLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
//string functions, cleaning up geoJSON for display.
//clean up address
var addr;
var zip = feature.properties.zip;
if (feature.properties.addr) {
addr = feature.properties.addr + ', ' + zip + '<br>' + feature.properties.city + ', España';
}
//check for description
var desc;
if (feature.properties.description) {
desc = feature.properties.description;
} else {
desc = '';
}
//check for phone numbers
var phone;
if (feature.properties.phone) {
phone = '<strong>' + feature.properties.phone + '</strong>';
} else {
phone = '';
}
// create custom popup content
var popupContent = '<div class="tooltip"><h2>' + feature.properties.name + '</h2>' +
phone +
'<div class="addr"><p>' +
addr +
'</p></div><span>' +
desc +
'</span></div>';
// http://leafletjs.com/reference.html#popup
marker.bindPopup(popupContent, {
closeButton: false,
minWidth: 150,
});
});
// Add features to the map
map.featureLayer.setGeoJSON(data);
//filter locations by color/type
var filters = document.getElementById('filters');
var checkboxes = document.getElementsByClassName('filter');
// When the form is touched, re-filter markers
filters.onchange = change;
// Initially filter the markers
change();
});
function change() {
// Find all checkboxes that are checked and build a list of their values
var on = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) on.push(checkboxes[i].value);
}
// The filter function takes a GeoJSON feature object
// and returns true to show it or false to hide it.
map.markerLayer.setFilter(function(f) {
// check each marker's color to see if its value is in the list
// of colors that should be on, stored in the 'on' array
return on.indexOf(f.properties['marker-color']) !== -1;
});
return false;
}
相关文章:
- 我可以在json对象中添加一个函数吗
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 单击更改图标并通过javascript添加一个css类
- fluxxor向一个flux实例添加一组以上的操作
- 当在Ember中点击一个项目时,我如何将一个活动类添加到项目列表中
- 如何在Angular单元测试中从另一个控制器的rootScope将方法添加到rootScope中
- 将添加一个相同类型的事件附加或覆盖以前添加的具有相同名称的事件
- angularjs移除焦点上的活动类并添加到下一个项目
- 使用jquery contains获取一个元素并添加类
- 有没有添加一个ng点击到md背景
- 如何为下拉列表的每个选项添加一个属性
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- 单击删除其中一个添加的行
- 几个jQuery日期选择器小部件,只向其中一个添加类
- 我想创建一个添加新表单的按钮
- Babel v6:我如何/可以编写一个添加新语法(即新运算符)的插件
- GWT SimplePager -为每个下一个和上一个添加历史记录
- 自动提交表单上的最大长度,-为现有的一个添加java脚本代码
- 如何在jquery中移除一个添加了类的类
- 动态更改URL,而不需要将前一个添加到历史堆栈