mapbox/传单上的聚类标记

Clustering markers on mapbox / leaflet(mapbox/传单上的聚类标记)
本文介绍了mapbox/传单上的聚类标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在 mapbox 上设置集群地图,例如 http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html

I'm trying to set up a clustered map on mapbox, like http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html

但他们的示例使用纯 .js 文件作为数据http://www.mapbox.com/mapbox.js/assets/realworld.388.js

But their example uses a plain .js file as data http://www.mapbox.com/mapbox.js/assets/realworld.388.js

而我唯一能从 mapbox 得到的是 .geojsonhttp://api.tiles.mapbox.com/v3/thebteam.map-w9jzcznw/markers.geojson

And the only thing I can get from mapbox is .geojson http://api.tiles.mapbox.com/v3/thebteam.map-w9jzcznw/markers.geojson

有没有办法可以将 geojson 转换为 js(定期)?还是从 mapbox 导出一个 javascript 数组?

Is there a way I can convert the geojson to js (on a regular basis)? Or export a javascript array from mapbox?

最终将我的数据切换为 CSV 并找到了解析器.如果有人需要,这是有效的代码:

ended up switching my data to CSV and finding a parser. Here's the code that worked, if anyone needs it:

var url = 'https://docs.google.com/spreadsheet/pub?key=abc123';

$.get(url, function(data) {
  var addressPoints = $.csv.toArrays(data);
  var map = L.mapbox.map('map', 'map-abc123').setView([20.30, 18.98], 2);
  var markers = new L.MarkerClusterGroup({ showCoverageOnHover: false });

  for (var i = 0; i < addressPoints.length; i++) {
    var a = addressPoints[i];
    var title = a[2];
    var marker = L.marker(new L.LatLng(a[0], a[1]), {
      icon: L.mapbox.marker.icon({'marker-size': 'small', 'marker-color': 'e8168c'}),
      title: title
    });
    marker.bindPopup(title);
    markers.addLayer(marker);
  }

  map.addLayer(markers);

});

推荐答案

var geojson = dataFromMapbox;
var lat;
var lng;
for(var i= 0;i<geojson.features.length;i++)
  {
    lat = geojson.features[i].geometry.coordinates[0];
    lng = geojson.features[i].geometry.coordinates[1];

    //create a marker with those values, pass it to a MarkerCluster object

  }

这篇关于mapbox/传单上的聚类标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)