I am attempting to follow mbostock's "Let's Make a Map" Tutorial here: http://bost.ocks.org/mike/map/. At a certain point in the tutorial, he writes:
d3.json("uk.json", function(error, uk) {
svg.append("path")
.datum(topojson.feature(uk, uk.objects.subunits))
.attr("d", d3.geo.path().projection(d3.geo.mercator()));
});
Without seeing the format of his topoJSON file, it is hard to determine what the equivalent "uk.objects.subunits" line is for my code (my topoJSON can be viewed here: https://gist.github.com/jcahan/e1772766f01b68b00dc9).
Would someone please help clarify how I (and future readers) can determine the inner property (eg uk.objects.subunits) of my topojson file?
Thanks for your time!
Use the web console in your browser (I use the Firebug extension in Firefox) to view Mike's example page and you can watch the browser pull down the uk.json file and view its format. Here's the relevant snippet:
{"type":"Topology","transform":{"scale":
[0.001546403012701271,0.0010939367048704803],"translate":
[-13.69131425699993,49.90961334800009]},"objects":{"subunits":
{"type":"GeometryCollection","geometries":[{"type":"MultiPolygon","id":"ENG","arcs":[[[0]],
[[1]],[[2]],[[3]],[[4]],[[5]],[[6,7,8,9]]],"properties":{"name":"England"}},
You can see the hierarchy of uk.objects.subunits
subunits contains the GeometryCollection. Have a look at your json file and do the same.
Double check that this instruction from Mike is working:
d3.json("uk.json", function(error, uk) {
console.log(uk);
});
Now if you peek at your JavaScript console, you should see a topology object that represents the administrative boundaries and populated places of the United Kingdom.
If you get it to work, let me know, as I cannot get my personal TopoJSON file to load, although I can get all of Mike's to do so. I've come to the conclusion that my TopoJSON file must be wrong somehow.
Sure.
That JSON file happens to be close friend (actually a neightboor) of the example. So you can see it atthe http://bost.ocks.org/mike/map/uk.json
Regards.
Related
I'm using the latest version of the here javascript sdk 3.1.32.0
When I use H.service.Url.MultiValueQueryParameter for my via points like
{
...,
via: new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
}
I see in the URL params of my request this: &via=%5Bobject%20Object%5D
Someone an idea why this happens?
Thanks in advance!
When you use "via" parameter, you define a list of via waypoints. A via waypoint is not a native datatype recongnized by JavaScript, therefore, you will see in the URL params the word object refering to a particular data structure, in this case the via Waypoint composed mainly by Latitude, Longitude.
Regards.
This took a while to figure out the actual issue with the malformed url params. I was dynamically loading the here maps service script on mount of a component. Accidentally this happened in some cases twice. In both cases H was globally available and everything worked like expected. BUT when the script was loaded twice H.service.Url.MultiValueQueryParameter didn't return the correct params. It basically encoded them twice, or tried to.
The other side issue was that https://www.npmjs.com/package/#types/heremaps is outdated and doesn't cover MultiValueQueryParameter. So I had to remove the types and use my own. Else I probably would have realized the issue earlier.
I can get basic html text to flip 180*, but I'd like to know how to get a whole Doc in my Drive file to flip using a standalone script (so I can do it repeatedly). I'm aware I can get a doc, open the scripts editor and then use my flippin' project to flip the doc I called, but I don't know what the syntax looks like. My first flippin' success was pasting text into the .html file as simply as possible and using:
function doGet() {
return HtmlService.createHtmlOutputFromFile('Page');
getContent()
}
I just test ran it from the dialog box as a web app. But I'm interested in building this one command feature out into several different domains to get experience with the variety of possibilities available in GAS. Anyone care to tutor me? Please?!...
document_name ='TestDoc'
document_path = ("/Users/Me/QA/Project/Documents/#{document_name}")
File.new ("/Users/Me/QA/Project/Documents/#{document_name}") # => File is created
filename_field.send_keys("#{document_path}")
filename_field.send_keys :tab # => To Trigger event but where error occurs
filename_field = browser.file_field(:name, 'file') declared in a module elsewhere.
As far as I can tell, I have provided an absolute path for the filename to upload the file but when the tab key is sent, an error occurs of:
Selenium::WebDriver::Error::UnknownError: unknown error: path is not absolute:
With an odd squiggly symbol in RubyMine that I've never seen before. Any ideas?
Update:
I added
puts filename_field.value
# => C:\fakepath\TestDoc
Spoke to one of the developers and she said "Browser does it to fake things out, so the filesystem isn't exposed". Not sure if that helps solve my issue or I'm SOL?
That error comes from Chromedriver, and comes from sending an incorrect path string to a file element. Since :tab is not a path, it is correctly raising an error.
You shouldn't need to send a tab; just sending the path of the file should accomplish what you need.
I see many small strange things in your code.
Why
document_path = ("/Users/Me/QA/Project/Documents/#{document_name}")
Not
document_path = "/Users/Me/QA/Project/Documents/#{document_name}"
Why
filename_field.send_keys("#{document_path}")
Not
filename_field.send_keys(document_path)
But the main question is why you are using send_keys instead of set?
I failed to reproduce your problem. Maybe it will be possible if you will provide your html. But i suggest you to try:
filename_field.set(document_path)
Because you can easily check it even with irb send_keys is acting differently in firefox and in chrome for example. So maybe problem with it.
Another suggestion
That is a much more weak idea. But...
Try to clear value before changing it. You can do it with javascript:
b.execute_script("arguments[0].value=''", field)
I had the same issue with Chromedriver 2.26.436421 and it was solved when I removed the code which was sending the tab key.
With previous Chromedriver sending tab key was required to trigger the change event on the file input but with latest one it seems like it is only causing issues and the change event gets triggered without it.
I wanted to place a google static map in a pdffile generated by using the fpdf extension.
and used code to make a tempfile first. Using this code. However I run into an error ('can't open image file').
// define the mapurl
$fullURL = 'http://maps.googleapis.com/maps/api/staticmap?center=Amsterdam&z=14&size=100x100&sensor=false';
// create a tempfile
$tempF = tmpfile();
fwrite($tempF, file_get_contents($fullURL));
//Rewind to the start of file
rewind($tempF);
// place the image in the pdf.
if (!empty($tempF)) {
$this->Image($tempF,$start_x, $this->GetY(),0,100);
}
fclose($tempF); // remove the tempfile
Note: OP's own answer extracted from the question.
Then I found out it can be done much easier... I don't need to use a tempfile. If I put the url in the image variable and give a format the thing works in two lines.. I don't use the height and width parameters in fpdf because they stretch the image into a unreadable form.
$fullURL = "http://maps.googleapis.com/maps/api/staticmap?center=". \
$row-Google_coor."&zoom=10&size=2200x200\
&markers=color:blue%7Clabel:D%7C".$row->Google_coor;
$this->Image($fullURL,$start_x, $this->GetY(),0,0,"PNG");
Saddly when using this function sometimes the program returns an error. The image could not be found. But when I put the url string in the browser the image shows up fine. Hopefully this is also a minor fallback.
Lets see if I find a solution on the google apis site https://developers.google.com/maps/documentation/staticmaps/?csw=1
For what it is worth I had this problem as well, I found that my server had an outgoing connections manager, this would automatically block the request, I had to add the ip, once this was done it worked fine.
I had a problem similiar to the OP's. I was getting an error when using FPDF and trying to get the static map image from Google Maps and into my PDF. I was getting "FPDF error: Missing or incorrect image file". What I did is to register in the Google Developer Console and get an API Key, just like they say in the documentation
Hope this helps.
You can download the image and use it with fpdf
$url ="https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=".$googleApiKey;
$img = __DIR__.'/img/map.png';
file_put_contents($img, file_get_contents($url));
$pdf->Image($img,null,null,170);
Hope that this will be helpful
I need to display google map with zip code boundaries like this
http://maps.huge.info/zip.htm
Perhaps I am overlooking it, but I've not been to find examples of this and documentation talking about this specifically at Google Maps API documentation. I've trying doing a view source on the above web page link, but it doesn't seem obvious to me how it works. There is also other stuff on the page which I don't know if it's part of what I need or not.
Some simple code examples would be very helpful! Thanks!
If anyone still looking for the solution here is how I managed to draw boundaries.
Download zip file from http://www2.census.gov/geo/tiger/TIGER2014/ZCTA5/tl_2014_us_zcta510.zip (its around 500mb)
Unzip it, u need the shp file from the extracted files
On windows u need to install QGIS, to get the ogr2ogr utility
Run the command to get geoJSON file from shp file:
ogr2ogr -f "GeoJSON" -lco COORDINATE_PRECISION=4 -simplify 0.00010 zipRegions.json tl_2014_us_zcta510.shp
You can play with simplify to remove extra points and compress your data
Create free account on cartodb
Upload zipRegions.json file there
Now using cartodb.js file you can draw zip code regions on google maps easily
Simply by code like this
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(42.1038846,-72.5868353),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
cartodb.createLayer(map, {
user_name: 'your_user_name',
type: 'cartodb',
sublayers: [
{
sql: "SELECT * FROM cartodb1",
cartocss: '#cartodb1 {polygon-fill: #7bd490;polygon-opacity: 0.7;line-color: #6da57a;line-width: 0.5;line-opacity: 1;}'
}
]})
.addTo(map, 0) // add the layer to our map which already contains 1 sublayer
.done(function(layer) {
console.log('Fine');
})
.error(function(e) {
console.log(e);
});
Google Maps API will not provide you with this data. You need an external source. A Fusion Table could be of some help. You can check this one *.
You then need to create your own layers from the KML data that is in the table. There is documentation about it.
You can render the data directly from the Fusion Table or import it to your own database, which is often preferable for performance.
Hope this helps to get you started. Try to find your way and if you are stuck, then ask another question and show us your code as the first comment suggests.
* FusionTables was discontinued on 3 December 2019.
Working on the same thing and found boundaries-io way too expensive for our use case.
Check out https://www.maptechnica.com/
Much larger data set
Much more affordable
I parsed the 2016 census kml file (over 150MB) to over 32,000 individual kml files you can use as a kml layer for your maps.
I put a zip file here:
https://github.com/tomeralmog/zipcode-kml
Hope this helps
A Very Simply API exists for this query by zipcode,city,etc.. returns geoJson
http://www.boundaries-io.com
Image of the results in GooleMap:
I know this is a relatively old question and #tomer-almog has done some great work making KML files, but I stumbled on this free resource (no relation, just using the data) that has zip code data in verious geo formats (GeoJSON, KML, etc)
https://public.opendatasoft.com/explore/dataset/us-zip-code-latitude-and-longitude/table/
Might be usefull for someone....