希望实现一个地图,该地图将缩放到显示多个标记和用户当前位置的特定位置。
地图以(0,0)为中心,没有标记。 已经搜索了几个小时的答案 - 已经连续两天试过!!
请感谢任何反馈!
SupportMapFragmentActivity.java
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var file = "https://gist.githubusercontent.com/mbostock/1044242/raw/8f22cf2264e1f6ec6cb233c4b49333fb8f75bb99/readme-flare-imports.json",
fileinternet = "https://gist.githubusercontent.com/mbostock/1044242/raw/8f22cf2264e1f6ec6cb233c4b49333fb8f75bb99/readme-flare-imports.json",
fileregular = "data.json",
isLineActive = false,
//originally 0.85
tension = 0.85,
//originally 960
diameter = 900,
radius = diameter / 2,
innerRadius = radius - 120;
var cluster = d3.layout.cluster()
.size([360, innerRadius])
.sort(null)
.value(function(d) { return d.size; });
var bundle = d3.layout.bundle();
var line = d3.svg.line.radial()
.interpolate("bundle")
.tension(tension)
.radius(function(d) { return d.y; })
.angle(function(d) { return d.x / 180 * Math.PI; });
var svg = d3.select("body").append("svg")
.attr("width", diameter*1.5)
.attr("height", diameter)
.attr("style", "outline: thin solid grey;")
.call(d3.behavior.zoom().on("zoom", function () {
svg.attr("transform", "translate(" + d3.event.translate[0] + "," + d3.event.translate[1] + ")" + " scale(" + d3.event.scale + ")")
}))
.append("g")
/*.attr("transform", "translate(" + radius*1.5 + "," + radius + ")")*/;
var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");
d3.json(file, function(error, classes) {
if (error) throw error;
var nodes = cluster.nodes(packageHierarchy(classes)),
links = packageImports(nodes);
link = link
.data(bundle(links))
.enter().append("path")
.each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
.attr("class", "link")
.attr("d", line)
//added the transform here to center the links
.attr("transform", "translate(" + radius*1.5 + "," + radius + ")");
node = node
.data(nodes.filter(function(n) { return !n.children; }))
.attr("transform", "translate(" + radius*1.5 + "," + radius + ")")
.enter().append("text")
.attr("class", "node")
.attr("dy", ".31em")
//I suppose this is where I need to change the transform to somehow center the nodes, but keep the way it's generated
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x < 180 ? "" : "rotate(180)"); })
.style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.text(function(d) { return d.key; })
.on("click", mouseovered);
});
function mouseovered(d) {
if (isLineActive) {
link
.classed("link--target", false)
.classed("link--source", false);
node
.classed("node--target", false)
.classed("node--source", false);
isLineActive = false;
}
else {
node
.each(function(n) { n.target = n.source = false; });
link
.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
.classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
.filter(function(l) { return l.target === d || l.source === d; })
.each(function() { this.parentNode.appendChild(this); });
node
.classed("node--target", function(n) { return n.target; })
.classed("node--source", function(n) { return n.source; });
}
}
function mouseouted(d) {
link
.classed("link--target", false)
.classed("link--source", false);
node
.classed("node--target", false)
.classed("node--source", false);
}
d3.select(self.frameElement).style("height", diameter + "px");
function packageHierarchy(classes) {
var map = {};
function find(name, data) {
var node = map[name], i;
if (!node) {
node = map[name] = data || {name: name, children: []};
if (name.length) {
node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
node.parent.children.push(node);
node.key = name.substring(i + 1);
}
}
return node;
}
classes.forEach(function(d) {
find(d.name, d);
});
return map[""];
}
function packageImports(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
</script>
</body>
答案 0 :(得分:0)
您可以在此SO question尝试解决方案,因为您都试图在旧金山展示标记。
解决方案是将经度更改为负( - )坐标。因为西侧的经度被指示为负号。
还有关于位置服务的问题。我认为tutorial可以帮助您了解应用程序如何显示您当前的位置。