select polygon loaded from kml having its title - google-maps-api-3

I am trying to select a polygon loaded from kml (in js) from its title but I do not know how (I found only from js variable if manually defined the single polygon). Is this possible?
If not, what is the best way to "copy" a selected polygon (define a new polygon take the data from the selected one) on a double click event (for example for show it with a different style) and delete the loaded kml (with hundreds of polygons)?
Thanks for any reply and sorry for my bad English.

I not found a way to point directly the polygon loaded by kml for title but thanks to this example using geoxml3 that parse, show kml and permit "after parse" operations and with I reached the goal, although with a lot of code for a few small operations. Thanks to the people that worked on them.

Related

Does a polygon loaded from a KML contain a given Lat/Lng in Google Maps API

I have a KML file which contains a polygon. I am wanting to write a simple application which will give a true/false result on whether a lat/lng is inside of that polygon.
For whatever reason, this seems to be more difficult that it sounds, as the google.maps.KmlLayer seems to be very limited with the functions it offers.
I am aware that a non-KML map has a "containsLocation()" function which does exactly what I need, however, the KML layer contains no such function
I am not quite sure how you are using the KML file however I would suggest the following approach:
Parse your KML file (Many libraries available for many languages)
Use the parsed KML data to render your Polygon using the Google Maps API (i.e. reconstruct you KML polygon in Google Maps with the Google Maps methods)
Use the Google Maps API containslocation() method to check whether a co-ordinate is inside the Polygon
The Google Maps API has a large feature set so by doing this you could incorporate some of their methods, i.e. You click on the map and the program tells you wether the point you have just clicked is inside the polygon or not. Have a look at this, I suspect this is what you want to accomplish (or at least similar to it).
Edit: By parse I mean decode the KML

Loading a KML file - is there a limit to the number of points?

I was loading 6,000 points of interests from a single KML file but it's not loading. What I did is to split it in 4 KML files. It loads but it's quite slow. My questions are:
Is there a limit on the number of points I can put in the KML file?
Is there a code to speed it up? I just used these codes to load the KML files:
kmlManager.parseKML("./SOURCE_KML/Part1.KML")
kmlManager2.parseKML("./SOURCE_KML/Part2.KML", onParsed);
kmlManager3.parseKML("./SOURCE_KML/Part3.kml", onParsed);
kmlManager4.parseKML("./SOURCE_KML/Part4.kml", onParsed);
Obviously there must be some limit to the number of points read/displayed from a KML file. Since you haven't mentioned how large your file(s) are and what the time taken for each stage of processing it is difficult to tell where in the chain of actions your file or files are being so slow.
It could be any of the following:
Network connection/download of the KML. Speed is based on your network.
KML processing as done by the HERE Maps JavaScript Library. Speed is based on the browser used.
Actual rendering of Points on the map as done by the HERE Maps JavaScript Library. Speed is based on the browser used.
Programmatically there is nothing you can do about point 1. If it takes time to load then so be it. This is basically a user interface issue (managing expectations), your technique of chunking up the data and loading a smaller files is probably a good one. Combine this with a wait icon to show the user that something is happening.
Regarding point 2 - you should consider whether KML is the correct (i.e flexible) format for processing your data. Other file formats could be shorter or could hold your data more concisely. Maybe you need to use some custom processing prior to display. This example uses AJAX and the KML Manager parse() method prior to displaying the file. This allows customization of the KML prior to rendering.
Regarding point 3 - there is something you can do about this - adding and rendering 6000 Markers directly is bound to take time. This can be alleviated by marker clustering - i.e. only rendering a fraction of the markers at any one time.
Consider the data visualisation KML Earthquake example from developer.here.com - the example blindly renders a given KML file with approximately 300 points. At the size shown below the points overlap and can't be easily distinguished anyway:
Now if you want to modify the rendered result it would be better to preprocess or use another format such as GeoJSON, and customize the response. An example combining GeoJSON parsing and marker clustering can be found in the HERE Maps community examples. This renders a fraction of the data and hence displays the data file more quickly.
Obviously if you have 6000 points rather than 300 the improvement will be even more noticeable.

Google Maps - How do I efficiently create a polygon with many points?

I need a polygon for every German state. I go all the GeoPoints in one JavaScript-file but the file is because of the amout of points about 4MB. I've been googling and thinking about this problem all day but couldn't figure out a solution...
How can I use Google Maps polygons without forcing the user to download a huge js-file with the coordinates?
Thanks!
Ron
You can encode the polygon points to vastly reduce the size of the javascript file. To do this, you must include the geometry library.
https://developers.google.com/maps/documentation/javascript/reference#encoding
https://developers.google.com/maps/documentation/javascript/geometry#Encoding
One option is to use a FusionTablesLayer to display the polygons. They are available in the Natural Earth data set that is publicly available.
Example
You could do the same with your points and a KmlLayer if you convert your data to KML.
Well... somehow the points have to get to the user. You could think of the following solutions to reduce the data usage:
Use different polygons for different zoom levels. For example zoomed out you won't need the full details.
only send parts of your polygon back to the user. You can for example send the viewport coordinates to an AJAX script. This one queries your database and/or shapefile and only returns the polygon parts that are visible in the user's viewport
preprocess tiles. If you can generate images from your shape, you can overlay these on Google Maps.

How to modify weather information displayed on google map

I have created a google map displaying markers and the weather layer using Google Maps API V3.
The weather layer is great for displaying weather information at well-known locations; however, for my map I only care about the wind speed rather than the forecast (ex. sunny, rainy, etc). Is there any way to modify the weather layer so that it displays "wind: s 5m/s" directly on the map instead of the sun/rain icon?
I realize that you can click on the icon to get the wind information but given that we do not care about the actual weather, we do not want people to have to click to get that. Instead we want the wind displayed directly.
(If it is not possible, then any alternative suggestions would be greatly appreciated as well :) )
I made a Weather API available on mashape, and they have a ready to use simple PHP SDK.
This api is really simple to use because we use the cool standards that are available nowadays, like JSON and REST.
If you like it please give it a try on mashape
I've tried but haven't found a way to change how the weather icons look when they are loaded.
It is possible (as you may know) to create a custom overlay using discrete weather data items (like wind speed) when a weather icon is clicked but that wouldn't seem to solve your problem.
See" "google.maps.weather.WeatherConditions object specification" in the V3 API reference
Like many of these kinds of things, I imagine it is theoretically possible to scan the DOM, find the weather 'markers', extract the info you want and redraw them as you wish them to look, but you may (unsure about this) find that the weather icons are actually images and data like wind speed doesn't actually exist in the DOM until the weather icon is clicked: The discrete data may be the product of an ajax load in response to the click event. Even if you got a DOM crawler to work it could be broken by a new release of the API and you'd never know what hit you.
Best bet may be to submit a change request to the API developers asking for the ability to format the weather icons and specify their content.
or
Use some other online source of json or xml weather data and create your own weather markers, labels, or whatever on your map.
Sorry I can't provide a more constructive answer :-(

Google Earth api get coordinates

here goes a simple question:
I've got a showKmz() function which receives an URL belonging to a KML/KMZ file and which goes straight ward to a fetchkml() method, after that it gets appended to my Google Earth instance.
Now I want to recover the coordinates of this fetched KML/KMZ file and use them to immediatelly after load a custom ico I want to put exactly on the same location of the KML/KMZ file I fetched.
The reason for that is that I want to show this files on Google Earth with their clicable icon despite of whatever icon those KML/KMZ could have by default...
Does anybody knows a way to either achieve the goal of retrieving the coordinates or even better: a more direct way to make this custom icon superposing I want?
Thanks in advance!!
Bye!!
From here
http://code.google.com/apis/earth/documentation/kml.html
When getting a KML/Z file with fetchKml, you have in the callback an option to interact with the KMLFeatures you've obtained before appending them to the globe. There could be several items in that file which have coordinates, as well as several icons. So it sounds like you want to get the features, iterate over them, and insert an IconStyle for each (or replace existing IconStyle) to have it render with the Icon you want. You don't have to place a new feature at the same location as the existing ones.

Resources