Tuesday, September 07, 2010

VE - custom pushpins

Posted by david on 17. November 2008 21:01

trying to find out how to customize pushpin for the layer … seems like the only way to do is loop through all shapes of the layer, setting them individually:

javascript:  ( source )

function onFeedLoad(layer)
{
   var numShapes = layer.GetShapeCount();
   for(var i=0; i < numShapes; ++i)
   {
      var s = layer.GetShapeByIndex(i);
      s.SetCustomIcon("<img src='hiking_icon.gif'/>");
   }
}

which actually is cool because while stepping through you can apply logic to decide which shape you want to see for that particular data point:

the slightly irritating thing about c# is that you can never seem to just do something … shape.setcustomicon … noooo first you gotta

4296

colinmackay.net Drawing Lines

colinmackay.net Using Pushpins

there’s a real lack of .net specific information out there – it’s all for the javascript control. 

So, I’ve got the map loads in pageload with the following:

ShapeLayer aGeoRSSLayer = new ShapeLayer();
ScubaMap.AddShapeLayer(aGeoRSSLayer);
ScubaMap.ImportShapeLayerData(new ShapeSourceSpecification(DataType.ImportXML, "http://david.egerton.info/Storage/1992hurricaneandrew.xml", aGeoRSSLayer), "", true);

I tried looping through the shape to set custom icon – didn’t work … I even tried deleting the shapelayer, after creating it, that didn’t work.  Seems like I’ve lost access to it after it is sent to the map.

My next line of attack is to create the shapelayer myself, rather than use the importxml … following the Drawing Lines method in the above link. 

Map Control

“Client events are handled as JavaScript functions that are declared within a <script> tag. All JavaScript event handling functions must have the same signature, where OnClientEventHandler is the name of the JavaScript function that handles the event.”

Using JavaScript Along with ASP.NET

ASP.NET AJAX  Overview  ScriptManager Control Overview

The control follows the ASP.NET AJAX architecture so all properties of the control are exposed using the getters and setters.
 
You can use the $find(mapcontrolID) to get the control and then call:
 
get_VEMap()to get the actual VEMap object, then use as normal VE js control. You can also use this to set properties, call methods, bind to events etc. In debug mode the javascript is well laid out, in release mode it is compressed, at least it should be.
 
In order to get the map's control ID you need to expose the Map1.ClientID to javascript. I normally do this in my aspx page by doing this (assuming the map is ID=Map1:
 
<script type="text/javascript">
   1:  
   2: var cMapControlID = '<% =Map1.ClientID %>';
</script>
 
then you can get the map object at run time like this:
 
var mymap = $find(cMapControlID).get_VEMap()
 

(source)

Virtual Earth Basics Series Part 1 – Loading the Map - Virtual Earth- Map Control Development -

so, what it looks like is that

the map is loaded from server to client … after that, server can’t touch it, at least at this point.

to deal with it at the client level, I’ve got to use javascript.

for a sec, it seems like there’s not much point to the .net control after all … but everytime something happens on the map, it can fire off server events.  I just don’t know what they are yet.    I’ve got a fresh page & am now going to try working at the client with the javascript, because it seems that’s where I have to do any manipulation of the layer, once that layer has been laid down.  I’m also aiming at keeping any script off the page, in another file, so a, it’ll be clean and b, I can use it again.

Add comment


 

biuquote
Loading