Select to view content in your preferred language

External Link to Map Element

821
2
11-30-2012 06:52 AM
GrantRussell1
Emerging Contributor
Hello all 🙂

We have a web map embedded in a website page. And we are able to listen to elements clicked on in the map for use externally to the map within the website.

But, what we would now like to do is to alter the map view based on a link that a user clicks on outside of the map.

Is it possible to have an external link on the same page as the map, that when clicked on would zoom and center the map on the chosen map element? Say a polygon etc.

Is this possible?

Cheers
Livetech
0 Kudos
2 Replies
SteveCole
Honored Contributor
I can think of one way of doing this but it may not fit in with how you've designed your website. Here it goes-


  1. On your webpage, use an IFRAME for the map.

  2. In the IFRAME, load an HTML page of your javascript API map that uses 100% of the browser's width and height.

  3. In your map initialization javascript, include some code to check the URL to see if any parameters were passed to it. I've done this before and it looked something like this:

  4. [INDENT]
     //Evaluate the URL of this HTML page to determine if any parameters were passed with it
         var htmlPagePath = window.location.toString();
         var qLocation = htmlPagePath.indexOf('?');
    
         if (qLocation < 1)
         {
       passedLatLong = false;
      }
      else
       passLatLong = true;
                 }
                 .
                 .
                 .
          //If a coordinate location was passed as a parameter, zoom the map to it
          if (passedLatLong)
          {
       //Extract the lat/long coordinates passed as a parameter with the URL
       var coordStr = window.location.toString().substr(qLocation + 1,window.location.toString().length);
       var coords = new Array();
       coords = coordStr.split(',');
    
       //Create a lat/long point
       var bridgeLoc = new esri.geometry.Point(coords[0],coords[1], new esri.SpatialReference({wkid:4326}));
    
       //set the map extent based on the lat/long coordinate passed. The coordinate must be converted
       //to Web Mercator since the web services used have been defined with that projection..
       map.setExtent(pointToExtent(map,esri.geometry.geographicToWebMercator(bridgeLoc),3));
           }
    
  5. Hopefully you now see where I'm going with this. When your users click on your "external link" on the page, have the onClick event reload the IFRAME but append a parameter to the URL (FID, lat/long, etc) and then your map init() routine will recognize the parameter and respond accordingly.
  6. [/INDENT]

Again, this approach may not fit in with what you want to do but it's possible. Good luck!

Steve
0 Kudos
GrantRussell1
Emerging Contributor
Cheers, will investigate that, but dont really want to go the Iframe route if can be helped due to other processes we have going on....

Hmmm
0 Kudos