سؤال

أحاول رسم خريطة NYC باستخدام D3. لقد قمت بتنزيل مجموعة من الأشكال من الأشكال من http://www.nyc. GOV / HTML / DCP / HTML / BYTES / DWNDISTRACT.SHTML . لقد قمت بتحويلها إلى Geojson باستخدام http://converter.mygeodata.eu/ ، مثل ذلك في WGS 84 (ويعرف أيضا باسم، أعتقد أن خطوط الطول والعرض).

أنا متأكد من أن Geojson صالح: يمكنني رسمه باستخدام MatplotLib ويبدو وكأنه NYC، ويبدو أن الأرقام في نطاق صالح. ها هي جافا سكريبت: giveacodicetagpre.

هذه المؤامرات، كما هو معلن، ومساورة أليجدية في مدينة نيويورك. مشكلة، أعتقد أن حجم الإسقاط يتم اختياره بحيث يناسب الولايات المتحدة على صفحة ويب لطيفة، مما يجعل مسارات NYC الصلح قليلا في الجانب الأيمن من الشاشة.

ما هي الطريقة "الصحيحة" (محاولة Lemme المطالبة بأنها أول من يقول D3onic) لتوسيع نطاق geo.path() بحيث توفر النطاق من مقياس Lat / Lat الخاص بي على عرض وارتفاع SVG الخاص بي؟

(إخلاء المسئولية الصغيرة: الاعتذار إذا فاتني شيئا واضحا، فهذا هو للمشروع الذي أحاول إكماله في نهايات اليوم الشديدة)

هل كانت مفيدة؟

المحلول

First, you'll want to create a projection, and assign that to the d3.geo.path, so that you can customize the projection settings.

var albers = d3.geo.albers(),
    path = d3.geo.path().projection(albers);

The default projection is d3.geo.albersUsa, which is actually a composite projection (with four different discontinuous areas) designed for showing the 48 states, Alaska, Hawaii and Puerto Rico. Ah, ethnocentrism. ;)

Use the albers example in the git repository to determine the correct projection settings interactively. The settings you need to set are:

  • the origin should be NYC's latitude and longitude (perhaps 73.98°, 40.71°)
  • the translate should be the center of your display area (so, if you're drawing something 960×500, you can use the default 480,250; this will be the pixel location of the origin)
  • the scale is some number that specifies how much to zoom-in; since you're drawing a city-scale map, you probably want a value more like 10000

Lastly, you'll need to pick some parallels. You can use the defaults provided by d3.geo.albers(), but there might be more suitable ones for NYC. Possibly check with the USGS, because they often publish standard parallels for different map areas.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top