How to plot lat/long pairs over map in D3.js$location not working in AngularJS using d3.jshow to format time on xAxis use d3.jsDraw the line use the same y values, plots line at the bottomD3 JS Displaying Text Next To CircleOpenlayers: select a feature programmatically from GeoJsonD3 JS - GeoJson (US Map) - not loadingD3js Map : GeometryCollection Vs FeaturesCollectionD3 Bar Chart - Reverse Bars from Right to LeftHow to append properties to geojson file in python?loading geojson into Mapbox object not valid
How does Donald Trump manage to remain so popular over a rather long period of time?
Are there any conflicts with casting Fire Wings while Wild Shaped?
Transiting through Switzerland by coach with lots of cash
What is the next number in the sequence 21, 21, 23, 20, 5, 25, 31, 24, ...?
How do I adjust the cooking time on a baked rice dish if I cut the recipe in half?
In 1700s, why was 'books that never read' grammatical?
Who became a professor?
Why didn't Trudy wear a breathing mask in Avatar?
How to enable Automatic file download in Windows 10 Settings?
Why is the final chapter of "The Midwich Cuckoos" entitled "Zellaby of Macedon"?
How to accompany with piano in latin music when given only chords?
Meaning/Translation of title "The Light Fantastic" By Terry Pratchet
Had there been instances of national states banning harmful imports before the Opium wars?
Is having your hand in your pocket during a presentation bad?
How is the speed of nucleons in the nucleus measured?
Is insurance company’s preferred auto shop biased?
The locus of polynomials with specified root multiplicities
Coffee Grounds and Gritty Butter Cream Icing
Where can I find Armory 92.3 for download?
I've been fired, was allowed to announce it as if I quit and given extra notice, how to handle the questions?
What are the limits on an impeached and not convicted president?
How to prove (A v B), (A → C), (B → D) therefore (C v D)
This fell out of my toilet when I unscrewed the supply line. What is it?
What is a practical use for this metric?
How to plot lat/long pairs over map in D3.js
$location not working in AngularJS using d3.jshow to format time on xAxis use d3.jsDraw the line use the same y values, plots line at the bottomD3 JS Displaying Text Next To CircleOpenlayers: select a feature programmatically from GeoJsonD3 JS - GeoJson (US Map) - not loadingD3js Map : GeometryCollection Vs FeaturesCollectionD3 Bar Chart - Reverse Bars from Right to LeftHow to append properties to geojson file in python?loading geojson into Mapbox object not valid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I'm having a problem plotting points from a geoJSON file over a map using D3.js. The map is rendering fine, but the points are not showing up. I'm not receiving any error messages at this time.
I'm following along with this tutorial but using my own geoJSON file to plot the data.
This is what I have:
var width = 960,
height = 500;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
var projection = d3.geoAlbers()
.scale(1000)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, 'states.json') // Load US States
.defer(d3.json, 'trump_geoJson.json') // Load tweet lat/long data
.await(makeMyMap); // Run 'ready' when JSONs are loaded
function makeMyMap(error,states,tweets)
svg.append('path')
.datum(topojson.feature(states, states.objects.usStates))
.attr('d', path)
.attr('class', 'states');
svg.selectAll('.tweets')
.data(tweets.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
I'm expecting about 600 points to be plotted, but getting none.
The json file trump_geoJson looks like:
{
"type": "FeatureCollection",
"features": [
"type": "Feature",
"id": 0,
"properties":
"primary_geo": "Utah, USA",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
39.32373809814453,
-111.67823791503906
]
,
"type": "Feature",
"id": 1,
"properties":
"primary_geo": "New York, NY",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
40.71455001831055,
-74.00714111328125
]
,... ]
d3.js geojson
add a comment
|
I'm having a problem plotting points from a geoJSON file over a map using D3.js. The map is rendering fine, but the points are not showing up. I'm not receiving any error messages at this time.
I'm following along with this tutorial but using my own geoJSON file to plot the data.
This is what I have:
var width = 960,
height = 500;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
var projection = d3.geoAlbers()
.scale(1000)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, 'states.json') // Load US States
.defer(d3.json, 'trump_geoJson.json') // Load tweet lat/long data
.await(makeMyMap); // Run 'ready' when JSONs are loaded
function makeMyMap(error,states,tweets)
svg.append('path')
.datum(topojson.feature(states, states.objects.usStates))
.attr('d', path)
.attr('class', 'states');
svg.selectAll('.tweets')
.data(tweets.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
I'm expecting about 600 points to be plotted, but getting none.
The json file trump_geoJson looks like:
{
"type": "FeatureCollection",
"features": [
"type": "Feature",
"id": 0,
"properties":
"primary_geo": "Utah, USA",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
39.32373809814453,
-111.67823791503906
]
,
"type": "Feature",
"id": 1,
"properties":
"primary_geo": "New York, NY",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
40.71455001831055,
-74.00714111328125
]
,... ]
d3.js geojson
You'll need to provide some path attributes (mainly.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use.attr("d",path)
.
– Andrew Reid
Mar 28 at 21:12
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22
add a comment
|
I'm having a problem plotting points from a geoJSON file over a map using D3.js. The map is rendering fine, but the points are not showing up. I'm not receiving any error messages at this time.
I'm following along with this tutorial but using my own geoJSON file to plot the data.
This is what I have:
var width = 960,
height = 500;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
var projection = d3.geoAlbers()
.scale(1000)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, 'states.json') // Load US States
.defer(d3.json, 'trump_geoJson.json') // Load tweet lat/long data
.await(makeMyMap); // Run 'ready' when JSONs are loaded
function makeMyMap(error,states,tweets)
svg.append('path')
.datum(topojson.feature(states, states.objects.usStates))
.attr('d', path)
.attr('class', 'states');
svg.selectAll('.tweets')
.data(tweets.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
I'm expecting about 600 points to be plotted, but getting none.
The json file trump_geoJson looks like:
{
"type": "FeatureCollection",
"features": [
"type": "Feature",
"id": 0,
"properties":
"primary_geo": "Utah, USA",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
39.32373809814453,
-111.67823791503906
]
,
"type": "Feature",
"id": 1,
"properties":
"primary_geo": "New York, NY",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
40.71455001831055,
-74.00714111328125
]
,... ]
d3.js geojson
I'm having a problem plotting points from a geoJSON file over a map using D3.js. The map is rendering fine, but the points are not showing up. I'm not receiving any error messages at this time.
I'm following along with this tutorial but using my own geoJSON file to plot the data.
This is what I have:
var width = 960,
height = 500;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
var projection = d3.geoAlbers()
.scale(1000)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.queue()
.defer(d3.json, 'states.json') // Load US States
.defer(d3.json, 'trump_geoJson.json') // Load tweet lat/long data
.await(makeMyMap); // Run 'ready' when JSONs are loaded
function makeMyMap(error,states,tweets)
svg.append('path')
.datum(topojson.feature(states, states.objects.usStates))
.attr('d', path)
.attr('class', 'states');
svg.selectAll('.tweets')
.data(tweets.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
I'm expecting about 600 points to be plotted, but getting none.
The json file trump_geoJson looks like:
{
"type": "FeatureCollection",
"features": [
"type": "Feature",
"id": 0,
"properties":
"primary_geo": "Utah, USA",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
39.32373809814453,
-111.67823791503906
]
,
"type": "Feature",
"id": 1,
"properties":
"primary_geo": "New York, NY",
"tag": "#Bernie",
"text": "text",
"user_id": "id"
,
"geometry":
"type": "Point",
"coordinates": [
40.71455001831055,
-74.00714111328125
]
,... ]
d3.js geojson
d3.js geojson
edited Apr 4 at 20:11
altocumulus
15.8k11 gold badges49 silver badges61 bronze badges
15.8k11 gold badges49 silver badges61 bronze badges
asked Mar 28 at 21:07
Maxfield GreenMaxfield Green
257 bronze badges
257 bronze badges
You'll need to provide some path attributes (mainly.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use.attr("d",path)
.
– Andrew Reid
Mar 28 at 21:12
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22
add a comment
|
You'll need to provide some path attributes (mainly.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use.attr("d",path)
.
– Andrew Reid
Mar 28 at 21:12
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22
You'll need to provide some path attributes (mainly
.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use .attr("d",path)
.– Andrew Reid
Mar 28 at 21:12
You'll need to provide some path attributes (mainly
.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use .attr("d",path)
.– Andrew Reid
Mar 28 at 21:12
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22
add a comment
|
1 Answer
1
active
oldest
votes
Your geojson uses the wrong coordinate convention. You have:
"coordinates": [ latitude, longitude ]
But, you must use:
"coordinates": [ longitude, latitude ]
From the spec:
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, and latitude for geographic coordinates)
It is funny that the spec considers eastings and northings for projected coordinates given the spec also states geojson must use unprojected (lat/long) coordinates using the WGS84 datum
Here's a demo of the first two items in your geojson feature collection:
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406856%2fhow-to-plot-lat-long-pairs-over-map-in-d3-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your geojson uses the wrong coordinate convention. You have:
"coordinates": [ latitude, longitude ]
But, you must use:
"coordinates": [ longitude, latitude ]
From the spec:
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, and latitude for geographic coordinates)
It is funny that the spec considers eastings and northings for projected coordinates given the spec also states geojson must use unprojected (lat/long) coordinates using the WGS84 datum
Here's a demo of the first two items in your geojson feature collection:
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
add a comment
|
Your geojson uses the wrong coordinate convention. You have:
"coordinates": [ latitude, longitude ]
But, you must use:
"coordinates": [ longitude, latitude ]
From the spec:
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, and latitude for geographic coordinates)
It is funny that the spec considers eastings and northings for projected coordinates given the spec also states geojson must use unprojected (lat/long) coordinates using the WGS84 datum
Here's a demo of the first two items in your geojson feature collection:
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
add a comment
|
Your geojson uses the wrong coordinate convention. You have:
"coordinates": [ latitude, longitude ]
But, you must use:
"coordinates": [ longitude, latitude ]
From the spec:
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, and latitude for geographic coordinates)
It is funny that the spec considers eastings and northings for projected coordinates given the spec also states geojson must use unprojected (lat/long) coordinates using the WGS84 datum
Here's a demo of the first two items in your geojson feature collection:
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
Your geojson uses the wrong coordinate convention. You have:
"coordinates": [ latitude, longitude ]
But, you must use:
"coordinates": [ longitude, latitude ]
From the spec:
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, and latitude for geographic coordinates)
It is funny that the spec considers eastings and northings for projected coordinates given the spec also states geojson must use unprojected (lat/long) coordinates using the WGS84 datum
Here's a demo of the first two items in your geojson feature collection:
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
var data =
"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-111.6782379150,39.32373809814]
,
"type": "Feature",
"geometry":
"type": "Point",
"coordinates": [-74.00714111328,40.71455001831]
];
var width = 500,
height = 300;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geoAlbers()
.scale(600)
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world)
if (error) throw error;
svg.append("path")
.attr("d", path(topojson.mesh(world)))
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width",1);
svg.selectAll('.tweets')
.data(data.features)
.enter()
.append('path')
.attr('d',path)
.attr('class', 'tweets');
);
.tweets
fill: red;
opacity: 0.7;
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-queue.v2.min.js"></script>
answered Mar 28 at 23:35
Andrew ReidAndrew Reid
21.8k5 gold badges30 silver badges50 bronze badges
21.8k5 gold badges30 silver badges50 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406856%2fhow-to-plot-lat-long-pairs-over-map-in-d3-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You'll need to provide some path attributes (mainly
.attr("d",...)
) to the paths you are appending for each data item (each point), currently you are adding a path, but not specifying where it should go or how it should be drawn (or how the data should be projected). If you include your data structure, or an example of your data, it will be easier to help provide a solution that does this; however, if your items are valid geojson objects, then you should be able to use.attr("d",path)
.– Andrew Reid
Mar 28 at 21:12
Thanks @AndrewReid, I changed the code as advised and added an example of the geojson. That didn't fix the problem unfortunately.
– Maxfield Green
Mar 28 at 21:22