Access ArcGIS JS API from external JS file?

1588
11
Jump to solution
11-02-2016 05:17 AM
BrettKruger
New Contributor II

Hi Guys

So I have created my map with the webapp builder and plugged it into a system. When displaying the map I use the index.html file from the map.

I load my script like this at the bottom of the index.html file:

 <script type="text/javascript" src="*.js"></script>

My script does a basic thing like a zoom using the CentreAndZoom function of the map, but I do however create a point by using legacy code such as: point = new esri.geometry.Point(lng, lat);

But it seems I cannot access anything else in the JS api, any ideas why or how to enable my js file to have access to the functions provided by the API?

My js file:

//map object
var esriMap;

function zoomTo(lat, lng, factor) {
    var point;
    point = new esri.geometry.Point(lng, lat);
    esriMap.centerAndZoom(point, factor);
 
}

function setZoom(faktor) {
    esriMap.setZoom(faktor);
}

What happens so far is that I have dropdowns on my html page and this calls my zoomTo function which zooms to a point on the map. I am trying now to highlight the point with the SimpleMarkerSymbol function but I cannot get any access to it at all, says undefined now this could be that I do not declare it but if my point is declared in this matter and works should a markersymbol not work the same?

Looking forward to you're responses.

Brett

0 Kudos
11 Replies
BrettKruger
New Contributor II

HI Robert,

So I have got it working in the way which I originally wanted to.

For my marker I was using this page on the API: https://developers.arcgis.com/javascript/3/jsapi/simplemarkersymbol-amd.html

SimpleMarkerSymbol | API Reference | ArcGIS API for JavaScript 3.18

After including it like this from the legacy example it actually became a JS object and I could start using and adding to the map.

marker = new esri.symbol.SimpleMarkerSymbol();

I know you are not encouraging the way I am using the API (outside of widgets) but perhaps if you ever get a gap in your schedule I can perhaps show you the system and how I am coding it. I am sure you could perhaps give me extremely valuable pointers and tips on how to rather improve my coding and where/what I should rather have done instead of how I have done it.

Thanks as always for you're rapid responses and valuable input. Please do let me know if you would like to see the system and code.

Brett Kruger

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Brett,

   I have a custom JS API sample already created to use a .net service to get US state names and their counties that I can easily convert to a widget or I can update it to use a map service instead.