git-svn-id: https://msi/svn/firstRepo/WebClient/branches/NewRelease@46 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
+53
-25
@@ -9,8 +9,13 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
template: _.template(mapsViewTemplate),
|
||||
infoWindowtemplate: _.template(infoWindowTemplate),
|
||||
defaultLatLng: new google.maps.LatLng(45.4654219, 9.1859243), // Default to Milan
|
||||
iconPM: {
|
||||
url: "http://app.gruppolapastamadre.it/icon.png",
|
||||
scaledSize: new google.maps.Size(24, 24)
|
||||
},
|
||||
initialize: function () {
|
||||
this.id = "MapsView";
|
||||
this.markers = [];
|
||||
MapsView.__super__.initialize.call(this);
|
||||
},
|
||||
_centerControl: function(controlDiv, map) {
|
||||
@@ -56,7 +61,6 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
_drawMap: function(LatLng){
|
||||
var self = this;
|
||||
@@ -75,7 +79,8 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
self.map = new google.maps.Map($("#map-canvas")[0], myOptions);
|
||||
|
||||
// Create the search box and link it to the UI element.
|
||||
var input = $("#pac-input")[0];
|
||||
var input = $('<input id="pac-input" data-role="none" class="controls" type="text" placeholder="Ricerca località..." style="display:none;">')[0];
|
||||
self.$el.find('div[data-role="content"]')[0].appendChild(input);
|
||||
var searchBox = new google.maps.places.SearchBox(input);
|
||||
self.map.controls[google.maps.ControlPosition.TOP_CENTER].push(input);
|
||||
var centerControlDiv = document.createElement('div');
|
||||
@@ -129,11 +134,6 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
self.map.fitBounds(bounds);
|
||||
});
|
||||
|
||||
var iconPM = {
|
||||
url: "http://app.gruppolapastamadre.it/icon.png",
|
||||
scaledSize: new google.maps.Size(24, 24)
|
||||
};
|
||||
|
||||
self.map.addListener('bounds_changed', function() {
|
||||
var bound = self.map.getBounds();
|
||||
searchBox.setBounds(bound);
|
||||
@@ -144,26 +144,18 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
//dataType: "json",
|
||||
//async: false,
|
||||
type: 'GET',
|
||||
success: function (resp) {
|
||||
success: function (resp) {
|
||||
resp.forEach(function(ele, index){
|
||||
if(!self.markers["|" + ele.Latitudine+ "|" + ele.Longitudine+ "|"])
|
||||
var key = "|" + ele.Latitudine+ "|" + ele.Longitudine+ "|";
|
||||
if(!self.markers[key])
|
||||
{
|
||||
var marker = new google.maps.Marker({
|
||||
position: new google.maps.LatLng(ele.Latitudine, ele.Longitudine),
|
||||
icon: iconPM,
|
||||
//label: ele.Name,
|
||||
title: ele.Name,
|
||||
map: self.map
|
||||
});
|
||||
self.markers["|" + ele.Latitudine+ "|" + ele.Longitudine+ "|"] = marker;
|
||||
|
||||
var infowindow = new google.maps.InfoWindow({
|
||||
content: self.infoWindowtemplate({item: ele})
|
||||
});
|
||||
|
||||
marker.addListener('click', function() {
|
||||
infowindow.open(self.map, marker);
|
||||
});
|
||||
self._makeMarker(ele, key);
|
||||
}
|
||||
else if(!self.markers[key][ele.ID])
|
||||
{
|
||||
ele.Latitudine = parseFloat(ele.Latitudine) + (Math.random() / 500);
|
||||
ele.Longitudine = parseFloat(ele.Longitudine) + (Math.random() / 500);
|
||||
self._makeMarker(ele, key);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -171,7 +163,33 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
});
|
||||
$("#pac-input").show();
|
||||
},
|
||||
_makeMarker: function(ele,key){
|
||||
var self = this;
|
||||
var marker = new google.maps.Marker({
|
||||
position: new google.maps.LatLng(ele.Latitudine, ele.Longitudine),
|
||||
icon: self.iconPM,
|
||||
//label: ele.Name,
|
||||
title: ele.Name,
|
||||
map: self.map
|
||||
});
|
||||
|
||||
if(!self.markers[key])
|
||||
self.markers[key] = [];
|
||||
|
||||
self.markers[key][ele.ID] = marker;
|
||||
|
||||
var infowindow = new google.maps.InfoWindow({
|
||||
content: self.infoWindowtemplate({item: ele})
|
||||
});
|
||||
|
||||
marker.addListener('click', function() {
|
||||
infowindow.open(self.map, marker);
|
||||
});
|
||||
},
|
||||
onShowed: function(){
|
||||
if(this.map)
|
||||
return;
|
||||
|
||||
var self = this;
|
||||
|
||||
$( window ).resize( function(){
|
||||
@@ -193,6 +211,16 @@ define(['jquery', 'underscore', 'backbone', 'text!modules/maps/mapsViewTemplate.
|
||||
self._drawMap(self.defaultLatLng); // No geolocation support, show default map
|
||||
}
|
||||
},
|
||||
onClosing: function(){
|
||||
var self = this;
|
||||
Object.keys(self.markers).forEach(function(key, i){
|
||||
Object.keys(self.markers[key]).forEach(function(ID, k){
|
||||
self.markers[key][ID].setMap(null);
|
||||
});
|
||||
});
|
||||
|
||||
self.markers = [];
|
||||
},
|
||||
//render the content into div of view
|
||||
render: function () {
|
||||
if (this.created === true)
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
<div id="searchPanel">
|
||||
<h3>Mappa Spacciatori</h3>
|
||||
</div>
|
||||
<input id="pac-input" data-role="none" class="controls" type="text" placeholder="Ricerca località..." style="display:none;">
|
||||
<div id="map-canvas">
|
||||
<!-- map loads here... -->
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user