ok here comes the full code, that worked for me:
======================================================================================
The contents of the xml file, that holds all the lat,lon for the area:
<states>
<state name ="Skyros" colour="#88ff00" >
<point lat="39.027985" lng="24.464527"/>
<point lat="39.015449" lng="24.495769"/>
....
<point lat="39.027985" lng="24.464527"/>
</state>
</states>
======================================================================================
and here is the main file (only script):
<script type="text/javascript" src="http://WWW.YOURDOMAIN.COM/
gmaps_polyline.js"></script>
<script type="text/javascript">
var user_icon = new GIcon();
user_icon.image = 'http://
WWW.YOURDOMAIN.COM/pin.png';
user_icon.iconSize = new GSize(48, 48);
user_icon.iconAnchor = new GPoint(16, 37);
var setLat = <?php echo $the_pro_lat; ?>;
var setLon = <?php echo $the_pro_lon; ?>;
function add_spot_map() {
if (GBrowserIsCompatible()) {
var polys = [];
var labels = [];
var map = new
GMap(document.getElementById('map_addspot'));
map.addControl(new GLargeMapControl3D());
map.setCenter(new GLatLng(<?php echo
$the_pro_lat; ?>, <?php echo $the_pro_lon; ?>), <?php echo
$the_zoom_level; ?>);
GEvent.addListener(map, 'click',
function(overlay, point) {
if (!overlay) {
for (var i=0; i<polys.length; i++) {
if (polys[i].Contains(point)) {
if (overlay) {
map.removeOverlay(overlay);
} else if (point) {
map.recenterOrPanToLatLng(point);
var marker = new
GMarker(point,user_icon);
map.addOverlay(marker);
var matchll =
/\(([-.\d]*), ([-.
\d]*)/.exec( point );
if ( matchll ) {
var lat
=
parseFloat( matchll[1] );
var lon
=
parseFloat( matchll[2] );
lat =
lat.toFixed(6);
lon =
lon.toFixed(6);
} else {
}
document.getElementById('spot_lat').value = lat;
document.getElementById('spot_lon').value = lon;
}
i = 999;
}
}
}
});
var request = GXmlHttp.create();
request.open("GET", "http://WWW.YOURDOMAIN.COM/
xml_allowed_area.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc =
GXml.parse(request.responseText);
var states =
xmlDoc.documentElement.getElementsByTagName("state");
for (var a = 0; a < states.length; a++) {
var label =
states[a].getAttribute("name");
var colour =
states[a].getAttribute("colour");
var points =
states[a].getElementsByTagName("point");
var pts = [];
for (var i = 0; i < points.length; i++) {
pts[i] = new
GLatLng(parseFloat(points[i].getAttribute("lat")),
parseFloat(points[i].getAttribute("lng")));
}
var poly = new GPolygon(pts,"#FFFFFF",
1,1,colour,0.5,{clickable:false});
polys.push(poly);
labels.push(label);
//just to show you the area, that is
active for adding a marker, not Necessary
map.addOverlay(poly);
}
}
}
request.send(null);
}
}
</script>
======================================================================================
the only problem i got now (minor, but for this feature to be
perfect), user adds a marker the first time, marker shows up,
everything fine. User thinks, this is not the point, clicks on another
part of the map... the first marker is still visible.
why is this one
if (overlay) {
map.removeOverlay(overlay);
} else if (point) {
not working??
worked fine, till now, before i added the xml loading stuff :(
thank you for all your help, and a bog thanks to Mike Williams from
http://econym.org.uk/gmap/ for all his tutorials, this guy rocks :)
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.