Home  >  Article  >  Web Front-end  >  Google Map API update to implement user-defined labeling coordinates_javascript skills

Google Map API update to implement user-defined labeling coordinates_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:49:071242browse

Demo address: http://www.yaohaixiao.com/effects/google-map.html

Copy code The code is as follows:

if(typeof GoogleMap === 'undefined'){
var GoogleMap = {};
}
(function(){
if (!document.getElementById(" fgmap")) {
return false;
}
else {
// Whether the Google Map control can be created
var isCompatible = new GBrowserIsCompatible();
if (isCompatible) {
var mapContainer = document.getElementById("fgmap");
// Create GoogleMAP map instance
var map = new GMap2(mapContainer);
// Default scale level of the map
var perviewLevel = 14;
// Large map zoom level control
var largeMapControl = new GLargeMapControl();
// Map thumbnail control
var overviewMapControl = new GOverviewMapControl();
/ / Scale control
var scaleControl = new GScaleControl();
// Map type selection control
var mapTypeControl = new GMapTypeControl();
// Address-coordinate converter
var geocoder = new GClientGeocoder();
// The last query address
var lastAddress = '';
// The last query coordinates
var lastPoint = null;
// The last one Created marker control
var lastMarker = null;
//The last coordinate point marked by the user
var cusLastPoint = null;

GoogleMap.mapMsg = [];

// Create a map
GoogleMap.Map = function(lat, lng){
var point = new GLatLng(lat, lng);
map.addMapType(G_PHYSICAL_MAP);
map.setCenter( point, perviewLevel);

map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
map.enableContinuousZoom();

map.addControl(largeMapControl)
map.addControl(overviewMapControl);
map.addControl(mapTypeControl);
map.addControl(scaleControl);
};

// Create Marker
GoogleMap.createMarker = function (latlng, markerOptions){
var marker = markerOptions ? new GMarker(latlng, markerOptions) : new GMarker(latlng);
lastMarker = marker;
return marker;
};

//Custom mark options
/* ===================================== ================================================== ================================================== ================================================
Parameter description:
Constant: G_DEFAULT_ICON The default icon used by the tag.
image String The foreground image URL of the icon.
shadow String Shadow image URL of the icon.
iconSize GSize The pixel size of the icon foreground image.
shadowSize GSize The pixel size of the shadow image.
iconAnchor GPoint The pixel coordinates of this icon's anchor point on the map relative to the upper left corner of the icon image.
infoWindowAnchor GPoint The pixel coordinate of the anchor point of the information window on this icon relative to the upper left corner of the icon image.
printImage String URL of the foreground icon image used to print the map. It must be the same size as the main icon image provided by image .
mozPrintImage String The URL of the foreground icon image used when printing maps with Firefox/Mozilla. It must be the same size as the main icon image provided by image .
printShadow String URL of the shadow image used when printing the map. Since most browsers cannot print PNG images, the image format should be GIF.
transparent String The URL of the transparent foreground icon image used when capturing click events in Internet Explorer. This image should be the main icon image in 24-bit PNG format with 1% opacity, but the same size and shape as the main icon.
imageMap Array of Number An integer array representing the x/y coordinates of the image map, used to specify the clickable portion of the icon image in a browser (non-Internet Explorer).
maxHeight Integer Specifies the distance (in pixels) that the marker will visually "rise" vertically when dragging it. (Since 2.79)
dragCrossImage String Specifies the URL of the cross image when dragging the icon. (Since 2.79)
dragCrossSize GSize Specifies the pixel size of the cross image when dragging the icon. (Since 2.79)
dragCrossAnchor GPoint Specifies the pixel coordinate offset (relative to the iconAnchor) of the cross image when dragging the icon.(自 2.79 开始)
========================================================================================================================================================================================= */
GoogleMap.setCustomIcon = function(IconOptions){
var myIcon = new GIcon(G_DEFAULT_ICON), i;
for (i in IconOptions) {
switch (i) {
case 'iconSize':
case 'shadowSize':
case 'dragCrossSize':
myIcon[i] = new GSize(IconOptions[i][0], IconOptions[i][1]);
break;
case 'iconAnchor':
case 'infoWindowAnchor':
case 'infoShadowAnchor':
case 'dragCrossAnchor':
myIcon.iconAnchor = new GPoint(IconOptions[i][0], IconOptions[i][1]);
break;
default:
myIcon[i] = IconOptions[i];
break;
}

}
return myIcon;
};

// 用户自定义标注
GoogleMap.customMarkPoint = function(){
var marker = null;
var markPoint = cusLastPoint ? new GLatLng(cusLastPoint[0],cusLastPoint[1]) : new GLatLng(lastPoint[0],lastPoint[1]);
var markOptions = {
icon: GoogleMap.setCustomIcon({
image: 'http://www.yaohaixiao.com/effects/img/icon13.png'
}),
draggable: true
};

marker = GoogleMap.createMarker(markPoint, markOptions);
GEvent.addListener(marker, "dragstart", function(){
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function(){
var custPoint = marker.getPoint();
var markTip = '
';
markTip = '

用户地图标注

';
markTip = '

当前经纬度:(' custPoint.lat() ',' custPoint.lng() ')
';
markTip = '是否将新位置设置为此商户的默认位置?

';
markTip = '
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn