Remove invalidated marker - here-api

I have a H.map.Group with a bunch of markers.
If i need to remove a single marker i run:
this.markerGroup.removeObject(marker);
But sometimes in other part of my code i run:
this.markerGroup.removeAll();
So if after i run single marker remove method it throws me an error, because there is no such marker on markerGroup layer because all markers were removed previously.
How can i know the marker is valid and exists on a map so i can remove it correctly?
In Yandex Maps i have isValid method so i can validate marker before making some actions with one:
marker.isValid && markerGroup.remove(marker);
If isValid is true it means the marker has geometry and it is on a map, if false means the marker just exists in memory and not attached to the map.
What is equal functionality in Here maps?

H.map.Marker#getParentGroup() or H.map.Marker#getRootGroup() should work for that case.

Related

MapsUI polygon blocks mapClick

I have a layer with a number of polygons, where the layer is marked as NOT being an infolayer
myLayer = new Layer() { IsMapInfoLayer = false...
I also have an eventhandler for clicking the map defined in the xaml
MapClicked="myClickHandler"
This click works well on empty areas, but if I click a polygon, the map click is blocked. Previously I solved this by responding to the info event handler for the polygons and route that to the same code that handled map clicks, but that is not enough now, as I need the lat,lng of the clicked position.
How do I make the polygons not intercept my click?
If a feature is clicked the MapInfo event is called. If not the MapClicked event is called. This is by design. You mention IsMapInfoLayer is set to false. In that case no MapInfo event should be triggered and you should get a MapClicked event. Note, that the MapInfo event could also be triggered from another layer.
A workaround for your problem: The MapInfo event also contains the WorldPosition but it is on SphericalMercator coordinates. You can translate that with:
var latLon = Projection.SphericalMercator.ToLonLat(point.X, point.Y);

Google Maps Engine Image Layer Events

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.

Google maps setMap() and map options

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.

How to loop through loaded KML in maps api v3?

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

How can I display moving object in google maps api 3

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.

Resources