function not defined in map js file

839
1
Jump to solution
06-15-2019 04:49 AM
NadirHussain
Occasional Contributor II

Dear All

i have two files in asp,net project.one is pure js file in which i defined all the map related function in dojo style library.Other file is .aspx page.In html part i am calling one function which is defined in map js file.After calling it always throuh me the error function not defined.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="WebApplication1.Home" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<title>Asset View</title>

<link rel="stylesheet" href="https://js.arcgis.com/3.28/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css" />
<script src="https://js.arcgis.com/3.28/"></script>
<script src="Scripts/MapScript.js" type="text/javascript"></script>  //Map Script file
<script src="https://Code.jquery.com/jquery-1.12.4.js"></script>


<link href="Content/Style.css" rel="stylesheet" />
</head>
<body>
<div style="height:100%;background-color:white;width:100%;position:fixed" >
<div style="position: fixed;
margin-top: 0px;
margin-right: 0px;
z-index:999;
height:100px;
width:100px;
background-color:aquamarine "/>
<div id="MapDiv" class="MapDiv">
</div>
<div id="AttributeDiv" class="AttributeDiv">
</div>
<div id="TblDiv" class="TblDiv">

  <button id="btn" >CLick ME</button>

</div>

<script>
$(document).ready(function () {

$( "#btn" ).click(function() {
layerVisibility("LayerNAme",true);  //THis function is defined .mapScript.js file. Error on this line function not defiined.
});

});

</script>


</body>
</html>

///Map JS file

var map;
var basemap;
var dynamicMapServiceLayer;
var RestServiceUrl;
var featureServiceValidURl;
var featureServiceRenewalURl;
var featureServiceExpiredURl;
var featureServiceBlockedURl;
var app = {};
require(["dojo/dom", "dojo/on", "dijit/registry", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/ArcGISTiledMapServiceLayer", "esri/map",
"esri/layers/FeatureLayer","esri/layers/ImageParameters", "dojo/parser", "esri/tasks/QueryTask", "esri/tasks/query", "esri/graphic", "dojo/domReady!"
], function (dom, on, registry, ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer, Map, FeatureLayer, ImageParameters, parser, QueryTask, Query, GraphicMap) {
parser.parse();
var streetsService = "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

map = new Map("MapDiv", {
basemap: "osm"
zoom: 6,
center: [46.66, 24.72] // longitude, latitude
});
map.on("load", mapLoaded);
var imageParameters = new ImageParameters();
imageParameters.format = "jpeg"
function mapLoaded() {
var featureLayer = new FeatureLayer(featureServiceRenewalURl, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] });
map.addLayer(featureLayer);
}
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://0.0.00:6080/arcgis/rest/services/UpdateLicenes/MapServer",
{ "opacity": 0.5, "imageParameters ": imageParameters }
);
map.addLayer(dynamicMapServiceLayer);

//**********************************************************************************************************************//
function layerVisibility( strLAyerName,BLFlag) {
alert("gggggggggg");
}
//**********************************************************************************************************************//
});

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   This is more of an ASP.net question but your issue is that you are trying to call the code from the aspx page html instead of the pages code behind Page_Load event.

ButtonName.Attributes.Add("onclick", layerVisibility("LayerName",true));‍‍

Or there are a couple of other ways to do this in ASP.net

<asp:Button runat="server" ID='next' OnClientClick="layerVisibility('LayerName',true);" />‍‍

View solution in original post

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   This is more of an ASP.net question but your issue is that you are trying to call the code from the aspx page html instead of the pages code behind Page_Load event.

ButtonName.Attributes.Add("onclick", layerVisibility("LayerName",true));‍‍

Or there are a couple of other ways to do this in ASP.net

<asp:Button runat="server" ID='next' OnClientClick="layerVisibility('LayerName',true);" />‍‍
0 Kudos