# map

Start from base library version 1.0.0. Please remaining backward compatible.

Map (v2.7.0 Rise support Same-layer rendering, related api wx.createMapContext

# Mini Program solution

In addition to this chapter introduces the basic properties of the Mini Program map, Tencent location services launched"WeChat Mini Program Solution", from the retrieval API, basic map components, personalization, plug-ins, industry solutions and other levels, for different scenarios demand Mini Program developers to provide complete map capabilities.

# Personalized map

Personalized map style is an advanced capability of Tencent Location Services, developers can use their own products according to the use of the scene, UI style, Select or create a style matching map style. Within the Mini Program map component, use the same Subkey, available through Layer-style (style of location service website settings style Property configuration and support for dynamic switching styles. The unit of length of the component attribute defaults to px,2.4.0 to support incoming units(rpx/px)。 For details see:Personalized Map Guide

# Mini Program plugin

Tencent Location Services, based on WeChat's ability to plug in mini-programs, focuses on (around) the map function, creating a series of mini-program plug-ins, which can help developers build mini-programs easily and quickly, is the best partner for you to achieve map function. At present, the plug-in provides route planning, subway map, map selection services, details see:Mini Program Map Plug-in Guide

# Map retrieval

Tencent Location ServicesWeChat open community service platform launched a series of map retrieval services, It contains 4 POI data classes (Inverse Address Resolution, Location Search, Keyword Input Prompt), 2 route planning classes (driving route planning, walking route planning), 1 coordinate tool class (coordinate transformation), Covers most of the map application scenarios. Or log on to the location service website.Web service usage guide for details. WeChat mini program developers can use overseas maps for display, if you need overseas search ability, you canOverseas location services to apply.

# Mini Program sample center

Contains Map components, APIs, plug-ins and other functions to use methods, a comprehensive understanding of the Mini Program under all maps capabilities. Sample content source code open, reduce the developer access costs.

# Recent additions

  1. Support point aggregation for marker too many scenarios.
  2. Support rainbow earthworm line, commonly used in route planning scenarios.
  3. Overlay supports adjusting overlay relationships with other map elements.
  4. Support marker (car) translation animation, suitable for track playback scene.

# Map base attribute

attribute type Default value Required Introductions Minimum version
longitude number yes Central longitude 1.0.0
latitude number yes Central latitude 1.0.0
scale number 16 no Zoom level, values range from 3-20 1.0.0
min-scale number 3 no Minimum Zoom Level 2.13.0
max-scale number 20 no Maximum zoom level 2.13.0
markers Array.&ltmarker&gt no Marker point 1.0.0
covers Array.&ltcover&gt no To remove, use the markers 1.0.0
polyline Array.&ltpolyline&gt no route 1.0.0
circles Array.&ltcircle&gt no circular 1.0.0
controls Array.&ltcontrol&gt no Control is about to be deprecated and recommended cover-view Substitute) 1.0.0
include-points Array.&ltPoint & Gt no Scale the field of view to include all the given coordinate points 1.0.0
show-location boolean false no Displays the current anchor point with direction 1.0.0
polygons Array.&ltpolygon&gt no polygon 2.3.0
subkey string no Key to personalize map usage 2.3.0
layer-style number 1 no Personalized Map Configuration Style, does not support dynamic modification
rotate number 0 no Angle of rotation 0 360, Map due north and equipment and Angle of axis angle 2.5.0
skew number 0 no Angle, range 0 40 , about with Inclination angle of shaft 2.5.0
enable-3D boolean false no Display 3D block(Tools not supported) 2.3.0
show-compass boolean false no Show compass 2.3.0
show-scale boolean false no Display scale, tool does not support 2.8.0
enable-overlooking boolean false no Open up Overlook 2.3.0
enable-zoom boolean true no Whether scaling is supported 2.3.0
enable-scroll boolean true no Drag supported 2.3.0
enable-rotate boolean false no Support for rotation 2.3.0
enable-satellite boolean false no Whether to turn on satellite imagery 2.7.0
enable-traffic boolean false no Whether to turn on real-time traffic 2.7.0
enable-poi boolean true no Whether to show THEN point 2.14.0
enable-building boolean no Whether to display buildings 2.14.0
setting object no Configuration item 2.8.2
bindtap eventhandle no Triggered when the map is clicked, Return latitude and longitude information from 2.9.0 1.0.0
bindmarkertap eventhandle no Triggered when the marker point is clicked,and.detail = {Markers} 1.0.0
bindlabeltap eventhandle no Triggered when the label is clicked,and.detail = {Markers} 2.9.0
bindcontroltap eventhandle no Triggered when the control is clicked,and.detail = {controlId} 1.0.0
bindcallouttap eventhandle no When you click on the bubble corresponding to the marker point.and.detail = {Markers} 1.2.0
bindupdated eventhandle no Triggered when the map render update is complete 1.6.0
bindregionchange eventhandle no Triggered when visual field changes, 2.3.0
bindpoitap eventhandle no Triggered when the map poi point is clicked,and.detail = {name, longitude, latitude} 2.3.0
bindanchorpointtap eventhandle no When the positioning mark is clicked,and.detail = {longitude, latitude} 2.13.0

# regionchange Return value

When the field of vision changes, the region changes It triggers twice and returns. type The values are begin and end。

2.8.0 rise begin Phase return CausedBy with a valid value of Gestural (gesture triggering) & Update (interface trigger)

2.3.0 rise end Phase return CausedBy with a valid value of Drag (drag), scale (scale), update (call update interface).

and = {causedBy, type, detail: {rotate, skew, scale, centerLocation, region}}

# setting

provide setting Object to uniformly set the map configuration. At the same time for animation properties such as rotate and skewThrough setData Cannot take effect simultaneously when setting separately. You need to go through the settting Uniform revision.

// Default value
const setting = {
  skew: 0,
  rotate: 0,
  showLocation: false,
  showScale: false,
  subKey: '',
  layerStyle: 1,
  enableZoom: true,
  enableScroll: true,
  enableRotate: false,
  showCompass: false,
  enable3D: false,
  enableOverlooking: false,
  enableSatellite: false,
  enableTraffic: false,
}

this.setData({
  // Only the properties set will take effect, the rest will not be affected
  setting: {
    enable3D: true,
    enableTraffic: true
  }
})

# marker

Marker points are used to display the location of markers on a map

attribute Introductions type Required Remarks Minimum version
id Marker point id number no marker Click the event callback to return this id。Recommended for each marker Set up number type Id, guaranteed update marker Have better performance.
clusterId Aggregate cluster id Number no To customize the point cluster effect
joinCluster Participate in point aggregation Boolean no Default does not participate in point aggregation
latitude latitude number yes Floating point number, range -90 90
longitude longitude number yes Floating point number, range -180 180
title Calling-out string no Shown when clicked, and ignored when callout exists
zIndex Display level number no 2.3.0
iconPath Display icons string yes Project directory under the picture path, support network path, local path, code package path (2.3.0
rotate Rotation angle number no The angle of a clockwise rotation 0 360, default to 0
alpha Annotated transparency number no default 1, no transparency, scope 0 1
width Label icon width number/string no Default is the actual width of the picture
height Mark icon height number/string no Default is the actual height of the picture
callout Bubble window above the marker point Object no The supported properties are shown in the following table and are recognized as newlines. 1.2.0
customCallout Custom bubble window Object no The supported properties are shown in the following table
label Add labels next to marker points Object no The supported properties are shown in the following table and are recognized as newlines. 1.2.0
anchor Latitude and longitude at anchor point of callout icon, default bottom midpoint Object no {x, y},x Represent horizontal(0-1),y Vertical(0-1)。{x: .5, and: 1} Represents the midpoint of the bottom 1.2.0
aria-label Accessibility, additional description of (attribute) elements string no 2.5.0

# marker Bubbles on top callout

attribute Introductions type Minimum version
content text string 1.2.0
color Text color string 1.2.0
fontSize Text size number 1.2.0
borderRadius Border fillet number 1.2.0
borderWidth Border width number 2.3.0
borderColor Border color string 2.3.0
bgColor Background color string 1.2.0
padding Text margin number 1.2.0
display 'BYCLICK ': Click Show 'Always': Chang Hin string 1.2.0
textAlign Text alignment. Valid value: left, right, center string 1.6.0
anchorX Lateral offset, positive to the right number 2.11.0
anchorY Vertical offset, positive downward number 2.11.0

# marker Custom bubbles on customCallout

customCallout When present, will ignore callout and title Property. Custom Bubble Adoption cover-view Customization, higher flexibility.

attribute Introductions type Minimum version
display 'BYCLICK ': Click Show 'Always': Chang Hin string 2.12.0
anchorX Lateral offset, positive to the right number 2.12.0
anchorY Vertical offset, positive downward number 2.12.0

The manner of use is as follows,map Component to add the name named callout of slot Node and its internal cover-view adopt marker-id Property and marker Binding. when marker When created, the cover-view The content displayed will be treated as callout Is displayed above the marker point.

<map>
  <cover-view slot="callout">
    <cover-view marker-id="1"></cover-view>
    <cover-view marker-id="2"></cover-view>
  </cover-view>
</map>

Example DEMO : https://developers.WeChat.qq.with/s/cZWIojm47pjN

# marker Bubbles on top label

attribute Introductions type Minimum version
content text string 1.2.0
color Text color string 1.2.0
fontSize Text size number 1.2.0
x Coordinates of the label (discarded) number 1.2.0
and Coordinates of the label (discarded) number 1.2.0
anchorX The coordinates of the label, the origin is marker Corresponding latitude and longitude number 2.1.0
anchorY The coordinates of the label, the origin is marker Corresponding latitude and longitude number 2.1.0
borderWidth Border width number 1.6.0
borderColor Border color string 1.6.0
borderRadius Border fillet number 1.6.0
bgColor Background color string 1.6.0
padding Text margin number 1.6.0
textAlign Text alignment. Valid value: left, right, center string 1.6.0

# Dot polymerization

When the marker points on the map need to be displayed marker Too much can result in an interface marker The presence of a gland, incomplete display, and lead to poor overall performance. For this kind of problem, the point aggregation capability is introduced.

The process is as follows:

  1. MapContext.initMarkerCluster Initialize configuration of aggregation points (optional)
  2. MapContext.addMarkers Specifies that the aggregate marker
  3. MapContext.on('markerClusterCreate', callback) When triggered, by MapContext.addMarkers Update the style of the cluster (optional)
  4. MapContext.removeMarkers Removes the item participating in the aggregation marker

# sample code

Preview with Developer Tool

Note that:

  1. On the map. marker Divided into ordinary marker And those involved in aggregation Marker, specify properties when participating in the aggregation joinCluster for true
  2. When you customize the cluster style, you also use the MapContext.addMarkers To draw, at which point you need to carry clusterId。

# polyline

Specifies a series of coordinates, wired from the first item in an array to the last item. When drawing a rainbow line, specify the colors of the different segments, such as points Contain 5 Point, then colorList Should be introduced 4 Color valueif colorList Length less than points.length - 1, then the remaining segment color is the same as the last item.

attribute Introductions type Required Remarks Minimum version
points Longitude and latitude array array yes [{latitude: 0, longitude: 0}]
color The color of the line string no Hexadecimal
colorList Rainbow line array no Ignore when present color value 2.13.0
width Width of line number no
dottedLine Whether dashed lines boolean no default false
arrowLine Lines with arrows boolean no default False, this attribute is not supported by developer tools 1.2.0
arrowIconPath Replace Arrow Icon string no in arrowLine for true Effective 1.6.0
borderColor Border color of line string no 1.2.0
borderWidth Thickness of line number no 1.2.0
level Gland relation string no Default is abovelabels 2.14.0

level Field represents a gland relationship with other map elements, with optional values as follows

value Introductions Minimum version
abovelabels Display at all THEN above 2.14.0
abovebuildings Shown above the building block THEN under 2.14.0
aboveroads Above the road, under the block 2.14.0

# polygon

Specifies a series of coordinates, based on the points Coordinate data generating closed polygon

attribute Introductions type Required Remarks Minimum version
points Longitude and latitude array array yes [{latitude: 0, longitude: 0}] 2.3.0
strokeWidth Width of stroke number no 2.3.0
strokeColor Stroke color string no Hexadecimal 2.3.0
FillColor Fill color string no Hexadecimal
zIndex Set polygon z-axis value number no 2.3.0
level Gland relation string no Default is abovelabels 2.14.0

# circle

Show circles on a map

attribute Introductions type Required Remarks
latitude latitude number yes Floating point number, range -90 90
longitude longitude number yes Floating point number, range -180 180
color Stroke color string no Hexadecimal
FillColor Fill color string no Hexadecimal
radius Radius number yes
strokeWidth Width of stroke number no
level Gland relation string no Default is abovelabels

# control

Displays controls on a map without moving with the map.About to be discarded, please use cover-view

attribute Introductions type Required Remarks
id Control id number no Clicking on an event callback in a control returns this id
position Control location on the map object yes Control relative map position
iconPath Display icons string yes Project directory picture path, support local path, code package path
clickable Is it clickable? boolean no Default not clickable

# position

attribute Introductions type Required Remarks
left How far from the left edge of the map? number no Defaults to 0
top How far to the upper boundary of the map? number no Defaults to 0
width Control Width number no Default is picture width
height Control Height number no Default image height

# bindregionchange Return value

attribute Introductions type Remarks
type Triggered at the beginning and end of visual field changes string The visual field changes start with begin and end with end
causedBy Causes of visual field changes string Drag the map to cause(Drag), scale(The call interface causes(update)

# scale

scale 3 4 5 6 7 8 9 10 11
proportion 1000km 500km 200km 100km 50km 50km 20km 10km 5km
scale 12 13 14 15 16 17 18 19 20
proportion 2km 1km 500m 200m 100m 50m 50m 20m 10m

# sample code

Preview with Developer Tool

# Bug & Tip

  1. tipCustom maps do not support debugging in tools. Please use the WeChat client to test.
  2. tipColor: color value in maps/borderColor/BgColor, etc., uses a 6-bit (8-bit) hexadecimal representation, with the last two bits representing alpha values when 8-bit, such as:#000000AA
  3. tip: The latitude and longitude of the map component must be filled, If you do not fill in the latitude and longitude then the default value is Beijing's longitude and latitude.
  4. tip: map The latitude and longitude component uses a martian coordinate system, calling the wx.getLocation Interface needs to be specified type for gcj02
  5. tip:: from 2.8.0 rise map Support same layer rendering, please refer to[Native component usage limits]((native-component#Native component usage restrictions)
  6. tipPlease note that[Native component usage limits](./native-component.md#Restrictions on the use of native components).