Search
MapView.mapCenter Property
See Also
 






Gets the geographical center of a loaded map.

Namespace: MindFusion.Mapping
File: MapView.js

 Syntax

JavaScript  Copy Code

get mapCenter() {}

 Property Value

LatLong. A LatLong instance, representing the geographical center of the map.

 Example

The following code creates a new MapView using a <DIV> element called "mapview" that we've declared in the HTML code of the page and adds a new Marker to its decorations collection. It sets the center of the map to the location of the Marker:

JavaScript  Copy Code

// create a new instance of the mapView
var view = new m.MapView(document.getElementById("mapView"));
view.theme = "light";

// create a map layer
var l = new m.MapLayer("Map");
l.urlTemplate = "http://d.tile.stamen.com/terrain/{z}/{x}/{y}.png";
l.attribution = 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.';
view.layers.add(l);

// create some markers with images
var mark = new m.Marker(new m.LatLong(-22.951916, -43.210487));
mark.imageSrc = "./images/christ_redeemer.png";
mark.text = "Christ the Redeemer";

//adds the Maker to the decorations collection of the view
view.decorations.add(mark);

view.center = mark.location;

 See Also