Loading .terrain files from tiled to plain javascript - javascript

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.

Related

How can i convert .txt to .gpx with an API in web or get GPX export?

i'm working on a web mapping project with openlayers (a JavaScript API for web GIS) and i need to make a option for users to get .gpx Export from coordinates that they have been before.
I am making an option to export TXT with a JavaScript API.
Is there any API to convert my TXT to GPX?
Is there a different method for exporting GPX files?
Sure that's possible with OpenLayers 3. You dont need to create an TXT first and then convert it to the GPX. In OpenLayers 3 there is a function called ol.format.GPX() which will convert your features to a gpx format. With writeFeatures() you can add you features to the ol gpx object. Here is a working JS FIDDLE.

Point inside polygon -- json or kml?

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

Using geoxml3 json object to simulate a update method?

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

Looking for examples of polyline with google maps V 3

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.

finding shortest paths using google maps for a large number of nodes

I'm trying to do some network analysis for a client. The provided road-network GIS layer is of bad quality; therefore, I have to resort to Google maps to provide me shortest path between 200 points, to produce time and distance matrices between each point.
is there a way i can input the layer as a set of KML points to obtain outputs of the distance and time between these points ?
if this is doable via the api, do you have any hints or suggestions on how to write such a script?
EDIT
the ideal final result would be a CSV file of the following form:
node_1, node_2, distance, travel_time
node_n, node_m, distance, travel_time
I won't write the whole script for you, but this can be done with the maps API. Open up the maps sandbox and add to the onGDirectionsLoad function:
alert(gdir.getDistance().meters);
You can find the documentation here - a getDuration() is also available. Then all you need to do is issue a new request once one finished, getting directions for each pair of start and end point.
However, note that if you're planning on getting 200*200 paths, google may decide to rate limit you at some point. Use this method at your own risk, and with a delay between requests.
Note also that google's builtin KML support doesn't seem to support giving you the list of points - this makes sense, since the client may only have those that are currently onscreen. You might need to write your own KML loader if you want to use KML as the input format. Or use a simpler format, as in this example.

Categories

Resources