I am trying to create a Windows Phone 8.1 (Runtime) app that has a Map Control on it. I would like to attach additional data to the OnMappedTapped event or a way to grab an assigned Location ID when someone clicks on the MapIcon. Is this possible?
Yes. If you want to do something when someone clicks on a MapIcon (pushpin), then add a tap to the map and then do a search for elements that intersect the touch point using the Map.FindMapElementsAtOffset method: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.maps.mapcontrol.findmapelementsatoffset.aspx
or the Map.FindSubElementsForTouchTargeting method: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.uielement.findsubelementsfortouchtargeting.aspx
When it comes to storing or associating data to a pushpin, I like to store my data in the standard Tag property as that's something I've been doing for a while with WPF and Silverlight. You will notice that the MapIcon/MapElement classes do not have a Tag property, however they are DependancyObjects which meanswe can easily add custom properties to these classes. Here is a simple extension I often use in my WP apps to add a Tag property to these classes.
public static class MapElementExt
{
public static readonly DependencyProperty TagProperty = DependencyProperty.Register("Tag", typeof(object), typeof(MapElement), new PropertyMetadata(null));
}
You can then set this value like this:
pushpin.SetValue(MapElementExt.TagProperty, MyPinData);
Personally, when it comes to pushpins I normally don't mess with the MapIcon/MapElement classes and just create a UIElement for my pushpin. By doing this I can easily have a lot more control over creating my pushpin and can also easily add Tap events. You can specify the location for a UIElement like this:
MapControl.SetLocation(pushpin, MyGeopoint);
And then add the pushpin to the Map.Children property.
If you want to get the coordinates for a randomly selected point on a map through a touch event you can take the pixel coordinates from the tap event and pass them through the Map.GetLocationFromOffset method. For example:
MyMap.Tapped += (s, e) =>
{
Geopoint loc;
MyMap.GetLocationFromOffset(e.GetPosition(MyMap), out loc);
};
Related
i am using a CesiumJS instance to display a base map of the earth using a imageryProvider from source A.
var viewer = new Cesium.Viewer('cesiumContainer', imageryProvider:providerA);
Now while using the Viewer I would like to be able to change this map to get images from providerB at a certain event.
I tried:
viewer.scene.imageryLayers.get(0).imageryProvider.url = providerB.url
However that does not seem to work and also feels quite like hack anyway.
I could not find anything in Cesium's documentation .
Is this at all possible without restarting / recreating the viewer instance?
I know that there is a Cesium.BaseLayerPicker (https://cesium.com/docs/cesiumjs-ref-doc/BaseLayerPicker.html)
However I do not see what method this picker calls on "select" )
Thanks a lot.
The BaseLayerPicker widget calls this code when the user selects a new layer.
There's a lot of boilerplate widget management in that block of code, but for your sake, only a couple of the lines are critical. First, the old existing active imagery layer is searched for, and removed:
imageryLayers.remove(layer);
Then, a new imagery provider is constructed and added at index 0, the first position, which is the base imagery layer:
imageryLayers.addImageryProvider(newProviders, 0);
You can directly change the URL of the provider but you should also change appropriate parameters("layers" in case of WMS, "layer", "style", "format", "tileMatrixSetID " ... in case of WMTS) depending on the type of provider(WMS or WMTS).
So I basically have an application with three tabs. On one of them, I have a Google Map with corresponding markers and a listener with a location based Firestore query. When the tab is selected, nearby elements will be queried and presented on the map.
However, when I change the tab and go back to the map again, the map, the listener and all the markers will be setup again (since initState() and dispose() were called).
What is the best way to save all the states from the map and continue on the previous state of the map, when the page is selected?
I have read something regarding Redux and BloC, is this the pattern I will need here? If yes, how can this be applied to the GoogleMap?
I had the same problem, Flutter is basically reloading your googlemaps page everytime you change page. I solved this using IndexedStack. So I have all my pages in the stack all the time and they wont reload. I'm not sure if this is the best way but it works.
child: new IndexedStack(
children: _pages,
index: widget.currentItem,
),
IndexedStack only shows the index item of the Stack, but all the items are in the stack even though they are not shown, so they wont be reloaded when you change the tab. Change the currentItem depending on the index of TabBar index with setState...
You can actually force Flutter to keep the widget tree alive using AutomaticKeepAliveClientMixin like so:
class LocationMapScreen extends StatefulWidget {
#override
_LocationMapScreenState createState() => _LocationMapScreenState();
}
class _LocationMapScreenState extends State<LocationMapScreen>
with AutomaticKeepAliveClientMixin {
#override
bool get wantKeepAlive => true;
// ....
}
I am making an 2d rpg game with box2d. So, I've got a problem. When one of my bodies(the character) collides with another(a door) the map needs to change, should I just create new screens for maps and change them? Or is there a more simple solution?
You can change your current map on the same screen only. What you have to do is, Let's say your map variable name is testMap. Now let's say your player just collided with a door. Now let's say you will call a method called changeMap(). Here is what you will put inside changeMap() method. (Assuming you are using tiled maps, you can change logic accordingly here)
void changeMap() {
Gdx.app.postRunnable(() -> { //Post runnable posts the below task in opengl thread
testMap = new TmxMapLoader().load("someMap.tmx"); //load the new map
renderer.getMap().dispose(); //dispose the old map
renderer.setMap(testMap); //set the map in your renderer
});
}
For educational purposes, I want to extend the WP8 Map control to add a property for the current location (e.g so I can call myMap.CurrentLocation) and then use this custom control in my XAML template. Is this even possible?
If it wasn't sealed you could just inherit form it and add whatever other properties you want.
Unfortunately it is sealed so I'd suggest creating a new UserControl which includes a map instance and then add whatever other properties you want to that control. Make the new properties either regular ones or DependencyProperties as necessary you could also create wrapper properties to those of the map control or expose the inner control directly. It will depend on your specific use cases.
A similar question was already asked, but does not have a satisfying answer.
I want to change the CSS style for the map type selection buttons (which are actually DIVs that don't have a CSS class). The links in the referenced question show how to subclass controls, but the examples don't seem to work for GMapTypeControl. Tried the following
function CustomGMapTypeControl() {}
CustomGMapTypeControl.prototype = new GMapTypeControl()
CustomGMapTypeControl.prototype.setButtonStyle_ = function(button) {
button.style.backgroundColor = "red";
}
but the setButtonStyle_ function doesn't even get called.
Any solutions for this?
From the above code, I can say that you don't fully understand how to create a custom map control. There are 2 steps:
subclassing GControl
provide initialize() and getDefaultPosition() method.
Well, the initialize method is the place you create and style your control dom elements, and this method must return that dom element back. The getDefaultPosition() method indicates where this control should be placed (top-right,...), and it must return an object of type GControlPosition.
You must provide enough information so that when you call map.addControl(new CustomGMapTypeControl()) so that the map object could invoke and do the right things.
NOTE: All map controls should be added to the map container which can be accessed with GMap2's getContainer() method.
You can play around with http://code.google.com/apis/maps/documentation/javascript/v2/examples/control-custom.html when you want to create your own custom control with firebug.