//(function () {
angular.module('MobileWebLogistics')
.service('zoomTo', function () {
var self = this;
this.zoomToParcel = function ($scope, fromMapIt) {
//remove everything related to multiple layer identify
$("#identifyButton").removeClass("selected");
$("#iImage").attr('src', "img/ilayers3.png");
$("#identifyButton").css('background', '#666666');
$scope.map.infoWindow.hide();
$scope.map.infoWindow.clearFeatures();
//console.log($scope.map.infoWindow);
//this function is updated for different spatial references
//var thisExtent = $scope.selectedParcel.geometry.getExtent().expand(2.0);
//
if (fromMapIt != "btn") { $scope.bufferLayer.clear(); }
$scope.selectedLayer.clear();
//+++++++++++++++++
var projectParams = new esri.tasks.ProjectParameters();
var parcelGeom = $scope.selectedParcel.geometry;
//console.log (parcelGeom.type);
//$scope.queryObjectId($scope.selectedParcel.GPIN);
//$scope.queryObjectId($scope.selectedParcel[$scope.parcelUid]);
projectParams.geometries = [parcelGeom];
projectParams.outSR = $scope.map.spatialReference;
var geomService = new $scope.GeometryService($scope.geometryServiceUrl);
//var defer = esri.config.defaults.geometryService.project(projectParams);
var defer = geomService.project(projectParams);
dojo.when(defer, function (projectedGeometry) {
if (projectedGeometry.length > 0) { //alert(parcelGeom.type);
//$scope.map.setExtent(projectedGeometry[0]);
if (parcelGeom.type == 'point') { //if address point
var hSymbol = $scope.sms;
$scope.bubbleInfoSource = $scope.ptBubbleInfoField;
$scope.geomType = 'pt';
$scope.map.infoWindow.setTitle($scope.addrPtLyrName);
}
else { //if parcel polygon
var hSymbol = $scope.selParcelSymbol;
$scope.bubbleInfoSource = $scope.bubbleInfoField;
$scope.geomType = 'pl';
$scope.map.infoWindow.setTitle($scope.parcelLyrName);
}
//console.log($scope.selectedParcel);
var highlightGraphic = new $scope.Graphic(projectedGeometry[0], hSymbol);
$scope.selectedLayer.add(highlightGraphic);
if (window.innerWidth > 650) {
//bubble contentPane
var t = '${' + $scope.bubbleInfoSource[0][1] + '}
';
for (var i = 1; i < $scope.bubbleInfoSource.length - 1; i++) {
t += '' + $scope.bubbleInfoSource[i][0] + ': ${' + $scope.bubbleInfoSource[i][1] + '}
';
}
if ($scope.noReport == 'true') {
t += '' + $scope.bubbleBtnTxt[0] + '
'
+ '' + $scope.bubbleBtnTxt[1] + '
';
}
else {
if ($scope.geomType == 'pl') {
t += '' + $scope.bubbleBtnTxt[0] + '
'
+ '' + $scope.bubbleBtnTxt[1] + '
';
}
else if ($scope.geomType == 'pt') {
t += '' + $scope.bubbleBtnTxt[0] + '
'
+ '' + $scope.bubbleBtnTxt[1] + '
';
}
}
window.queryObjectId = function (uniqueID, OBJECTID, selBtn, layer) {
$scope.queryObjectId(uniqueID, OBJECTID, selBtn, layer);
}
window.gotoCounty = function (parcelid) {
$scope.localCustom.gotoCounty($scope, parcelid);
}
$scope.map.infoWindow.on('hide', function () { $scope.selectedLayer.clear(); })
$('#zoomImage').on("click touchend", function () {
$scope.zoomToParcel();
});
$('#openAdjoiners').on("click touchstart", function () {
$scope.showAdjoiner = true;
$scope.switchParcelDetails('adjoiner');
$("#detailPanels").addClass("active");
setTimeout($scope.myScroll2.refresh(), 300);
setTimeout($scope.myScroll3.refresh(), 300);
});
$('#openListView').on("click touchstart", function () {
$("#parcelPreloaderContainer").addClass("active");
$scope.switchParcelDetails('detail');
$("#detailPanels").addClass("active");
$("#panel1").addClass("active");
$("#panel1").removeClass("inactive");
setTimeout($scope.myScroll2.refresh(), 300);
setTimeout($scope.myScroll3.refresh(), 300);
});
//var taxParcelTemplate = new $scope.InfoTemplate('Parcels',t);
if ($scope.selectedParcel.attributes) {
var content = $scope.esriLang.substitute($scope.selectedParcel.attributes, t);
} else {
var content = $scope.esriLang.substitute($scope.selectedParcel, t);
}
//$scope.map.infoWindow = taxParcelTemplate;
//$scope.map.infoWindow.setTitle($scope.parcelLyrName);
$scope.map.infoWindow.setContent(content);
if (parcelGeom.type == 'point') { //if address point
var defer = $scope.map.centerAndZoom(projectedGeometry[0], 18)
.addCallback(function () {
$scope.selCentroid = projectedGeometry[0];
//console.log($scope.selCentroid);
setTimeout($scope.map.infoWindow.show($scope.selCentroid), 300);
});
}
else {
var defer = $scope.map.setExtent(projectedGeometry[0].getExtent().expand(2.0))
.addCallback(function () {
$scope.selCentroid = projectedGeometry[0].getCentroid();
//console.log($scope.selCentroid);
setTimeout($scope.map.infoWindow.show($scope.selCentroid), 300);
});
}
}
else {
if (parcelGeom.type == 'point') { //if address point
$scope.map.centerAndZoom(projectedGeometry[0], 18);
}
else {
$scope.map.setExtent(projectedGeometry[0].getExtent().expand(2.0));
}
}
if ($("#layerSelect").hasClass("active")) { //to prevent layer UI visible
$("#layerSelect").removeClass("active");
$("#openLayerSelect").removeClass("active");
$("#basemapGalleryButton").css("opacity", 0.8); //temp solution to init change in android app
}
$scope.showMap();
}
});
}
this.zoomToBookmark = function ($scope, bookmark) {
$scope.thisPoint = new esri.geometry.Point({
latitude: bookmark.y,
longitude: bookmark.x
});
//var observationRenderer = new $scope.SimpleRenderer(sps);
var highlightGraphic = new $scope.Graphic($scope.thisPoint, $scope.sps);
var font = new $scope.Font("12px", $scope.Font.STYLE_NORMAL, $scope.Font.VARIANT_NORMAL, $scope.Font.WEIGHT_BOLDER, "arial");
//var font = new $scope.Font("20px", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLDER,"Ariel");
var bookmarkLable = new $scope.TextSymbol(bookmark.label, font, new $scope.Color([10, 10, 10]));
//bookmarkLable.font.setFamily("arial");
bookmarkLable.setAlign($scope.TextSymbol.ALIGN_START);
bookmarkLable.setOffset(10, 0);
//bookmarkLable.setColor("#333333"); //it makes error when printing map
bookmarkLable.setColor(new $scope.Color([0, 0, 0]));
bookmarkLable.setHaloColor(new $scope.Color([255, 255, 255]));
bookmarkLable.setHaloSize(1);
var highlightGraphicLable = new $scope.Graphic($scope.thisPoint, bookmarkLable);
$scope.bmLayer.clear();
$scope.bmLayer.add(highlightGraphic);
$scope.bmLayer.add(highlightGraphicLable);
//$scope.map.centerAndZoom($scope.thisPoint, 18);
if (bookmark.zoom) {
$scope.map.centerAndZoom($scope.thisPoint, bookmark.zoom);
} else {
$scope.map.centerAt($scope.thisPoint);
}
}
this.isNumber = function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
this.execGotoXY = function ($scope) {
var xInput = $("#lon_txt").val();
var yInput = $("#lat_txt").val();
if (self.isNumber(xInput) && self.isNumber(yInput)) {
$scope.thisPoint = new esri.geometry.Point({
latitude: yInput,
longitude: xInput
});
//var observationRenderer = new $scope.SimpleRenderer(sps);
var highlightGraphic = new $scope.Graphic($scope.thisPoint, $scope.sps);
var font = new $scope.Font("12px", $scope.Font.STYLE_NORMAL, $scope.Font.VARIANT_NORMAL, $scope.Font.WEIGHT_BOLDER, "arial");
//var font = new $scope.Font("20px", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLDER,"Ariel");
var bookmarkLable = new $scope.TextSymbol(xInput + ", " + yInput, font, new $scope.Color([10, 10, 10]));
//bookmarkLable.font.setFamily("arial");
bookmarkLable.setAlign($scope.TextSymbol.ALIGN_START);
bookmarkLable.setOffset(10, 0);
//bookmarkLable.setColor("#333333"); //it makes error when printing map
bookmarkLable.setColor(new $scope.Color([0, 0, 0]));
bookmarkLable.setHaloColor(new $scope.Color([255, 255, 255]));
bookmarkLable.setHaloSize(1);
var highlightGraphicLable = new $scope.Graphic($scope.thisPoint, bookmarkLable);
$scope.bmLayer.clear();
$scope.bmLayer.add(highlightGraphic);
$scope.bmLayer.add(highlightGraphicLable);
//$scope.map.centerAndZoom($scope.thisPoint, 18);
$scope.map.centerAndZoom($scope.thisPoint, 18);
}
else {
alert("Please enter valid X, Y.");
}
}
this.clrBmLyr = function ($scope) {
$scope.bmLayer.clear();
}
});
//})();