编辑#3 以获得更好的帮助(感谢您的耐心)我想结合这两个脚本:
脚本 1:
//get csv file and set up array
d3.csv('../mapdata/mapdatatest.csv', function (csv) {
var rid = [],
lat = [],
lon = [],
pinclr = [],
name = [],
str = [],
citystzip = [],
phone = [],
lastinspturl = [],
lastinspctdt = [];
csv.map(function (d) {
rid.push(d.rid).toString();
lat.push(d.lat).toString();
lon.push(d.lon).toString();
pinclr.push(d.pinclr).toString();
name.push(d.name).toString();
str.push(d.str).toString();
citystzip.push(d.citystzip).toString();
phone.push(d.phone).toString();
lastinspturl.push(d.lastinspturl).toString();
lastinspctdt.push(d.lastinspctdt).toString();
for (i = 0; i < rid.length; i++) {
var points = ('"' + lat[i] + "," + lon[i] + '"');
}
});
});
脚本 2:
deCarta.Core.Configuration.clientName = Config.clientName;
deCarta.Core.Configuration.clientPassword = Config.clientPassword;
var center = new deCarta.Core.Position(Config.position);
var pinOverlay = new deCarta.Core.MapOverlay({
name: "Pins"
});
window.map = new deCarta.Core.Map({
id: "mapContainer",
autoResize: true,
zoom: 11,
center: center,
onReady: function (map) {
map.addLayer(pinOverlay);
postPins();
}
});
function postPins() {
var points = {
"points": [
//i have typed in these values for testing purposes only
"47.15211, -97.570039",
"48.625045, -101.375369",
"48.39679, -101.052669"]
};
for (var i = 0; i < points.points.length;) {
pos = new deCarta.Core.Position(points.points[i]);
pin = pin = new deCarta.Core.Pin({
position: center.clone(),
text: 'pin: ' + (points.points[i]),
position: pos
// imageSrc: 'img/pin.png'
});
pinOverlay.addObject(pin);
i++;
}
var view = new deCarta.Core.BoundingBox(points.points);
var centerAndZoom = view.getIdealCenterAndZoom(window.map);
map.zoomTo(centerAndZoom.zoom);
map.centerOn(centerAndZoom.center);
}
我试图达到的结果:
而不是像我在 SCRIPT 2 中那样使用键入的值——我希望从 SCRIPT 1 中输入这些值。
所以
var points = {
"points": [
//i have typed in these values for testing purposes only
"47.15211, -97.570039",
"48.625045, -101.375369",
"48.39679, -101.052669"]
};
需要是
var points = {
"points": [
THE "point" VALUES FROM THE SCRIPT 1 loop]
};
我明白了这个概念,似乎无法正确使用语法...尝试了所有建议,push();,阅读了很多文章,示例...我在 10 小时前需要这个,任何帮助都会很大赞赏。如果我有足够的代表,我会投票给你 :) 谢谢,谢谢,谢谢。