/public/javascripts/app/home.js
JavaScript | 6885 lines | 5412 code | 989 blank | 484 comment | 412 complexity | afa3634176114ef198ff0b14bf34698e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- GoogleMapApi = Service.GoogleMapApi = function() {
- this.map = null;
- this.bounds = new google.maps.LatLngBounds();
- this.infoWindow = new google.maps.InfoWindow();
- this.markers = [];
- this.markerCluster = null;
- };
- GoogleMapApi.DEFAULT_LAT = 12.565679;
- GoogleMapApi.DEFAULT_LNG = 104.990963
- GoogleMapApi.ZOOM_LEVEL = 7;
- GoogleMapApi.MAX_ZOOM_LEVEL = 14;
- GoogleMapApi.prototype.initializeMap = function(canvas) {
- var latlng = new google.maps.LatLng(GoogleMapApi.DEFAULT_LAT, GoogleMapApi.DEFAULT_LNG);
- var myOptions = {
- zoom: GoogleMapApi.ZOOM_LEVEL,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- this.map = new google.maps.Map(canvas, myOptions);
- var mcOptions = {gridSize: 60, maxZoom:14, zoomOnClick:true };
- this.markerCluster = new MarkerClusterer(this.map,this.markers,mcOptions); };
- GoogleMapApi.prototype.createMarker = function(optionData){
- var latLng = this.newLatLng(optionData.lat, optionData.lng);
- var option = optionData;
- option.position = latLng;
- this._calculateBounds(latLng);
- marker = new google.maps.Marker(option);
- this.markerCluster.addMarker(marker);
- return marker;
- };
- GoogleMapApi.prototype.refresh = function(){
- this.markerclusterer.redraw();
- };
- GoogleMapApi.prototype.createDraggableMarker = function(title, lat, lng, icon){
- var latLng = this.newLatLng(lat, lng);
- var option = {
- position: latLng,
- title: title,
- map: this.map,
- icon:icon,
- draggable:true
- };
- marker = new google.maps.Marker(option);
- return marker;
- };
- GoogleMapApi.prototype._calculateBounds = function(latLng){
- this.bounds.extend(latLng);
- };
- GoogleMapApi.prototype.fitBounds = function(){
- this.map.fitBounds(this.bounds);
- var zoomLevel = this.map.getZoom();
- if(zoomLevel > GoogleMapApi.MAX_ZOOM_LEVEL){
- this.map.setZoom(GoogleMapApi.MAX_ZOOM_LEVEL);
- this.bounds = this.map.getBounds();
- }
- };
- GoogleMapApi.prototype.newLatLng = function(lat, lng){
- return new google.maps.LatLng(lat, lng);
- };
- GoogleMapApi.prototype.setMarkerPosition = function(marker, latLng) {
- marker.setPosition(latLng);
- };
- GoogleMapApi.prototype.addMarkerClickListener = function(marker, data, handler){
- google.maps.event.addListener(marker, 'click', function() {
- handler(data);
- });
- };
- GoogleMapApi.prototype.addMapClickListener = function(e){
- google.maps.event.addListener(this.map, 'click', function(point) {
- e.click(point.latLng.lat(), point.latLng.lng());
- });
- };
- GoogleMapApi.prototype.moveMarkerTo = function(marker, lat, lng){
- marker.setMap(this.map);
- marker.setPosition(this.newLatLng(lat, lng));
- return marker;
- };
- GoogleMapApi.prototype.removeMarker = function(marker){
- marker.setMap(null);
- };
- GoogleMapApi.prototype.setIcon = function(marker, icon){
- if(icon)
- marker.setIcon(icon);
- };
- GoogleMapApi.prototype.setShadow = function(marker, imageUrl){
- var shadow = new google.maps.MarkerImage(imageUrl, null, null, new google.maps.Point(16, 32));
- marker.setShadow(shadow);
- };
- GoogleMapApi.prototype.addListener = function(obj, eventName, handler){
- google.maps.event.addListener(obj, eventName, handler);
- };
- GoogleMapApi.prototype.addMarkerClickListener = function(marker, data, handler){
- google.maps.event.addListener(marker, 'click', function(){
- handler(data);
- });
- };
- GoogleMapApi.prototype.setMarkerDraggability = function(marker,draggability){
- marker.setDraggable(draggability);
- };
- GoogleMapApi.prototype.getAllMarkers = function(){
- return this.markers;
- };
- GoogleMapApi.prototype.clearAllMarkers = function(){
- this.markerCluster.clearMarkers();
- };
- GoogleMapApi.prototype.attachDataToMarker = function(marker,key,value){
- if(!marker.data)
- marker.data={};
- marker.data[key]=value;
- };
- GoogleMapApi.prototype.processMarkerVisibility = function(){
- this.markerCluster.processMarkersVisibility(true);
- };
- GoogleMapApi.prototype.updateMarkerClusterer = function(resource,redraw){
- var markers = this.markerCluster.getMarkers();
- var tempMarker = null;
- for(var i=0; i< markers.length; i++){
- if(markers[i].id == resource.id ){
- var latLng = this.newLatLng(resource.lat, resource.lng);
- markers[i].setPosition(latLng);
- if(redraw)
- this.markerCluster.processMarkersVisibility(true);
- return true;
- }
- }
- return false;
- };
- GoogleMapApi.prototype.getCenter = function(){
- return this.map.getCenter();
- };
- GoogleMapApi.prototype.setCenter = function(latLng){
- return this.map.panTo(latLng);
- };
- GoogleMapApi.prototype.setZoom = function(level){
- return this.map.setZoom(level);
- };
- GoogleMapApi.prototype.getMap = function(){
- return this.map;
- };
- /**
- * @name MarkerClusterer for Google Maps v3
- * @version version 1.0
- * @author Luke Mahe
- * @fileoverview
- * The library creates and manages per-zoom-level clusters for large amounts of
- * markers.
- * <br/>
- * This is a v3 implementation of the
- * <a href="http://gmaps-utility-library-dev.googlecode.com/svn/tags/markerclusterer/"
- * >v2 MarkerClusterer</a>.
- */
- /**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * A Marker Clusterer that clusters markers.
- *
- * @param {google.maps.Map} map The Google map to attach to.
- * @param {Array.<google.maps.Marker>} opt_markers Optional markers to add to
- * the cluster.
- * @param {Object} opt_options support the following options:
- * 'gridSize': (number) The grid size of a cluster in pixels.
- * 'maxZoom': (number) The maximum zoom level that a marker can be part of a
- * cluster.
- * 'zoomOnClick': (boolean) Whether the default behaviour of clicking on a
- * cluster is to zoom into it.
- * 'averageCenter': (boolean) Wether the center of each cluster should be
- * the average of all markers in the cluster.
- * 'styles': (object) An object that has style properties:
- * 'url': (string) The image url.
- * 'height': (number) The image height.
- * 'width': (number) The image width.
- * 'anchor': (Array) The anchor position of the label text.
- * 'textColor': (string) The text color.
- * 'textSize': (number) The text size.
- * @constructor
- * @extends google.maps.OverlayView
- */
- function MarkerClusterer(map, opt_markers, opt_options) {
- this.extend(MarkerClusterer, google.maps.OverlayView);
- this.map_ = map;
- /**
- * @type {Array.<google.maps.Marker>}
- * @private
- */
- this.markers_ = [];
- /**
- * @type {Array.<Cluster>}
- */
- this.clusters_ = [];
- this.sizes = [53, 56, 66, 78, 90];
- /**
- * @private
- */
- this.styles_ = [];
- /**
- * @type {boolean}
- * @private
- */
- this.ready_ = false;
- var options = opt_options || {};
- /**
- * @type {number}
- * @private
- */
- this.gridSize_ = options['gridSize'] || 60;
- /**
- * @type {?number}
- * @private
- */
- this.maxZoom_ = options['maxZoom'] || 20;
- this.styles_ = options['styles'] || [];
- /**
- * @type {string}
- * @private
- */
- this.imagePath_ = options['imagePath'] ||
- this.MARKER_CLUSTER_IMAGE_PATH_;
- /**
- * @type {string}
- * @private
- */
- this.imageExtension_ = options['imageExtension'] ||
- this.MARKER_CLUSTER_IMAGE_EXTENSION_;
- /**
- * @type {boolean}
- * @private
- */
- this.zoomOnClick_ = true;
- if (options['zoomOnClick'] != undefined) {
- this.zoomOnClick_ = options['zoomOnClick'];
- }
- /**
- * @type {boolean}
- * @private
- */
- this.averageCenter_ = false;
- if (options['averageCenter'] != undefined) {
- this.averageCenter_ = options['averageCenter'];
- }
- this.setupStyles_();
- this.setMap(map);
- /**
- * @type {number}
- * @private
- */
- this.prevZoom_ = this.map_.getZoom();
- var that = this;
- google.maps.event.addListener(this.map_, 'zoom_changed', function() {
- var maxZoom = that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom;
- var zoom = that.map_.getZoom();
- if (zoom < 0 || zoom > maxZoom) {
- return;
- }
- if (that.prevZoom_ != zoom) {
- that.prevZoom_ = that.map_.getZoom();
- if(zoom > that.maxZoom_)
- that.resetViewport(); //Ilab modification default behavior
- else
- that.processMarkersVisibility();
- }
- });
- google.maps.event.addListener(this.map_, 'idle', function() {
- that.redraw();
- });
- if (opt_markers && opt_markers.length) {
- this.addMarkers(opt_markers, false);
- }
- }
- /**
- * The marker cluster image path.
- *
- * @type {string}
- * @private
- */
- MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ = SETTING.WEBROOT + 'images/clusterer/m';
- /**
- * The marker cluster image path.
- *
- * @type {string}
- * @private
- */
- MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_ = 'png';
- /**
- * Extends a objects prototype by anothers.
- *
- * @param {Object} obj1 The object to be extended.
- * @param {Object} obj2 The object to extend with.
- * @return {Object} The new extended object.
- * @ignore
- */
- MarkerClusterer.prototype.extend = function(obj1, obj2) {
- return (function(object) {
- for (property in object.prototype) {
- this.prototype[property] = object.prototype[property];
- }
- return this;
- }).apply(obj1, [obj2]);
- };
- /**
- * Implementaion of the interface method.
- * @ignore
- */
- MarkerClusterer.prototype.onAdd = function() {
- this.setReady_(true);
- };
- /**
- * Implementaion of the interface method.
- * @ignore
- */
- MarkerClusterer.prototype.draw = function() {};
- /**
- * Sets up the styles object.
- *
- * @private
- */
- MarkerClusterer.prototype.setupStyles_ = function() {
- if (this.styles_.length) {
- return;
- }
- for (var i = 0, size; size = this.sizes[i]; i++) {
- this.styles_.push({
- url: this.imagePath_ + (i + 1) + '.' + this.imageExtension_,
- height: size,
- width: size
- });
- }
- };
- /**
- * Sets the styles.
- *
- * @param {Object} styles The style to set.
- */
- MarkerClusterer.prototype.setStyles = function(styles) {
- this.styles_ = styles;
- };
- /**
- * Gets the styles.
- *
- * @return {Object} The styles object.
- */
- MarkerClusterer.prototype.getStyles = function() {
- return this.styles_;
- };
- /**
- * Whether zoom on click is set.
- *
- * @return {boolean} True if zoomOnClick_ is set.
- */
- MarkerClusterer.prototype.isZoomOnClick = function() {
- return this.zoomOnClick_;
- };
- /**
- * Whether average center is set.
- *
- * @return {boolean} True if averageCenter_ is set.
- */
- MarkerClusterer.prototype.isAverageCenter = function() {
- return this.averageCenter_;
- };
- /**
- * Returns the array of markers in the clusterer.
- *
- * @return {Array.<google.maps.Marker>} The markers.
- */
- MarkerClusterer.prototype.getMarkers = function() {
- return this.markers_;
- };
- /**
- * Returns the array of markers in the clusterer.
- *
- * @return {Array.<google.maps.Marker>} The number of markers.
- */
- MarkerClusterer.prototype.getTotalMarkers = function() {
- return this.markers_;
- };
- MarkerClusterer.prototype.processMarkersVisibility = function(redraw) {
- var markers = this.getMarkers(); // 10 marker.isAdd ==
- this.resetViewport();
- var data = this.getData(); // data = {1:false,2:false}
- if(data){
- for(var i=0;i<markers.length;i++){
- for(var layer_id in data){
- var visible = data[layer_id];
- if(markers[i].layer_id == layer_id && visible==false){
- markers[i].isAdded = true;
- }
- }
- }
- }
- if(redraw)
- this.redraw();
- };
- MarkerClusterer.prototype.setData = function(data) {
- this.data = data;
- };
- MarkerClusterer.prototype.getData = function() {
- var data = Util.Cookies.getAsObject("activeLayers");
- var interestedLayers = {};
- for(var layer_id in data){
- if(data[layer_id]==false)
- interestedLayers[layer_id] = false;
- }
- return interestedLayers;
- };
- /**
- * Sets the max zoom for the clusterer.
- *
- * @param {number} maxZoom The max zoom level.
- */
- MarkerClusterer.prototype.setMaxZoom = function(maxZoom) {
- this.maxZoom_ = maxZoom;
- };
- /**
- * Gets the max zoom for the clusterer.
- *
- * @return {number} The max zoom level.
- */
- MarkerClusterer.prototype.getMaxZoom = function() {
- return this.maxZoom_ || this.map_.mapTypes[this.map_.getMapTypeId()].maxZoom;
- };
- /**
- * The function for calculating the cluster icon image.
- *
- * @param {Array.<google.maps.Marker>} markers The markers in the clusterer.
- * @param {number} numStyles The number of styles available.
- * @return {Object} A object properties: 'text' (string) and 'index' (number).
- * @private
- */
- MarkerClusterer.prototype.calculator_ = function(markers, numStyles) {
- var index = 0;
- var count = markers.length;
- var dv = count;
- while (dv !== 0) {
- dv = parseInt(dv / 10, 10);
- index++;
- }
- index = Math.min(index, numStyles);
- return {
- text: count,
- index: index
- };
- };
- /**
- * Set the calculator function.
- *
- * @param {function(Array, number)} calculator The function to set as the
- * calculator. The function should return a object properties:
- * 'text' (string) and 'index' (number).
- *
- */
- MarkerClusterer.prototype.setCalculator = function(calculator) {
- this.calculator_ = calculator;
- };
- /**
- * Get the calculator function.
- *
- * @return {function(Array, number)} the calculator function.
- */
- MarkerClusterer.prototype.getCalculator = function() {
- return this.calculator_;
- };
- /**
- * Add an array of markers to the clusterer.
- *
- * @param {Array.<google.maps.Marker>} markers The markers to add.
- * @param {boolean} opt_nodraw Whether to redraw the clusters.
- */
- MarkerClusterer.prototype.addMarkers = function(markers, opt_nodraw) {
- for (var i = 0, marker; marker = markers[i]; i++) {
- this.pushMarkerTo_(marker);
- }
- if (!opt_nodraw) {
- this.redraw();
- }
- };
- /**
- * Pushes a marker to the clusterer.
- *
- * @param {google.maps.Marker} marker The marker to add.
- * @private
- */
- MarkerClusterer.prototype.pushMarkerTo_ = function(marker) {
- marker.setVisible(false);
- marker.setMap(null);
- var data = Util.Cookies.getAsObject("activeLayers");
- marker.isAdded = false;
- for(var layer_id in data){
- var visible = data[layer_id];
- if(marker.layer_id == layer_id && visible==false){
- marker.isAdded = true;
- }
- }
- if (marker['draggable']) {
- var that = this;
- google.maps.event.addListener(marker, 'dragend', function() {
- marker.isAdded = false;
- that.resetViewport();
- that.redraw();
- });
- }
- this.markers_.push(marker);
- };
- /**
- * Adds a marker to the clusterer and redraws if needed.
- *
- * @param {google.maps.Marker} marker The marker to add.
- * @param {boolean} opt_nodraw Whether to redraw the clusters.
- */
- MarkerClusterer.prototype.addMarker = function(marker, opt_nodraw) {
- this.pushMarkerTo_(marker);
- if (!opt_nodraw) {
- this.redraw();
- }
- };
- /**
- * Remove a marker from the cluster.
- *
- * @param {google.maps.Marker} marker The marker to remove.
- * @return {boolean} True if the marker was removed.
- */
- MarkerClusterer.prototype.removeMarker = function(marker) {
- var index = -1;
- if (this.markers_.indexOf) {
- index = this.markers_.indexOf(marker);
- } else {
- for (var i = 0, m; m = this.markers_[i]; i++) {
- if (m == marker) {
- index = i;
- continue;
- }
- }
- }
- if (index == -1) {
- return false;
- }
- this.markers_.splice(index, 1);
- marker.setVisible(false);
- marker.setMap(null);
- this.resetViewport();
- this.redraw();
- return true;
- };
- /**
- * Sets the clusterer's ready state.
- *
- * @param {boolean} ready The state.
- * @private
- */
- MarkerClusterer.prototype.setReady_ = function(ready) {
- if (!this.ready_) {
- this.ready_ = ready;
- this.createClusters_();
- }
- };
- /**
- * Returns the number of clusters in the clusterer.
- *
- * @return {number} The number of clusters.
- */
- MarkerClusterer.prototype.getTotalClusters = function() {
- return this.clusters_.length;
- };
- /**
- * Returns the google map that the clusterer is associated with.
- *
- * @return {google.maps.Map} The map.
- */
- MarkerClusterer.prototype.getMap = function() {
- return this.map_;
- };
- /**
- * Sets the google map that the clusterer is associated with.
- *
- * @param {google.maps.Map} map The map.
- */
- MarkerClusterer.prototype.setMap = function(map) {
- this.map_ = map;
- };
- /**
- * Returns the size of the grid.
- *
- * @return {number} The grid size.
- */
- MarkerClusterer.prototype.getGridSize = function() {
- /*
- var tran = 50;
- var Ax = this.maxZoom_;
- var By = this.gridSize_- tran ;
- var x = (this.map_.getZoom()>this.maxZoom)?this.maxZoom:this.map_.getZoom();
- var distance = tran + By-(By/Ax)*x ;
- return distance;
- */
- return this.gridSize_;
- };
- /**
- * Returns the size of the grid.
- *
- * @param {number} size The grid size.
- */
- MarkerClusterer.prototype.setGridSize = function(size) {
- this.gridSize_ = size;
- };
- /**
- * Extends a bounds object by the grid size.
- *
- * @param {google.maps.LatLngBounds} bounds The bounds to extend.
- * @return {google.maps.LatLngBounds} The extended bounds.
- */
- MarkerClusterer.prototype.getExtendedBounds = function(bounds) {
- var projection = this.getProjection();
- var tr = new google.maps.LatLng(bounds.getNorthEast().lat(),
- bounds.getNorthEast().lng());
- var bl = new google.maps.LatLng(bounds.getSouthWest().lat(),
- bounds.getSouthWest().lng());
- var trPix = projection.fromLatLngToDivPixel(tr);
- trPix.x += this.gridSize_;
- trPix.y -= this.gridSize_;
- var blPix = projection.fromLatLngToDivPixel(bl);
- blPix.x -= this.gridSize_;
- blPix.y += this.gridSize_;
- var ne = projection.fromDivPixelToLatLng(trPix);
- var sw = projection.fromDivPixelToLatLng(blPix);
- bounds.extend(ne);
- bounds.extend(sw);
- return bounds;
- };
- /**
- * Determins if a marker is contained in a bounds.
- *
- * @param {google.maps.Marker} marker The marker to check.
- * @param {google.maps.LatLngBounds} bounds The bounds to check against.
- * @return {boolean} True if the marker is in the bounds.
- * @private
- */
- MarkerClusterer.prototype.isMarkerInBounds_ = function(marker, bounds) {
- return bounds.contains(marker.getPosition());
- };
- /**
- * Clears all clusters and markers from the clusterer.
- */
- MarkerClusterer.prototype.clearMarkers = function() {
- this.resetViewport();
- this.markers_ = [];
- };
- /**
- * Clears all existing clusters and recreates them.
- */
- MarkerClusterer.prototype.resetViewport = function() {
- for (var i = 0, cluster; cluster = this.clusters_[i]; i++) {
- cluster.remove();
- }
- for (var i = 0, marker; marker = this.markers_[i]; i++) {
- marker.isAdded = false;
- marker.setMap(null);
- marker.setVisible(false);
- }
- this.clusters_ = [];
- };
- /**
- * Redraws the clusters.
- */
- MarkerClusterer.prototype.redraw = function() {
- this.createClusters_();
- };
- /**
- * Creates the clusters.
- *
- * @private
- */
- MarkerClusterer.prototype.createClusters_ = function() {
- if (!this.ready_) {
- return;
- }
- var mapBounds = new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),
- this.map_.getBounds().getNorthEast());
- var bounds = this.getExtendedBounds(mapBounds);
- for (var i = 0, marker; marker = this.markers_[i]; i++) {
- var added = false;
- if (!marker.isAdded && this.isMarkerInBounds_(marker, bounds)) {
- for (var j = 0, cluster; cluster = this.clusters_[j]; j++) {
- if (!added && cluster.getCenter() &&
- cluster.isMarkerInClusterBounds(marker)) {
- added = true;
- cluster.addMarker(marker);
- break;
- }
- }
- if (!added) {
- var cluster = new Cluster(this);
- cluster.addMarker(marker);
- this.clusters_.push(cluster);
- }
- }
- }
- };
- /**
- * A cluster that contains markers.
- *
- * @param {MarkerClusterer} markerClusterer The markerclusterer that this
- * cluster is associated with.
- * @constructor
- * @ignore
- */
- function Cluster(markerClusterer) {
- this.markerClusterer_ = markerClusterer;
- this.map_ = markerClusterer.getMap();
- this.gridSize_ = markerClusterer.getGridSize();
- this.averageCenter_ = markerClusterer.isAverageCenter();
- this.center_ = null;
- this.markers_ = [];
- this.bounds_ = null;
- this.clusterIcon_ = new ClusterIcon(this, markerClusterer.getStyles(),
- markerClusterer.getGridSize());
- }
- /**
- * Determins if a marker is already added to the cluster.
- *
- * @param {google.maps.Marker} marker The marker to check.
- * @return {boolean} True if the marker is already added.
- */
- Cluster.prototype.isMarkerAlreadyAdded = function(marker) {
- if (this.markers_.indexOf) {
- return this.markers_.indexOf(marker) != -1;
- } else {
- for (var i = 0, m; m = this.markers_[i]; i++) {
- if (m == marker) {
- return true;
- }
- }
- }
- return false;
- };
- /**
- * Add a marker the cluster.
- *
- * @param {google.maps.Marker} marker The marker to add.
- * @return {boolean} True if the marker was added.
- */
- Cluster.prototype.addMarker = function(marker) {
- if (this.isMarkerAlreadyAdded(marker)) {
- return false;
- }
- if (!this.center_) {
- this.center_ = marker.getPosition();
- this.calculateBounds_();
- } else {
- if (this.averageCenter_) {
- var lat = (this.center_.lat() + marker.getPosition().lat()) / 2;
- var lng = (this.center_.lng() + marker.getPosition().lng()) / 2;
- this.center_ = new google.maps.LatLng(lat, lng);
- this.calculateBounds_();
- }
- }
- if (this.markers_.length == 0) {
- marker.setMap(this.map_);
- marker.setVisible(true);
- } else if (this.markers_.length == 1) {
- this.markers_[0].setMap(null);
- this.markers_[0].setVisible(false);
- }
- marker.isAdded = true;
- this.markers_.push(marker);
- this.updateIcon();
- return true;
- };
- /**
- * Returns the marker clusterer that the cluster is associated with.
- *
- * @return {MarkerClusterer} The associated marker clusterer.
- */
- Cluster.prototype.getMarkerClusterer = function() {
- return this.markerClusterer_;
- };
- /**
- * Returns the bounds of the cluster.
- *
- * @return {google.maps.LatLngBounds} the cluster bounds.
- */
- Cluster.prototype.getBounds = function() {
- this.calculateBounds_();
- return this.bounds_;
- };
- /**
- * Removes the cluster
- */
- Cluster.prototype.remove = function() {
- this.clusterIcon_.remove();
- this.markers_.length = 0;
- delete this.markers_;
- };
- /**
- * Returns the center of the cluster.
- *
- * @return {number} The cluster center.
- */
- Cluster.prototype.getSize = function() {
- return this.markers_.length;
- };
- /**
- * Returns the center of the cluster.
- *
- * @return {Array.<google.maps.Marker>} The cluster center.
- */
- Cluster.prototype.getMarkers = function() {
- return this.markers_;
- };
- /**
- * Returns the center of the cluster.
- *
- * @return {google.maps.LatLng} The cluster center.
- */
- Cluster.prototype.getCenter = function() {
- return this.center_;
- };
- /**
- * Calculated the bounds of the cluster with the grid.
- *
- * @private
- */
- Cluster.prototype.calculateBounds_ = function() {
- var bounds = new google.maps.LatLngBounds(this.center_, this.center_);
- this.bounds_ = this.markerClusterer_.getExtendedBounds(bounds);
- };
- /**
- * Determines if a marker lies in the clusters bounds.
- *
- * @param {google.maps.Marker} marker The marker to check.
- * @return {boolean} True if the marker lies in the bounds.
- */
- Cluster.prototype.isMarkerInClusterBounds = function(marker) {
- return this.bounds_.contains(marker.getPosition());
- };
- /**
- * Returns the map that the cluster is associated with.
- *
- * @return {google.maps.Map} The map.
- */
- Cluster.prototype.getMap = function() {
- return this.map_;
- };
- /**
- * Updates the cluster icon
- */
- Cluster.prototype.updateIcon = function() {
- var zoom = this.map_.getZoom();
- var mz = this.markerClusterer_.getMaxZoom();
- if (zoom > mz) {
- for (var i = 0, marker; marker = this.markers_[i]; i++) {
- marker.setMap(this.map_);
- marker.setVisible(true);
- }
- return;
- }
- if (this.markers_.length < 2) {
- this.clusterIcon_.hide();
- return;
- }
- var numStyles = this.markerClusterer_.getStyles().length;
- var sums = this.markerClusterer_.getCalculator()(this.markers_, numStyles);
- this.clusterIcon_.setCenter(this.center_);
- this.clusterIcon_.setSums(sums);
- this.clusterIcon_.show();
- };
- /**
- * A cluster icon
- *
- * @param {Cluster} cluster The cluster to be associated with.
- * @param {Object} styles An object that has style properties:
- * 'url': (string) The image url.
- * 'height': (number) The image height.
- * 'width': (number) The image width.
- * 'anchor': (Array) The anchor position of the label text.
- * 'textColor': (string) The text color.
- * 'textSize': (number) The text size.
- * @param {number} opt_padding Optional padding to apply to the cluster icon.
- * @constructor
- * @extends google.maps.OverlayView
- * @ignore
- */
- function ClusterIcon(cluster, styles, opt_padding) {
- cluster.getMarkerClusterer().extend(ClusterIcon, google.maps.OverlayView);
- this.styles_ = styles;
- this.padding_ = opt_padding || 0;
- this.cluster_ = cluster;
- this.center_ = null;
- this.map_ = cluster.getMap();
- this.div_ = null;
- this.sums_ = null;
- this.visible_ = false;
- this.setMap(this.map_);
- }
- /**
- * Triggers the clusterclick event and zoom's if the option is set.
- */
- ClusterIcon.prototype.triggerClusterClick = function() {
- var markerClusterer = this.cluster_.getMarkerClusterer();
- google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);
- if (markerClusterer.isZoomOnClick()) {
- this.map_.panTo(this.cluster_.getCenter());
- this.map_.fitBounds(this.cluster_.getBounds());
- }
- };
- /**
- * Adding the cluster icon to the dom.
- * @ignore
- */
- ClusterIcon.prototype.onAdd = function() {
- this.div_ = document.createElement('DIV');
- if (this.visible_) {
- var pos = this.getPosFromLatLng_(this.center_);
- this.div_.style.cssText = this.createCss(pos);
- this.div_.innerHTML = this.sums_.text;
- }
- var panes = this.getPanes();
- panes.overlayImage.appendChild(this.div_);
- var that = this;
- google.maps.event.addDomListener(this.div_, 'click', function() {
- that.triggerClusterClick();
- });
- };
- /**
- * Returns the position to place the div dending on the latlng.
- *
- * @param {google.maps.LatLng} latlng The position in latlng.
- * @return {google.maps.Point} The position in pixels.
- * @private
- */
- ClusterIcon.prototype.getPosFromLatLng_ = function(latlng) {
- var pos = this.getProjection().fromLatLngToDivPixel(latlng);
- pos.x -= parseInt(this.width_ / 2, 10);
- pos.y -= parseInt(this.height_ / 2, 10);
- return pos;
- };
- /**
- * Draw the icon.
- * @ignore
- */
- ClusterIcon.prototype.draw = function() {
- if (this.visible_) {
- var pos = this.getPosFromLatLng_(this.center_);
- this.div_.style.top = pos.y + 'px';
- this.div_.style.left = pos.x + 'px';
- }
- };
- /**
- * Hide the icon.
- */
- ClusterIcon.prototype.hide = function() {
- if (this.div_) {
- this.div_.style.display = 'none';
- }
- this.visible_ = false;
- };
- /**
- * Position and show the icon.
- */
- ClusterIcon.prototype.show = function() {
- if (this.div_) {
- var pos = this.getPosFromLatLng_(this.center_);
- this.div_.style.cssText = this.createCss(pos);
- this.div_.style.display = '';
- }
- this.visible_ = true;
- };
- /**
- * Remove the icon from the map
- */
- ClusterIcon.prototype.remove = function() {
- this.setMap(null);
- };
- /**
- * Implementation of the onRemove interface.
- * @ignore
- */
- ClusterIcon.prototype.onRemove = function() {
- if (this.div_ && this.div_.parentNode) {
- this.hide();
- this.div_.parentNode.removeChild(this.div_);
- this.div_ = null;
- }
- };
- /**
- * Set the sums of the icon.
- *
- * @param {Object} sums The sums containing:
- * 'text': (string) The text to display in the icon.
- * 'index': (number) The style index of the icon.
- */
- ClusterIcon.prototype.setSums = function(sums) {
- this.sums_ = sums;
- this.text_ = sums.text;
- this.index_ = sums.index;
- if (this.div_) {
- this.div_.innerHTML = sums.text;
- }
- this.useStyle();
- };
- /**
- * Sets the icon to the the styles.
- */
- ClusterIcon.prototype.useStyle = function() {
- var index = Math.max(0, this.sums_.index - 1);
- index = Math.min(this.styles_.length - 1, index);
- var style = this.styles_[index];
- this.url_ = style['url'];
- this.height_ = style['height'];
- this.width_ = style['width'];
- this.textColor_ = style['textColor'];
- this.anchor = style['anchor'];
- this.textSize_ = style['textSize'];
- };
- /**
- * Sets the center of the icon.
- *
- * @param {google.maps.LatLng} center The latlng to set as the center.
- */
- ClusterIcon.prototype.setCenter = function(center) {
- this.center_ = center;
- };
- /**
- * Create the css text based on the position of the icon.
- *
- * @param {google.maps.Point} pos The position.
- * @return {string} The css style text.
- */
- ClusterIcon.prototype.createCss = function(pos) {
- var style = [];
- if (document.all) {
- style.push('filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(' +
- 'sizingMethod=scale,src="' + this.url_ + '");');
- } else {
- style.push('background:url(' + this.url_ + ');');
- }
- if (typeof this.anchor_ === 'object') {
- if (typeof this.anchor_[0] === 'number' && this.anchor_[0] > 0 &&
- this.anchor_[0] < this.height_) {
- style.push('height:' + (this.height_ - this.anchor_[0]) +
- 'px; padding-top:' + this.anchor_[0] + 'px;');
- } else {
- style.push('height:' + this.height_ + 'px; line-height:' + this.height_ +
- 'px;');
- }
- if (typeof this.anchor_[1] === 'number' && this.anchor_[1] > 0 &&
- this.anchor_[1] < this.width_) {
- style.push('width:' + (this.width_ - this.anchor_[1]) +
- 'px; padding-left:' + this.anchor_[1] + 'px;');
- } else {
- style.push('width:' + this.width_ + 'px; text-align:center;');
- }
- } else {
- style.push('height:' + this.height_ + 'px; line-height:' +
- this.height_ + 'px; width:' + this.width_ + 'px; text-align:center;');
- }
- var txtColor = this.textColor_ ? this.textColor_ : 'black';
- var txtSize = this.textSize_ ? this.textSize_ : 11;
- style.push('cursor:pointer; top:' + pos.y + 'px; left:' +
- pos.x + 'px; color:' + txtColor + '; position:absolute; font-size:' +
- txtSize + 'px; font-family:Arial,sans-serif; font-weight:bold');
- return style.join('');
- };
- window['MarkerClusterer'] = MarkerClusterer;
- MarkerClusterer.prototype['addMarker'] = MarkerClusterer.prototype.addMarker;
- MarkerClusterer.prototype['addMarkers'] = MarkerClusterer.prototype.addMarkers;
- MarkerClusterer.prototype['clearMarkers'] =
- MarkerClusterer.prototype.clearMarkers;
- MarkerClusterer.prototype['getCalculator'] =
- MarkerClusterer.prototype.getCalculator;
- MarkerClusterer.prototype['getGridSize'] =
- MarkerClusterer.prototype.getGridSize;
- MarkerClusterer.prototype['getMap'] = MarkerClusterer.prototype.getMap;
- MarkerClusterer.prototype['getMarkers'] = MarkerClusterer.prototype.getMarkers;
- MarkerClusterer.prototype['getMaxZoom'] = MarkerClusterer.prototype.getMaxZoom;
- MarkerClusterer.prototype['getStyles'] = MarkerClusterer.prototype.getStyles;
- MarkerClusterer.prototype['getTotalClusters'] =
- MarkerClusterer.prototype.getTotalClusters;
- MarkerClusterer.prototype['getTotalMarkers'] =
- MarkerClusterer.prototype.getTotalMarkers;
- MarkerClusterer.prototype['redraw'] = MarkerClusterer.prototype.redraw;
- MarkerClusterer.prototype['removeMarker'] =
- MarkerClusterer.prototype.removeMarker;
- MarkerClusterer.prototype['resetViewport'] =
- MarkerClusterer.prototype.resetViewport;
- MarkerClusterer.prototype['setCalculator'] =
- MarkerClusterer.prototype.setCalculator;
- MarkerClusterer.prototype['setGridSize'] =
- MarkerClusterer.prototype.setGridSize;
- MarkerClusterer.prototype['onAdd'] = MarkerClusterer.prototype.onAdd;
- MarkerClusterer.prototype['draw'] = MarkerClusterer.prototype.draw;
- Cluster.prototype['getCenter'] = Cluster.prototype.getCenter;
- Cluster.prototype['getSize'] = Cluster.prototype.getSize;
- Cluster.prototype['getMarkers'] = Cluster.prototype.getMarkers;
- ClusterIcon.prototype['onAdd'] = ClusterIcon.prototype.onAdd;
- ClusterIcon.prototype['draw'] = ClusterIcon.prototype.draw;
- ClusterIcon.prototype['onRemove'] = ClusterIcon.prototype.onRemove;
- Model.Factory = {
- models: {},
- create: function(modelName){
- if(!this.models[modelName]){
- this.models[modelName] = new Model[modelName];
- }
- return this.models[modelName];
- }
- }
- Model.LayerManager = function(){
- var _self = this;
- this.layers = [];
- this.myLayers = [];
- Helper.layerHelper = new Helper.LayerHelper(this);
- this.getAllLayers = function(){
- AjaxRequest.get("/layers", function(response) {
- _self._getLayersEventHandler(response);
- });
- }
- this.getLayers = function(user) {
- AjaxRequest.get("/layers?user=" + user, function(response) {
- _self._getLayersEventHandler(response);
- });
- }
- this._getLayersEventHandler = function(response) {
- if(response.status == 200){
- var layersChanged = new Events.LayersEvent(Events.LayersEvent.LAYERS_CHANGED);
- _self.layers = Json.decode(response.responseText);
- GEvent.dispatchEvent(layersChanged);
- }
- }
- this.createLayer = function(data){
- AjaxRequest.post('/layers.json', data, function(response){
- _self._createLayerEventHandler(response);
- });
- }
- this._createLayerEventHandler = function(response){
- if(response.status == 201){
- GEvent.dispatchEvent(new Events.LayersEvent(Events.LayersEvent.LAYER_ADDED));
- _self.layers.push(Json.decode(response.responseText));
- GEvent.dispatchEvent(new Events.LayersEvent(Events.LayersEvent.LAYERS_CHANGED));
- GEvent.dispatchEvent(new Events.UsersEvent(Events.UsersEvent.USERS_RELOAD));
- }
- }
- this.loadMyLayer = function() {
- var options = {
- url:"/mylayers.json",
- headers:{"auth_token":Authentication.getAuthToken()},
- method:'get',
- success:_self._getMyLayersEventHandler
- };
- Util.Ajax(options);
- }
- this._getMyLayersEventHandler = function(response){
- var _self = this;
- if (response.status == 200){
- _self.myLayers = Json.decode(response.responseText);
- GEvent.dispatchEvent(new Events.LayersEvent(Events.LayersEvent.MYLAYERS_CHANGED,_self.myLayers));
- }
- }
- this.createMyLayer = function(data){
- var options = {
- url:"/layers.json",
- method:'post',
- params:data,
- success:_self._createMyLayerEventHandler
- };
- Util.Ajax(options);
- }
- this._createMyLayerEventHandler = function(response){
- if(response.status == 201){
- var layer = Json.decode(response.responseText);
- Util.func.setCurrentUserAsLayerOwner(layer);
- _self.layers.push(layer);
- GEvent.dispatchEvent(new Events.LayersEvent(Events.LayersEvent.MY_LAYER_ADDED,layer));
- }
- else{
- var errors = Json.decode(response.responseText);
- GEvent.dispatchEvent(new Events.LayersEvent(Events.LayersEvent.MY_LAYER_ADDED_FAILED, errors));
- }
- }
- this.getPublicLayers = function(){
- AjaxRequest.get('/public_layers', function(response){
- _self._getPublicLayersEventHandler(response);
- });
- }
- this._getPublicLayersEventHandler = function(response){
- if(response.status == 200){
- _self.layers = Json.decode(response.responseText);
- var layersChanged = new Events.LayersEvent(Events.LayersEvent.LAYERS_CHANGED);
- GEvent.dispatchEvent(layersChanged);
- }
- }
- this.updateMyLayerStatus = function(data){
- var _self = this;
- var options = {
- url:"/update_my_layer_status.json" ,
- method:'post',
- params: data,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._updateMyLayerStatusHandler
- };
- Util.Ajax(options);
- };
- this._updateMyLayerStatusHandler = function(response){
- if(response.status == 200){
- var datas = Json.decode(response.responseText);
- var layersChanged = new Events.LayersEvent(Events.LayersEvent.LAYERS_MY_LAYER_STATUS_SAVED);
- GEvent.dispatchEvent(layersChanged);
- }
- else{
- var datas = Json.decode(response.responseText);
- var layersChanged = new Events.LayersEvent(Events.LayersEvent.LAYERS_MY_LAYER_STATUS_SAVED_FAILED,datas);
- GEvent.dispatchEvent(layersChanged);
- }
- };
- this.findById = function(id){
- for(var i = 0; i < this.layers.length; i++){
- if(this.layers[i].id == id){
- return this.layers[i];
- }
- }
- return null;
- };
- this.saveMember = function(data){
- var _self = this;
- data = Json.encode(data);
- var options = {
- url:"/create_membership.json",
- method:'post',
- params: data,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._saveMemberHandler
- };
- Util.Ajax(options);
- };
- this._saveMemberHandler = function(response){
- var data = Json.decode(response.responseText);
- if(response.status == 201) {
- var memberSaved = new Events.MemberEvent(Events.MemberEvent.MEMBER_CREATED,data);
- GEvent.dispatchEvent(memberSaved);
- }
- else if (response.status == 200) {
- var memberSavedFailed = new Events.MemberEvent(Events.MemberEvent.MEMBER_CREATED_FAILED,data);
- GEvent.dispatchEvent(memberSavedFailed);
- }
- };
- this.editMember = function(data){
- var _self = this;
- params = Json.encode(data);
- var options = {
- url: "/getMembership?user_id=" + data.userId + "&layer_id=" + data.layerId ,
- method:'get',
- params: data,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._editMemberHandler
- };
- Util.Ajax(options);
- };
- this._editMemberHandler = function(response){
- var data = Json.decode(response.responseText);
- if(response.status == 200) {
- var getMemberSuccess= new Events.MemberEvent(Events.MemberEvent.GET_MEMBER_SUCCESS,data);
- GEvent.dispatchEvent(getMemberSuccess);
- }
- else if (response.status == 404) {
- alert('could not find this member');
- }
- };
- this.updateMember = function(data){
- var _self = this;
- params = Json.encode(data);
- var options = {
- url: "/memberships/" + data.id + ".json" ,
- method:'put',
- params: params,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._updateMemberHandler
- };
- Util.Ajax(options);
- };
- this._updateMemberHandler = function(response){
- var data = Json.decode(response.responseText);
- if(response.status == 201) {
- var memberGetUpdated = new Events.MemberEvent(Events.MemberEvent.MEMBER_GET_UPDATED,data);
- GEvent.dispatchEvent(memberGetUpdated);
- }
- else if (response.status == 200) {
- var memberGetUpdatedFailed = new Events.MemberEvent(Events.MemberEvent.MEMBER_GET_UPDATED_FAILED,data);
- GEvent.dispatchEvent(memberGetUpdatedFailed);
- }
- };
- }
- Model.ResourceManager = function(){
- var _self = this;
- this.resources = [];
- this.currentResource = null
- this.getResourceDetailForResourceList = function(id){
- AjaxRequest.get("/resources/" + id, function(response){
- _self._getResourceDetailForResourceList(response);
- })
- };
- this._getResourceDetailForResourceList = function(response){
- var resouceDetailEvent = null;
- if(response.status == 200){
- var resource = Json.decode(response.responseText);
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_DETAIL_FOR_RESOURCE_LIST, resource);
- }
- else{
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_DETAIL_FOR_RESOURCE_LIST_FAILED);
- }
- GEvent.dispatchEvent(resouceDetailEvent);
- };
- this.loadResources = function(){
- AjaxRequest.get("/resources", function(response){
- _self._loadResourcesEventHandler(response);
- });
- };
- this.loadResourcesOf = function(queryString){
- GEvent.dispatchEvent(new Events.MapsEvent(Events.MapsEvent.LOADING_WINDOW_SHOW));
- AjaxRequest.get("/resources?" +queryString, function(response){
- _self._loadResourcesEventHandler(response);
- });
- };
- this._loadResourcesEventHandler = function(response){
- if(response.status == 200){
- _self.resources = Json.decode(response.responseText);
- GEvent.dispatchEvent(new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCES_CHANGED));
- }
- GEvent.dispatchEvent(new Events.MapsEvent(Events.MapsEvent.LOADING_WINDOW_CLOSE));
- };
- this.createResource = function(data){
- var param = Json.encode({resource: data});
- var options = {
- url:"/resources",
- method:'post',
- params: param,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._createResourceEventHandler
- };
- Util.Ajax(options);
- };
- this._createResourceEventHandler = function(response){
- var resouceAddedEvent = null;
- if(response.status == 200){
- var resource = Json.decode(response.responseText);
- resouceAddedEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_ADDED, resource);
- _self.resources.push(Json.decode(response.responseText));
- }
- else{
- resouceAddedEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_ADDED, false);
- }
- GEvent.dispatchEvent(resouceAddedEvent);
- };
- this.getResourceDetail = function(id){
- AjaxRequest.get("/resources/" + id, function(response){
- _self._getResourceDetailEventHandler(response);
- })
- };
- this._getResourceDetailEventHandler = function(response){
- var resouceDetailEvent = null;
- if(response.status == 200){
- this.currentResource = Json.decode(response.responseText);
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_DETAIL, this.currentResource);
- }
- else{
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_DETAIL_FAILED);
- }
- GEvent.dispatchEvent(resouceDetailEvent);
- };
- this.loadResourcesPaging = function(data){
- var options = {
- url:"/layers/" + data.layerId + "/resources.json?page=" + data.page ,
- method:'get',
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._loadResourcesPaging
- };
- Util.Ajax(options);
- };
- this._loadResourcesPaging = function(response){
- var resouceDetailEvent = null;
- if(response.status == 200){
- var resources = Json.decode(response.responseText);
- resoucePaginglEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_PAGING, resources);
- }
- else{
- resoucePaginglEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_PAGING_FAILED);
- }
- GEvent.dispatchEvent(resoucePaginglEvent);
- };
- this.getResourceTemplate = function(layerId){
- var options = {
- url:"/layers/" + data.layerId + "/property_templates.json",
- method:'get',
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._getResourceTemplateEventHandler
- };
- Util.Ajax(options);
- };
- this._getResourceTemplateEventHandler = function(response){
- var resouceDetailEvent = null;
- if(response.status == 200){
- var template = Json.decode(response.responseText);
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_TEMPLATE, template);
- }
- else{
- resouceDetailEvent = new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_GET_TEMPLATE_FAILED);
- }
- GEvent.dispatchEvent(resouceDetailEvent);
- };
- this.confirmImport = function(fileName, layerId){
- GEvent.dispatchEvent(new Events.MapsEvent(Events.ResourcesEvent.LOADING_IMPORT_WINDOW_SHOW));
- var options = {
- url:"/import_from_csv",
- params: {fileName: fileName, layerId: layerId},
- method:'post',
- success:_self._confirmImportEventHandler
- };
- Util.Ajax(options);
- };
- this._confirmImportEventHandler = function(response){
- if (response.status == 200){
- var resources = Json.decode(response.responseText);
- for(var i = 0; i < resources.length; i++){
- _self.addResource(resources[i]);
- }
- GEvent.dispatchEvent(new Events.MapsEvent(Events.ResourcesEvent.LOADING_IMPORT_WINDOW_CLOSE));
- GEvent.dispatchEvent(new Events.ResourcesEvent(Events.ResourcesEvent.IMPORT_RESOURCES_FROM_CSV_SUCCESS));
- }
- };
- this.addResource = function(resource){
- this.resources.push(resource);
- GEvent.dispatchEvent(new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_ITEM_ADDED, resource));
- };
- this.editResource = function(resourceId){
- AjaxRequest.get("/resources/" +resourceId +"/edit", function(response){
- _self._editResourceHandler(response);
- });
- };
- this._editResourceHandler = function(response){
- if(response.status == 200){
- var resource = Json.decode(response.responseText);
- GEvent.dispatchEvent(new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCE_EDIT_SUCCESS, resource));
- }
- };
- this.updateResource = function(data){
- window.data = data ;
- var param = Json.encode({resource: data});
- var options = {
- url:"/resources/" + data.id ,
- method:'put',
- params: param,
- headers:{"Content-Type":"application/json; charset=utf-8"},
- success:_self._updateResourceEventHandler
- };
- Util.Ajax(options);
- };
- this._updateResourceEventHandler = function(response){
- if(response.status == 200){
- var resource = Json.decode(response.responseText);
- _self._updateResourceInCollection(resource);
- GEvent.dispatchEvent(new Events.ResourcesEvent(Events.ResourcesEvent.RESOURCES_UPDATE_SUCCESS, resource));
- }
- };
- this._updateResourceInCollection = function(resource){
- var resources = _self.resources ;
- for(var i=0;i<resources.length;i++){
- if(resources[i].id == resource.id){
- resources[i].name = resource.name;
- resources[i].lat = resource.lat;
- resources[i].lng = resource.lng;
- return true;
- }
- }
- return false;
- };
- };
- Model.AuthenticationManager = function(){
- var _self = this;
- this.session = {};
- this.login = function(user){
- AjaxRequest.post('/login_rpc', user, function(response){
- _self._loginEventHandler(response);
- });
- };
- this._loginEventHandler = function(response){
- if(response.status == 200){
- _self.session = Json.decode(response.responseText);
- var loginSuccess = new Events.AuthenticationEvent(Events.AuthenticationEvent.LOGIN_SUCCESS);
- GEvent.dispatchEvent(loginSuccess);
- }
- else{
- var loginFailed = new Events.AuthenticationEvent(Events.AuthenticationEvent.LOGIN_FAILED);
- GEvent.dispatchEvent(loginFailed);
- }
- };
- this.logout = function(){
- AjaxRequest.post('/logout_rpc', 'logout', function(response){
- _self._logoutEventHandler(response);
- });
- },
- this._logoutEventHandler = function(response){
- if(response.status == 200){
- var logoutSuccess = new Events.AuthenticationEvent(Events.AuthenticationEvent.LOGOUT_SUCCESS);
- GEvent.dispatchEvent(logoutSuccess);
- }
- }
- }
- Model.UploadManager = function(){
- var _self = this;
- this.getSWFUploadObject = function(){
- return window.SETTING.swfUpload;
- };
- this.startUploadIcon = function(swf){
- swf.startUpload(swf.QueueFile.id);
- };
- this.startImportResources = function(swf){
- swf.startUpload(swf.QueueFile.id);
- }
- };
- Helper.LayerHelper = function(layerManager){
- this.layerManager = layerManager;
- this.getIcon = function(layerId){
- var layer = this.layerManager.findById(layerId);
- return layer && layer.icon? layer.icon : SETTING.MARKER_ICON_DEFAULT;
- };
- this.getLayer = function(layerId){
- return this.layerManager.findById(layerId);
- };
- }
- Events.LayersEvent = function(type, data){
- this.type = type;
- this.data = data;
- }
- Events.LayersEvent.LAYERS_CHANGED = 'layersChangedLayersEvent';
- Events.LayersEvent.LAYER_ADDED = 'layerAddedLayersEvent';
- Events.LayersEvent.LAYER_NEW = 'layerNewLayersEvent';
- Events.LayersEvent.LAYERS_LOAD = 'layersLoadLayersEvent';
- Events.LayersEvent.MYLAYERS_SHOW = 'layersShowMyLayerEvent';
- Events.LayersEvent.MYLAYER_LOAD = 'layersLoadMyLayerEvent';
- Events.LayersEvent.MYLAYERS_CHANGED = 'layersChangeMyLayerEvent';
- Events.LayersEvent.MYLAYERS_HIDE = 'layersHideMyLayerEvent';
- Events.LayersEvent.MYLAYERS_SHOW = 'layersShowMyLayerEvent' ;
- Events.LayersEvent.CREATE_MY_LAYER = 'layerCreateMyLayerEvent';
- Events.LayersEvent.MY_LAYER_ADDED = 'layerMyLayerAddedEvent';
- Events.LayersEvent.MY_LAYER_ADDED_FAILED = 'layerMyLayerAddedFailedEvent';
- Events.LayersEvent.UPDATE_MY_LAYER_STATUS = 'layerUpdateMylayerEvent';
- Events.LayersEvent.LAYERS_MY_LAYER_STATUS_SAVED = 'layerMyLayerStatusSaveEvent';
- Events.LayersEvent.LAYERS_MY_LAYER_STATUS_SAVED_FAILED = "layerMyLayerStatusSavedFailedEvent";
- Events.LayersEvent.LAYERS_UPDATE_RESOURCE_LOCATION_DRAGGING = "layerUpdateResourceLocationDraggingEvent";
- Events.LayersEvent.LAYERS_LOAD_COMPLETED = "layersLoadCompletedLayerEvent";
- Events.LayersEvent.SHOW_FRONT_LAYER_EVENT = "layersShowFrontLayerEvent";
- Events.ResourcesEvent = function(type, data){
- this.type = type;
- this.data = data;
- }
- Events.ResourcesEvent.RESOURCES_CHANGED = 'resourcesChangedResourcesEvent';
- Events.ResourcesEvent.RESOURCES_SAVE = 'resourcesSaveResourcesEvent';
- Events.ResourcesEvent.RESOURCE_ADDED = "resourcesAddedResourceEvent";
- Events.ResourcesEvent.RESOURCE_GET_DETAIL = 'resourceGetDetailEvent';
- Events.ResourcesEvent.RESOURCE_GET_DETAIL_FAILED = 'resourceGetDetailFailedEvent';
- Events.ResourcesEvent.RESOURCE_REQUEST_GET_DETAIL = 'resourceRequestsGetDetailEvent';
- Events.ResourcesEvent.RESOURCE_LOAD = 'resourceLoadResourcesEvent';
- Events.ResourcesEvent.RESOURCES_LOAD_PAGING = 'resourcesLoadPagingResourcesEvent';
- Events.ResourcesEvent.RESOURCES_LOAD_TEMPLATE = 'resourcesLoadTemplateResourcesEvent';
- Events.ResourcesEvent.RESOURCE_GET_TEMPLATE = 'resourcesGetTemplateResourcesEvent';
- Events.ResourcesEvent.RESOURCE_GET_PAGING = "resourcesGetPagingResourcesEvent";
- Events.ResourcesEvent.RESOURCE_GET_PAGING_FAILED = "resourcesGetPagingFailedResourcesEvent";
- Events.ResourcesEvent.RESOURCE_LOAD_DETAIL_FOR_RESOURCE_LIST = "resourceLoadDetailForResourceList";
- Events.ResourcesEvent.RESOURCE_GET_DETAIL_FOR_RESOURCE_LIST = "resourceGetDetailForResourceList";
- Events.ResourcesEvent.RESOURCE_GET_DETAIL_FOR_RESOURCE_LIST_FAILED = "resourceGetDetailForResourceListFailed";
- Events.ResourcesEvent.LOAD_LAYER_RESOURCES = "loadLayerResourcesResourcesEvent";
- Events.ResourcesEvent.SHOW_IMPORT_RESOURCES = "showImportResourcesEvent";
- Events.ResourcesEvent.LOAD_CONFIRMED_RESOURCES = "loadConfirmedResourcesEvent";…
Large files files are truncated, but you can click here to view the full file