var map, mapObject, marker, streetview, streetviewObject, sPano, sHeading, sPitch, sZoom; //sLongitude,
jQuery(document).ready(function($) {
// map
var latTextfield = $('#ait-_ait-dir-item-gpsLatitude');
var lonTextfield = $('#ait-_ait-dir-item-gpsLongitude');
// streetview
var streetviewCheckbox = $('#ait-_ait-dir-item-showStreetview-enable');
sPano = $('#ait-_ait-dir-item-streetViewLatitude');
//sLongitude = $('#ait-_ait-dir-item-streetViewLongitude');
sHeading = $('#ait-_ait-dir-item-streetViewHeading');
sPitch = $('#ait-_ait-dir-item-streetViewPitch');
sZoom = $('#ait-_ait-dir-item-streetViewZoom');
// hide these options
$('#ait-_ait-dir-item-gpsLatitude-option').hide();
$('#ait-_ait-dir-item-gpsLongitude-option').hide();
$('#ait-_ait-dir-item-streetViewLatitude-option').hide();
$('#ait-_ait-dir-item-streetViewLongitude-option').hide();
$('#ait-_ait-dir-item-streetViewHeading-option').hide();
$('#ait-_ait-dir-item-streetViewPitch-option').hide();
$('#ait-_ait-dir-item-streetViewZoom-option').hide();
var initLat = (latTextfield.val()&&latTextfield.val()!=0) ? latTextfield.val() : 31.383068;
var initLon = (lonTextfield.val()&&lonTextfield.val()!=0) ? lonTextfield.val() : 120.9707;
var latRow = $('#ait-_ait-dir-item-gpsLatitude-option');
var streetviewCheckboxRow = $('#ait-_ait-dir-item-showStreetview-option');
var mapRow = $('<tr valign="top" id="ait-map-option"><td scope="row" class="ait-custom-fields-label"><label for="ait-map-select">Set position</label></td><td><div id="ait-map-select"></div></td></tr>');
var streetviewRow = $('<tr valign="top" id="ait-streetview-option"><td scope="row" class="ait-custom-fields-label"><label for="ait-streetview-select">Set streetview position (If window is gray then sreetview is not available for this position and you must use stick figure in map above to define correct streetview position)</label></td><td><div id="ait-streetview-select"></div><div id="ait-streetview-map"></div></td></tr>');
latRow.before(mapRow);
streetviewCheckboxRow.after(streetviewRow);
map = mapRow.find('#ait-map-select');
map.width('95%').height(500);
streetview = streetviewRow.find('#ait-streetview-select');
streetview.width('95%').height(350);
streetmap = streetviewRow.find('#ait-streetview-map');
streetmap.width('95%').height(150);
//var sFirsttime = (sLatitude.val()) ? false : true;
//var initsLat = (sLatitude.val()&&sLatitude.val()!=0) ? parseFloat(sLatitude.val()) : initLat;
//var initsLon = (sLongitude.val()&&sLongitude.val()!=0) ? parseFloat(sLongitude.val()) : initLon;
var initPano = (sPano.val()&&sPano.val().length>20) ? sPano.val() : '10121013120927123538500';
var initHeading = (sHeading.val()) ? parseFloat(sHeading.val()) : 0;
var initPitch = (sPitch.val()) ? parseFloat(sPitch.val()) : 0;
var initZoom = (sZoom.val()&&sZoom.val()!=0) ? parseInt(sZoom.val()) : 1;
latTextfield.val(initLat);
lonTextfield.val(initLon);
sPano.val(initPano);
sHeading.val(initHeading);
sPitch.val(initPitch);
sZoom.val(initZoom);
//创建街景
var panorama = new soso.maps.Panorama('ait-streetview-select', { //街景容器
pano:initPano, //场景ID
zoom:initZoom,
pov:{
heading:initHeading,
pitch:initPitch,
},
});
//创建街景地图实例
var ovc=document.getElementById('ait-streetview-map');
var overview = new soso.maps.PanoOverview(ovc,{
panorama:panorama
});
var smap=overview.getMap();
var pano_service = new soso.maps.PanoramaService();
//点击
soso.maps.event.addListener(smap, 'click', function (evt){
var point = evt.latLng;
var radius;
pano_service.getPano(point, radius, function (result){
panorama.setPano(result.svid);
});
//sPano.val(panorama.getPano());
});
//街景变化
soso.maps.event.addListener(panorama, 'pov_changed', function (evt){
var vPov=panorama.getPov();
sHeading.val(vPov.heading); //街景 heading
sPitch.val(vPov.pitch); //街景 pitch
})
soso.maps.event.addListener(panorama, 'zoom_changed', function (evt){
sZoom.val(panorama.getZoom());
})
soso.maps.event.addListener(panorama, 'pano_changed', function (evt){
sPano.val(panorama.getPano());
})
/*
var streetviewOptions = {
container: streetview,
opts:{
position: new google.maps.LatLng(initsLat,initsLon),
pov: {
heading: initHeading,
pitch: initPitch,
zoom: initZoom
}
}
}
*/
map.gmap3({
map: {
events: {
click:function(mapLocal, event){
map.gmap3({
get: {
name: "marker",
callback: function(marker){
marker.setPosition(event.latLng);
var pos = marker.getPosition();
latTextfield.val(pos.lat());
lonTextfield.val(pos.lng());
var point = new soso.maps.LatLng(pos.lat(),pos.lng());
var radius;
pano_service.getPano(point, radius, function (result){
panorama.setPano(result.svid);
});
//sPano.val(panorama.getPano());
}
}
});
}
},
options: {
center: [initLat,initLon],
zoom: 15
}
},
marker: {
values:[
{latLng:[initLat, initLon]}
],
options: {
draggable: true
},
events: {
dragend: function(marker){
var pos = marker.getPosition();
latTextfield.val(pos.lat());
lonTextfield.val(pos.lng());
var point = new soso.maps.LatLng(pos.lat(),pos.lng());
var radius;
pano_service.getPano(point, radius, function (result){
panorama.setPano(result.svid);
});
//sPano.val(panorama.getPano());
}
}
},
/*
streetviewpanorama:{
options: streetviewOptions,
events: {
position_changed: function (obj) {
sLatitude.val(obj.position.lat());
sLongitude.val(obj.position.lng());
},
pov_changed: function (obj) {
sHeading.val(obj.pov.heading);
sPitch.val(obj.pov.pitch);
sZoom.val(obj.pov.zoom);
}
}
}
*/
});
mapObject = map.gmap3({
get: {
name: "map"
}
});
marker = map.gmap3({
get: {
name: "marker"
}
});
// find address functionality
var findAddress = $('<a id="find-address-button" href="#" class="button">Find address on map</a>');
findAddress.insertAfter('#ait-_ait-dir-item-address');
findAddress.after('<span id="find-address-info-status" style="margin-left: 20px;"></span>');
findAddress.click(function (event) {
event.preventDefault();
var addr = $('#ait-_ait-dir-item-address').val();
if ( !addr || !addr.length ) return;
map.gmap3({
getlatlng:{
address: '江苏省昆山市,'+addr,
callback: function(results){
if ( !results ) {
$('#find-address-info-status').text('No results found!').show().fadeOut(2000);
} else {
$('#find-address-info-status').text('Address found!').show().fadeOut(2000);
marker.setPosition(results[0].geometry.location);
map.gmap3({
map: {
options: {
zoom: 15,
center: results[0].geometry.location
}
}
})
latTextfield.val(results[0].geometry.location.lat());
lonTextfield.val(results[0].geometry.location.lng());
var point = new soso.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
var radius;
pano_service.getPano(point, radius, function (result){
panorama.setPano(result.svid);
});
sPano.val(panorama.getPano());
}
}
}
});
});
});
map-singer-javascript.php加:
{ifset $options['showStreetview']}
streetviewpanorama = new soso.maps.Panorama(document.getElementById('directory-main-bar'), {
pano: {$options['streetViewLatitude']},
zoom: parseInt({$options['streetViewZoom']}),
scrollwheel:false,
visible:true,
pov:{
heading:parseFloat({$options['streetViewHeading']}),
pitch:parseFloat({$options['streetViewPitch']}),
},
});
{/ifset}
原{ifset $options['showStreetview']}部分删除