This translation is older than the original page and might be outdated. See what has changed.

MAPVIEW


Methods of the prop Z, viewmode="mapview"



Attributes to put in the props of the content collection:

ATTRIBUTES
mapview-address=“true” POI Address
mapview-latitude=“true” POI Latitude
mapview-longitude=“true” POI Longitude
mapview-marker-icon=“true” POI icon


ATTRIBUTES
zoom-to-my-location: with a true value it makes zoom to the current position, with a false value it doesn´t make zoom to the current position and it tries all the POIs are seen.
Show-pois: with a false value it doesn´t show the POIs drawer.
mapview-embedded: with a “true” value, this attribute embed the map in the collection where it has been defined. Value by default, false.
on-map-clicked: attribute to define the node when we make click on the map to be able to execute an action.



Example:

  Definimos en el prop type="Z" el siguiente atributo: on-map-clicked="onMapClicked"
  Nodo que ejecutar este atributo:
  <onMapClicked show-wait-dialog="false" refresh="false">
        <action name="runscript">
          <param name="nLatitude" /> <!--- parametro que recoge la latitud --> 
          <param name="nLongitude" /> <!--- parametro que recoge la longuitud -->
          <script>
                var window = ui.getView(self);
                ui.showToast("onMapClicked(), nLatitude: " + nLatitude + " nLongitude: " + nLongitude); 
              </script>
        </action>
      </onMapClicked>



METHODS:


Method that returns if the user has the geolocation enabled.

Example:

  var ventana = ui.getView(self);
  if (ventana != null) {
                    ui.showToast("Enabled: " + 		ventana.MAP_MAPA.isUserLocationEnabled());
}



Method that enables the device geolocation.

Example:

 var ventana = ui.getView(self);
 if (ventana != null) {
 	ventana.MAP_MAPA.enableUserLocation();
 }



Method that disables the device geolocation.

Example:

  var ventana = ui.getView(self);
  if (ventana != null) {
 	ventana.MAP_MAPA.disableUserLocation();
  }
 


Method that draws a line by connecting the point passed as parameter.

PARAMETERS Definition
PARAMETER 1Identifying name of the line.
PARAMETER 2Color of the line to be drawn.
PARAMETER 3Type of line to be drawn.
PARAMETER 4From the fourth parameter onwards, it defines the points by which the line is going to be guided in this format (Latitude,Longitude).

Example:

 var ventana = ui.getView(self);
 ventana.MAP_MAPA.drawLine("ruta 1", "#FF00FF", "dashed", 40.4167747, -3.70379019, 41.3850632, 2.1734035);
 ventana.MAP_MAPA.drawLine("ruta 1", "#FF0000", "normal", 40.4167747, -3.70379019, 43.3850632, 3.1734035);
 ventana.MAP_MAPA.drawLine("ruta 2", "#FFFF00", "normal", 39.4167747, -2.70379019, 42.3850632, 2.0004035);



Method that draws a route that connects two points .

PARAMETERS Definition
PARAMETER 1Identifying name of the route.
PARAMETER 2Latitude of the destination point.
PARAMETER 3Longitude of the destination point.
PARAMETER 4Latitude of the destination point.
PARAMETER 5Longitude of the destination point.
PARAMETER 6Type of line to be drawn.
PARAMETER 7Color of the line to be drawn.



Example:

  var ventana = ui.getView(self);
  ventana.MAP_MAPA.drawRoute("ruta 1", 40.4167747, -3.70379019, 41.3850632, 2.1734035, "walking", "#FFFF00");
  ventana.MAP_MAPA.drawRoute("ruta 2", 40.4167747, -3.70379019, 39.3850632, -2.1734035, "walking", "#FFFF00");
 



Method that clears the line to be drawn with drawLine.

PARAMETERIdentifying name of the line.


Example:

 var ventana = ui.getView(self);
 ventana.MAP_MAPA.clearLine("ruta 1");



Method that clears all the lines drawn with drawLine.

Example:

 var ventana = ui.getView(self);
      ventana.MAP_MAPA.clearAllLines();
 
 



Method that clears the route drawn with drawRoute.

PARAMETER Identifying name of the route.



Example:

var ventana = ui.getView(self);
ventana.MAP_MAPA.clearRoute("ruta 1");



Method that clears all the lines drawn with drawRoute.

Example:

 var ventana = ui.getView(self);
      ventana.MAP_MAPA.clearAllRoutes();



It adds a mark in the coordinates passed as parameter.

PARAMETERS Definition
PARAMETER 1 It defines the latitude.
PARAMETER 2 It defines the longitude.


Example:

var ventana = ui.getView(self);
ventana.MAP_MAPA.addMarker(40.4167747, -3.70379019);



It defines the function when we make click on the map.

Example:

var ventana = ui.getView(self);
ventana.MAP_MAPA.setOnMapClickedListener(function(nLatitude, nLongitude) {
                    ui.showToast("onMapClicked(), nLatitude: " + nLatitude + " nLongitude: " + nLongitude);
                    ventana.MAP_MAPA.addMarker(nLatitude, nLongitude);
                });