processData: function(topojsonData) { holyLand = topojsonData; subunits = topojson.feature(holyLand, holyLand.objects.holy_admin); places = topojson.feature(holyLand, holyLand.objects.holy_places); water = topojson.feature(holyLand, holyLand.objects.holy_water); rivers = topojson.feature(holyLand, holyLand.objects.holy_rivers); },
[RECIEVE_NATIONAL_DATA]: (state,action) => { var newState = Object.assign({},state); let us = action.payload; newState.loaded = true; newState.statesGeo = topojson.feature(us,us["objects"]["states.geo"]), newState.metrosGeo = topojson.feature(us,us["objects"]["fixMsa.geo"]) return newState; }
var t = promise.then(data => { let regionTopoJson = data let state = topojson.feature(regionTopoJson, regionTopoJson.objects.state) let regions = topojson.feature(regionTopoJson, regionTopoJson.objects.region) let counties = topojson.feature(regionTopoJson, regionTopoJson.objects.county) let streams = topojson.feature(regionTopoJson, regionTopoJson.objects.streamProperties) let tableOfContents = { state, regions, counties, streams } return tableOfContents })
module.exports = function(points, polygons, options) { var pointObjects = points.objects, polygonObjects = polygons.objects, polygonObjectKey = null, countKey = options.key for(polygonObjectKey in polygonObjects) { if(polygonObjects[polygonObjectKey].type !== 'GeometryCollection') continue var polygonGeometries = polygonObjects[polygonObjectKey].geometries, i = polygonGeometries.length while(i--) { var polygon = polygonGeometries[i], pointObjectKey = null // No support for multipolygons just yet if(polygon.type === 'MultiPolygon') continue process.stdout.write("Checking " + i + " polygon...\r") polygon = topojson.feature(polygons, polygon) for(pointObjectKey in pointObjects) { var pointGeometries = pointObjects[pointObjectKey].geometries, j = pointGeometries.length if(typeof polygon.properties[countKey] === 'undefined') polygon.properties[countKey] = 0 while(j--) { var point = topojson.feature(points, pointGeometries[j]) if(gju.pointInPolygon(point.geometry, polygon.geometry)) polygon.properties[countKey] += 1 } } } } if(options.out) { fs.writeFileSync(path.join(options.out), JSON.stringify(polygons), "utf8"); } else { console.log(polygons) } }
loadMap(data) { const map = L.map(this.mapRef, { center: [-21, 144], zoom: 6, }); L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', { attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', }).addTo(map); L.geoJson(topojson.feature(data, data.objects.districts), { style: { color: 'red', fillOpacity: 0, opacity: 0.25, weight: 3, }, }).addTo(map); L.geoJson(topojson.feature(data, data.objects.lga), { style: { color: 'green', fillOpacity: 0, opacity: 0.25, weight: 2, }, }).addTo(map); L.geoJson(topojson.feature(data, data.objects.proposal), { style: { color: '#0066ff', fillOpacity: 0, opacity: 1, weight: 2, }, onEachFeature(feature, layer) { const infoStr = Object.keys(feature.properties) .map(prop => `${prop}: ${feature.properties[prop]}`) .join('<br>'); layer.bindPopup(infoStr).addEventListener('popupopen', () => { layer.setStyle({ fillOpacity: 0.25 }); }).addEventListener('popupclose', () => { layer.setStyle({ fillOpacity: 0 }); }); }, }).addTo(map); }
d3.json('data/world-110m2.json', function(error, topology) { g.selectAll('path') .data(topojson.feature(topology, topology.objects.countries).features) .enter() .append('path') .attr('d', path); });
_createProjection(topoJSONData, topContour, center) { // The map's scale out is based on the solution: // http://stackoverflow.com/questions/14492284/center-a-map-in-d3-given-a-geojson-object var width = this.W; var height = this.H; var guide = this.config.guide; var scale = 100; var offset = [width / 2, height / 2]; var mapCenter = center || topoJSONData.center; var mapProjection = guide.projection || topoJSONData.projection || 'mercator'; var d3Projection = this._createD3Projection(mapProjection, mapCenter, scale, offset); var path = d3.geo.path().projection(d3Projection); // using the path determine the bounds of the current map and use // these to determine better values for the scale and translation var bounds = path.bounds(topojson.feature(topoJSONData, topoJSONData.objects[topContour])); var hscale = scale * width / (bounds[1][0] - bounds[0][0]); var vscale = scale * height / (bounds[1][1] - bounds[0][1]); scale = (hscale < vscale) ? hscale : vscale; offset = [ width - (bounds[0][0] + bounds[1][0]) / 2, height - (bounds[0][1] + bounds[1][1]) / 2 ]; // new projection return this._createD3Projection(mapProjection, mapCenter, scale, offset); }
d3_json(topoJSONPath, function(error, topoJSON) { const features = topojson.feature(topoJSON, topoJSON.objects[topoJSONRoot]); const polygons = container.selectAll('path') .data(features.features) .enter() .append('path') .attr('class', d => { return `polygon ${getPolygonClassName(d)}`; }) .attr('d', path); if (showTooltipCallback !== undefined) { polygons.on('mousemove', function(d) { showTooltipCallback(d, d3_event.clientX + 10, d3_event.clientY + window.scrollY + 10); } ) .on('mouseout', function() { hideTooltipCallback(); }); } const collection = { 'type': 'FeatureCollection', 'features' : features.features }; const featureBounds = path.bounds(collection); const { scale, trans } = fitGeoInside(featureBounds, width, height); container.attr('transform', [ 'translate(' + trans + ')', 'scale(' + scale + ')' ].join(' ')); container.selectAll('path').style('stroke-width', .5 / scale); });
loadMarketRentAreas(data) { let features = topojson.feature(data, data.objects.market_rent_area).features; let layersList = []; features.forEach((marketRentArea) => { let layerName = `market-rent-area-${marketRentArea.id}`; this.map.addSource(layerName, { "type": "geojson", "data": marketRentArea }); let layer = this.map.addLayer({ "id": layerName, "type": "line", "source": layerName, "paint": { "line-color": "transparent", "line-width": 2, "line-opacity": 0.8, "line-dasharray": [4, 1] } }); layersList.push(layerName); }); }
export default function Population() { const counties = topojson.feature(us, us.objects.counties).features; const densities = counties // TODO(joel): make this not side effect .map(d => { return d.properties.density = d.properties.pop / path.area(d); }) .sort((a, b) => a - b); color.domain([quantile(densities, .01), quantile(densities, .99)]); const paths = counties.map(county => ( <path key={county.id} fill={color(county.properties.density)} d={path(county)} /> )); return ( <svg width={width} height={height}> <g className="counties"> {paths} </g> </svg> ); }
// Fetch data function ready(error, grimentsStatic, resorts, topology) { if (error) throw error; // Pre-setup manual added resort griments = grimentsStatic[0]; var griments = snowtypes.getResortWithSnowTypes(griments); var edgeArr = snowtypes.createEdgeArray(griments.edges, griments.vertices, projection); var snowArr = snowtypes.getSnowtypes(); resorts.forEach(function(resort){ resort.snowType = snowArr[Math.floor((Math.random() * snowArr.length))]}); // Draw contours map.selectAll(".contour") .data(topojson.feature(topology, topology.objects.contours).features) .enter().append("path") .attr("class", "contour") .attr("d", null_path) .style("fill", function(d) { return color(d.id); }) .style("stroke", function(d) { return d3.hcl(color(d.id)).brighter(); }); //Draws all the resort map.selectAll("resorts") .data(resorts).enter() .append("rect") .attr("class", function(d) {return ("id-" + d.id)}) .attr("x", function (d) { return projection(d.lonLat)[0]; }) .attr("y", function (d) { return projection(d.lonLat)[1]; }) .attr("width", 10) .attr("height", 10) .attr("fill", function(d) {return d.snowType.color}) .on("click", clicked); //Draws the snowareas in forms of lines for Griments map.selectAll("line") .data(edgeArr) .enter() .append("line") .attr("x1", function(d) { return d.start[0]}) .attr("y1", function(d) { return d.start[1]}) .attr("x2", function(d) { return d.end[0]}) .attr("y2", function(d) { return d.end[1]}) .attr("stroke-width", 0.5) .attr("stroke", function(d) {return d3.rgb(d.snow.color).brighter(0.5)}) .style("opacity", 0); //Draws the vertices for griments map.selectAll("griments") .data(griments.vertices).enter() .append("rect") .attr("class", "grimentz") .attr("x", function (d) { return projection(d.lonLat)[0]-0.0625; }) .attr("y", function (d) { return projection(d.lonLat)[1]-0.0625; }) .attr("fill", function (d) { return d.snow.color}) .attr("width", 0.2) .attr("height", 0.2) .style("opacity", 0) .on("click", clicked); initAxis(); }
d3.json("data/world-110m.json", function (err, world) { if (err) { cb(err); } else { countries = topojson.feature(world, world.objects.countries).features; cb(null); } });
function processTopology(topology) { var countries = topojson.feature(topology, topology.objects.countries).features countries.forEach(function(d) { calculateCountryArea(d); trimProperties(d); }) }
loadMap(data) { const component = this; const map = L.map(this.mapRef, { center: [-21, 144], zoom: 6, }); const areaGeo = topojson.feature(data, data.objects.sa1); const districtGeo = topojson.feature(data, data.objects.districts); const lgaGeo = topojson.feature(data, data.objects.lga); L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', { attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', }).addTo(map); L.geoJson(districtGeo, { style: { color: '#0099ff', fillOpacity: 0, weight: 3, }, }).addTo(map); L.geoJson(lgaGeo, { style: { color: '#00ff00', fillOpacity: 0, weight: 2, }, }).addTo(map); L.geoJson(areaGeo, { style: { color: 'red', fillOpacity: 0, weight: 1, }, onEachFeature(feature, layer) { const { properties } = feature; layer.addEventListener('click', () => component.onLayerClick(properties.SA1, layer)); }, filter(feature) { return true; }, }).addTo(map); }
fromTopoJSON : function(layerName, data){ var s = data.objects[layerName]; var topojsonShapes = topojson.feature(data, s); if (topojsonShapes.features) { return topojsonShapes.features; } else { return [topojsonShapes]; } },
parse: function(data){ var layers = {}; for (var key in data.objects) { layers[key] = topojson.feature(data, data.objects[key]); } return layers; }
d3.json("/usa-map-data", function(error, map_json) { if (error) { return console.error(error); } svg.selectAll('.state') .data(topojson.feature(map_json, map_json.objects.states) .features) .enter().append("path") .attr("id", (d) => d.properties['postal']) .attr("class", "state") .attr("d", path); svg.append("path") .datum(topojson.mesh(map_json, map_json.objects.subunits, (a,b)=> a===b)) .attr("d", path) .attr("class", "exterior-borders"); svg.append("path", ".graticule") .datum(topojson.mesh(map_json, map_json.objects.states, (a,b)=> a !== b)) .attr("class", "state-borders") .attr("d", path); // add state labels // show state labels svg.selectAll(".state-label") .data(topojson.feature(map_json, map_json.objects.states).features) .enter().append("text") .attr("class", "state-label") .attr("transform", function (d) { var loc = path.centroid(d); loc[0] -= 30; return "translate("+loc+")";}) .attr("dy", ".35em") .text((d)=>d.properties['state-name']) //create mouse over event for changing the current state api d3Chart._addClickableState(el, props); });
d3.map(data.objects).entries().forEach(function(e){ var name = e.key; var s = e.value; var topojsonShapes = topojson.feature(data, s); if (topojsonShapes.features) { result.set(name, topojsonShapes.features); } else { result.set(name, [topojsonShapes]); } });
export const getGeoJSON = (feature, type = 'feature') => { if (!topology.objects[feature]) { throw new Error( `${feature} is not within the objects collection of the test topojson` ); } if (type === 'mesh') return topojson.mesh(topology, topology.objects[feature]); return topojson.feature(topology, topology.objects[feature]); };
export default function World() { const now = new Date(); const today = utcDay(now); const sun = antipode(solarPosition(now)); const angle = 180 - sun[0]; const translate1 = `translate(${width / 2}, ${height / 2})`; const rotate = `rotate(${angle})`; const translate2 = `translate(${-width / 2}, ${ -height / 2})`; const transform = translate1 + rotate + translate2; return ( <svg width={width} height={height}> <defs> <path id="sphere" d={path({type: 'Sphere'})} /> </defs> <use className="stroke" xlinkHref="#sphere" /> <use className="fill" xlinkHref="#sphere" /> <g transform={transform}> <path className="graticule" d={path(graticule())} /> <path className="land" d={path(topojson.feature(world, world.objects.land))} /> <path className="boundary" d={path(topojson.feature( world, world.objects.countries, (a, b) => a !== b ))} /> <path className="night" d={path(circle.center(sun)())} /> </g> </svg> ); }
function topojsonParse(data, options, layer) { var o = typeof data === 'string' ? JSON.parse(data) : data; layer = layer || L.geoJson(); for (var i in o.objects) { var ft = topojson.feature(o, o.objects[i]); if (ft.features) addData(layer, ft.features); else addData(layer, ft); } return layer; }
function topojsonParse(data) { var o = typeof data === 'string' ? JSON.parse(data) : data; var features = []; for (var i in o.objects) { var ft = topojson.feature(o, o.objects[i]); if (ft.features) features = features.concat(ft.features); else features = features.concat([ft]); } return features; }
.then(payload => { if (payload === undefined) { console.warn('missing vector layer file', vectorLayerURL); return; } const topoJSON = JSON.parse(payload); const key = Object.keys(topoJSON.objects)[0]; const geoJSON = topojson.feature(topoJSON, topoJSON.objects[key]); setGeoJSONMeta(geoJSON, getState().tool.nodesDict, getState().tool.geoIdsDict, geoColumn.id); mapVectorData[geoColumn.id].geoJSON = geoJSON; });
.then(function(data) { var _data = {} if (data) { _data['configs'] = data[0].data _data['global'] = data[1].data _data['geo'] = topojson.feature(data[2].data, data[2].data.objects['Aqueduct_country']).features } MapServerActionCreators.handleDATASuccess(_data) return true })
parseSourceData (tile, source, response) { let data = JSON.parse(response); // Single layer if (data.objects && Object.keys(data.objects).length === 1 && data.objects.vectile != null) { data = topojson.feature(data, data.objects.vectile); } // Multiple layers else { let layers = {}; for (let key in data.objects) { layers[key] = topojson.feature(data, data.objects[key]); } data = layers; } this.prepareGeoJSON(data, tile, source); }
reverseContours.forEach((c, i) => { var getInfo = (d) => labelsHash[`${c}-${d.id}`]; node.selectAll(`.map-contour-${c}`) .data(topojson.feature(topoJSONData, topoJSONData.objects[c]).features || []) .enter() .append('g') .call(function () { var cont = this; cont.attr('class', `map-contour-${c} map-contour-level map-contour-level-${i}`) .attr('fill', 'none'); cont.append('title') .text((d) => (d.properties || {}).name); cont.append('path') .attr('d', path); cont.append('text') .attr('class', `place-label-${c}`) .attr('transform', (d) => { var i = getInfo(d); return i ? `translate(${[i.x, i.y]})` : ''; }) .text(d => { var i = getInfo(d); return i ? i.name : ''; }); cont.append('line') .attr('class', `place-label-link-${c}`) .attr('stroke', 'gray') .attr('stroke-width', 0.25) .attr('x1', (d) => { var i = getInfo(d); return (i && i.isRef) ? i.sx : 0; }) .attr('y1', (d) => { var i = getInfo(d); return (i && i.isRef) ? i.sy : 0; }) .attr('x2', (d) => { var i = getInfo(d); return (i && i.isRef) ? (i.x - i.name.length * 0.6 * avgCharSize) : 0; }) .attr('y2', (d) => { var i = getInfo(d); return (i && i.isRef) ? (i.y - 3.5) : 0; }); }); });
function getTopoJSONFeature (topology, object) { let feature = topojson.feature(topology, object); // Convert single feature to a feature collection if (feature.type === 'Feature') { feature = { type: 'FeatureCollection', features: [feature] }; } return feature; }
function loadMap() { var topo = loadQueue.getResult('Topology'), map = d3.select('#map'), countries = topojson.feature(topo, topo.objects.ne_50m_admin_0_countries), states = topojson.feature(topo, topo.objects.ne_50m_admin_1_states_provinces_lakes), path = d3.geo.path().projection(d3.geo.mercator().scale(150)); map.selectAll('.country') .data(countries.features) .enter().append('path') .attr('class', function(d) { return 'country ' + d.properties.iso_a2; }) .attr('d', path) .on('click', function(d) { console.log(d.properties.name + ' clicked'); }); map.selectAll('.state') .data(_.filter(states.features, function(d) { return d.properties.iso_a2 == 'US' })) .enter().append('path') .attr('class', function(d) { return 'state ' + d.properties.code_hasc.replace('.', '_'); }) .attr('d', path) .on('click', function(d) { console.log(d.properties.code_hasc + ' clicked'); }); }
/** * Adds a Topo JSON file into a Map * @param data The parsed JSON File * @param options */ function addTopoJson(data, options) { var item, geoJson, features, x; for (x in options) { if (options.hasOwnProperty(x)) { item = options[x]; geoJson = topojson.feature(data, data.objects[item.object]); features = that.instance.data.addGeoJson(geoJson); addFeatureOptions(features, item); global.mapTools.maps[that.id].json.all[item.object] = features; } } return features; }
proto.drawTopo = function(selection, layerName, geoLayout) { if(geoLayout['show' + layerName] !== true) return; var topojson = this.topojson, datum = layerName==='frame' ? constants.sphereSVG : topojsonFeature(topojson, topojson.objects[layerName]); selection.append('g') .datum(datum) .attr('class', layerName) .append('path') .attr('class', 'basepath'); };