I need to get markers, overlays and etc, that were loaded from KML, but i don't understand how.
Here https://groups.google.com/forum/?fromgroups=#!topic/umapper/YCfHEWaCxMc is written that i can loop through KMLayer. but i can't!
I loading KML that way:
var nyLayer = new google.maps.KmlLayer("http://www.searcharoo.net/SearchKml/newyork.kml", { suppressInfoWindows: true, map: map });
Then i don't see anyway to find what objects inside. I tried to look in debugger what nyLayer contain inside, but nothing like objects array. Also tried this:
var test = nyLayer[0];
But test is undefined
You can't access the Placemarks in a KmlLayer other than by using a click listener.
You can access them if you use a third party parser like geoxml3 or geoxml-v3, but then you lose the advantage of the KmlLayer's tile based rendering, so you will see performance degradation for large numbers of objects.
Example which creates a dynamic sidebar using geoxml3
Related
when using new beta feature LocalContextMapView from Google map, as described in https://developers.google.com/maps/documentation/javascript/local-context
How does one refresh the localContext when the map is panned/zoomed ?
LocalContextMapView place search is strictly bound by the map viewport by default. You can use the locationRestriction parameter to set a bounds to be much larger than the map's initial viewport.
You can find the sample implementation here: https://developers.google.com/maps/documentation/javascript/local-context/samples/location-restriction
And, since Local Context Search is still in beta, I highly suggest that you file a feature request for having a function to set locationRestriction programatically/dynamically.
For example, having a localContextMapView.setLocationRestriction() property would be a great addition to the Local Context Library. You can use Google Public Issue Tracker to file a feature request.
I'm am trying to use a maps engine layer in google maps api v3 and am running into issues with events and opacity (accepted enhancement) for raster layers.
The issue is that raster type data does not allow any events as far as I can tell.
var layer2 = new google.maps.visualization.MapsEngineLayer({
layerId: '15658084116283052074-13711557424617485464',
map: map,
clickable: true,
suppressInfoWindows: false
});
google.maps.event.addListener(layer2, 'click', function (event) {
alert('click');
});
Demo (jsbin) with vector maps engine layer and raster layer here. Is there something I'm missing or is it simply not implemented?
Documentation:Maps Engine Layers
Edit: I would like to get the pixel value of the raster.
The click event in a DMEL is fired when a feature is clicked. In Maps Engine, a feature is the same as defined in GeoJSON. That is: a single geometry, or table row in your data set.
As raster layers are not attached to a tabular data source, they don't contain individual features like points and shapes.
Raster layers are much like the base layer in the map however, so you can grab a click event at the map level. e.g.
google.maps.event.addListener(map, 'click', function (event) {
alert(event.latLng);
});
I'm not sure what your intention is beyond just a lat/lng pair though. If you wish to interrogate pixel data you may be better off putting the raw data into a table.
I am new to Google maps api v3.
In the Google maps official tutorial, some of the sample code using
new google.maps.Marker({
map: map //Map option
});
or
new google.maps.Marker({
//some options here
}).setMap(map);
What are the difference between each other?
Off the top of head:
You can create markers and add them to a map at a later time e.g. after clicking some button using setMap()
You can have multiple maps on one page. You can selectively add markers to any one of them using setMap()
You can also remove markers selectively from a map using setMap(null)
assuming you mean google.maps.Marker both codes finally result in exactly the same.
The first code initializes the Marker with a map-property, while the second code initializes the marker without the map-property and sets the map-property of the already initialized marker.
I am trying to render a whole heap of vectors in the google earth plugin. I use the parseKml method to create my Kml Feature object and store it in an array. The code looks something like below. I loop over a list of 10,000 kml objects that I return from a database and draw it in the plugin.
// 'currentKml' is a kml string returned from my DB.
// I iterate over 10,000 of these
currentKmlObject = ge.parseKml(currentKml);
currentKmlObject.setStyleSelector(gex.dom.buildStyle({
line: { width: 8, color: '7fff0000' }
}));
ge.getFeatures().appendChild(currentKmlObject);
// After this, I store teh currentKml object in an array so
// I can manipulate the individual features.
This seems to work fine. But when I want to turn the visibility of all these features on or off at once, I have to iterate over all of these kml objects in my array and set their individual visibilities on or off. This is a bit slow. If I am zoomed out, I can slowly see each of the lines disappearing and it takes about 5 - 10 seconds for all of them to disappear or come back.
I was wondering if I could speed up this process by adding a layer and adding all my objects as children of this layer. This way I set the visibility of the whole layer on or off.
I have been unable to find out how to create a new layer in code though. If someone can point the appropriate methods, it would be great. I am not sure if a layer is the right approach to speed up the process either. If you also have any other suggestions on how I can speed up the process of turning on/off all these objects in the map at once, that would be very helpful as well.
Thanks in advance for you help.
Ok, found out how to do this by myself.
In the google earth extensions libarary I use the 'buildFolder' method.
var folder = gex.dom.buildFolder({ name: folderName });
ge.getFeatures().appendChild(folder);
Now, when I iterate over my object array, I add them to the folder instead using the following
folder.getFeatures().appendChild(currentKmlObject);
This way, later on I can turn the visibility on and off at the folder level using
folder.setVisibility(false); // or true
And this works quite well as well. IThere is no delay, I can see all the objects turning on and off at once. It is quite quick and performant.
I want to be able to show movement in a google maps just like in this example
http://www.labnol.org/internet/live-flight-tracking-google-maps/12308/
I am starting, and followed an example to load markers from mysql and put them in a map. But this is all static. If I keep track of a moving object in my database, how can I display them in real time?
Thank you
Assuming marker is your Marker instance, you should use some Ajax call to get new coordinates, depending how you return them, lets say your script will return an Object of lat and long and assign it to variable new_location. Now you need to change marker position to new coordinates:
function change_pos(new_location) {
var LatLong = new google.maps.LatLng(new_location.lat, new_location.long);
marker.setPosition(LatLong);
}
Just call this function everytime you got replay from Ajax.
And thats it.