Like the other Mexican municipalities map, but using projected TopoJSON for faster rendering and better simplification. In response to a Stack Overflow question.
-
-
Save johnjohndoe/9342761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build | |
node_modules | |
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.municipalities { | |
fill: #222; | |
} | |
.municipalities :hover { | |
fill: orange; | |
} | |
.state-boundary { | |
fill: none; | |
stroke: #fff; | |
pointer-events: none; | |
} | |
.municipality-boundary { | |
fill: none; | |
stroke: #fff; | |
stroke-opacity: .25; | |
stroke-width: .5px; | |
pointer-events: none; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 628; | |
var path = d3.geo.path() | |
.projection(null); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("mx.json", function(error, mx) { | |
svg.append("g") | |
.attr("class", "municipalities") | |
.selectAll("path") | |
.data(topojson.feature(mx, mx.objects.municipalities).features) | |
.enter().append("path") | |
.attr("d", path) | |
.append("title") | |
.text(function(d) { return d.properties.name; }); | |
svg.append("path") | |
.datum(topojson.mesh(mx, mx.objects.municipalities, function(a, b) { return a.properties.state !== b.properties.state; })) | |
.attr("class", "state-boundary") | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(mx, mx.objects.municipalities, function(a, b) { return a.properties.state === b.properties.state && a !== b; })) | |
.attr("class", "municipality-boundary") | |
.attr("d", path); | |
}); | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GENERATED_FILES = \ | |
mx.json | |
.PHONY: all clean | |
all: $(GENERATED_FILES) | |
clean: | |
rm -rf -- $(GENERATED_FILES) build | |
build/mgm2010v5_0a.zip: | |
mkdir -p $(dir $@) | |
curl -o $@ 'http://mapserver.inegi.org.mx/MGN/mgm2010v5_0a.zip' | |
build/mgm2010v5_0a.shp: build/mgm2010v5_0a.zip | |
rm -rf -- $(basename $@) | |
mkdir -p $(basename $@) | |
unzip -d $(basename $@) $< | |
for file in `find $(basename $@) -type f`; do chmod 644 $$file; mv $$file $(basename $@).$${file##*.}; done | |
rm -rf -- $(basename $@) | |
touch $@ | |
mx.json: build/mgm2010v5_0a.shp | |
node_modules/.bin/topojson --width=960 --margin 20 --simplify=.1 -o $@ -p name=NOM_MUN -p state=+CVE_ENT -- municipalities=$< |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment