I'm trying to decide if I want to use json or kml to store polygons in a file on a server. I have to read in this file and check which polygon a given point is within. I am attracted to kml because I can render an entire kml file in two lines with the Google Maps Javascript API :
var importedKml = new google.maps.KmlLayer('mykml.kml');
importedKml.setMap(map);
However, I can't find a built-in function for checking if a point is inside all the polygons in a kml file. I know I can check to see if a point is in a polygon using the code below:
google.maps.geometry.poly.containsLocation(latlngPoint, polygon);
but it looks as though I'd have to parse the kml and turn every
<Placemark><Polygon>
feature into a google.maps.polygon object first.
I've thought about going back to json, since json objects are extremely customizable and I could directly call something like
//json object polygonFile from server
google.maps.geometry.poly.containsLocation(latlngPoint, polygonFile.polygons[0].polygon);
with a structure I have built myself. There's no quick and easy way to render json to the map without first converting it to google maps objects and then rendeing those, though, it appears.
Is there a way to check if a point is within a polygon in a kml file without converting each feature to google maps objects first? If not, converting a json object to google maps objects sounds like the way to go.
what about GEarthExtensions . There is a function "containsPoint" for an Polygon object
here is an example:
http://code.google.com/p/earth-api-utility-library/source/browse/trunk/extensions/examples/point-in-poly.html
Related
I'm experimenting with d3.js and plotting data on maps.
My data only has general city/state information. It doesn't have lat/long.
Looking at the tutorials online, all the data they have is already in a geojson format.
Questions:
Is there a way to plot on a map without lat/long info? i.e. the map
is able to intelligently intrepret something like "Chicago, IL"
If not, What is the current best practice to map general arbitrary
location data like i have into a geojson format? I'm wondering if
there is a better way than just manually trying to map it using some
random source i find online.
I'd like to ask if its possible to load .terrain maps from "Tiled" in plain javascript without any frameworks or something...?
Or do you recommend using another map editor supported by plain javascript on websites?
It will be used in canvas as a map for players to play in.
Tiled supports saving and loading the map as a JSON file, which you can load in plain JavaScript with JSON.parse.
You can also save the Tiled map as JavaScript file. Then the data gets wrapped with some JavaScript code that can make it easier to use in a browser.
For easiest parsing, you'll want to make sure to use the "CSV" tile layer data format. But you'll still need to map the global tile IDs to the right tile from the right tileset (after clearing the tile flipping flags if you use that feature). See the TMX Map Format for how this works.
I have readed the API for elevation for Google Maps and what I can understands I must have the map visible to get the elevation for a point (coordinates). But almost nothing is impossible with JavaScript so I wonder now, is it possible to get the elevation from a point without viewing the map?
Thanks in advance.
Do you know what the co-ordinates are for the point? If so, the API for elevation will return the elevation, in both JSON and XML formats. I use the following URL (albeit in PHP, it should work the same for Javascript):
http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations=1.111,1.111.
You'll need to parse the results in JS. Switch XML out for JSON in the URL to change the result type.
Edit: If you use this service, you need to use it in conjunction with a Google Map as per their terms and conditions.
Follow geoXML3 api.. after every KML parse a JSON object mapping all tags is created.
SO is it possible o get that JSON object, make some modify, like update or remove some element.. AND create a NEW kml (dynamically) and show that changes visually?
I tried many times to modify the Json object but all modify in json not affect the kml rendered ..
..so the solution is create a new kml and show..( BUT HOW ?)
geoxml3 is a KML parser, it doesn't have the ability to create KML. You can add code to traverse its arrays holding the native Google Maps API objects and create KML that represents them.
If you want to modify the rendered Google Maps API objects, they are stored in arrays, you can get references to them and modify them dynamically.
I do not have a complete example (at least that I recall), that traverses the native Google Maps API objects and creates KML, but this page will create the <coordinates> piece for a single piece of a polygon:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_winding_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/crues_450_windingFix_kml.xml
I am looking for examlpes of how to use polylines in V3 of Google maps, I have read the help at Google but must admit I don't fully understand. I feel if I could see a good example I might understand it better. What I have is a site that I track my vehicle I have it plotting the points on the map what I want is to draw the line between the points. I am using a mysql database and a XML file with PHP to display the point on the map.
Any help would make my day. I have found this site very helpful and I wish to thank all.
Take care, all the best
It's a matter of creating a KML xml file, using data from your database, and feed google api with that. You can use this tool to interactively see how the kml file changes while adding points to the polyline.
EDIT:
Create a script in your preferred scripting language which retrieves the points from database, and generates a kml file format as in the third link above.
In your javascript script, you need to add a kml layer to the map, loading the kml you generate on the fly in your script at point 1. :
[...]
var map = new google.maps.Map(document.getElementById('map'), options);
[...]
kmlFiles = new google.maps.KmlLayer("http://yourdomain.com/generatekml.php");
kmlFiles.setMap(map);
and that's it.