Using geoxml3 json object to simulate a update method? - javascript

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

Related

update a Array without duplicate Map based on a parameter

I am currently using ArrayUnion to update an Array in a Document in Firebase. It Consists of a Map of the format {userid:XXXXXX,value:01234}. Now lets say I want to change this value, I was initially thinking of just using ArrayUnion and send an updated map, But how do I remove the pre-existing Map. (In Other Words No Too Map in the array can have the same ID).
Seems like a long shot, but I was also thinking maybe we can just use a Map which has a timestamp attribute to showing when it was added, and then on the client side ill perform the actions of removing those entries which are older.
Which of the options is better? and do you have any better solutions for the same problem?
(Note: Using Firebase v9 for Web)
The only way you can remove a map item from an array without reading the document first is if you know the entire contents of the map ahead of time. If you do, you can use arrayRemove, passing the entire map as an argument.
If you don't know the entire map contents, then your only option is to read the document into memory, modify the array the way you want in memory, then write the entire updated array field back to the document.
It is not possible to do anything with a map inside an array if you don't know its entire contents. If you only know one field, you can't update it and you can't use it in a query.
See:
Firestore Update single item in an array field
How to update an "array of objects" with Firestore?

Google Apps Scripts: Is there a Key-Value List Datatype?

i wanted to use Google Apps Scripts to analyze a Google Sheet.
I want to analyze how common certain answers are and wanted to use a map or dictionary to implement this.
My problem is, no suitable datatype seems to work inside Google Apps Script. I also read the tipp to just use objects with a key value, but it doesnt seem like Google Apps Scripts support the values parameter, generally associated with javascript objects.
So are there any types of key-value datastructure, that i can use and that has working functions for giving out the keys or values ?
Are you looking for a datastructure to store and retrieve map type data or is it just for processing?
The PropertiesServices and the CacheServices are the closest to what you are looking for. However, they take only strings as keys and values so you can build a mechanism on top of it to support objects in addition to string values.
You can use this helpful library that was created by github user yinonavraham that supports putting/getting objects in Cache
https://github.com/yinonavraham/GoogleAppsScripts/tree/master/EnhancedCacheService
While yinonavraham has built it for the CacheService, you can easily build an equivalent for the PropertiesService following his lead.

Loading .terrain files from tiled to plain 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.

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

Google Map Location constructor with general location type

I have been using Google maps api to get customer to a specific location using a constructor like this
new google.maps.LatLng(42.999, 54.000);
With the exact longitude and latitude as the arguments. What I want to do now is not use the lat, long option and use a keyword like rest area that would bring up the closet rest area. I am not quite finding it in Google map api here https://developers.google.com/maps/documentation/javascript/reference
Can some one help me come up with a constrctor that can take a key word and locate the nearest one in googLe maps.
You're going to have to use the google geocoding API.
Basically you do a request to google with a search string and it returns an object containing the long/lat for areas it may have found... There's a lot of options in there and you can do fairly neat tricks which are already carefully explained by google themselves.
https://developers.google.com/maps/documentation/geocoding/
There are some limitations to the # of requests you can make per-day. To keep this to a minimum you can ofcourse make a server side script that pre-fetches results for things that will be re-used (for example the long/lat for office location of a large enterprise which may have a dot on a map on the website...).
Simplest way would be to make a json request with a few parameters and parse the return json in js, like getting the long/lat of the first result returned.
If I understand correctly, you want to use keyword search for things around a particular location. I would suggest using the Places library of the Google Maps API:
https://developers.google.com/maps/documentation/javascript/places#place_searches
This allows you to search by category or by keyword over Google's datastore of 10s of millions of Places.

Categories

Resources