[OpenLayers-Users] draw a line on a map?

geoman csabbey at gmail.com
Mon Apr 14 16:14:52 EDT 2008


I'm new to OpenLayers; I'm evaluating it for a current project. I'm going to
be getting WKT for road segments from a database, and I want to highlight
those segments on a map. However, I haven't been able to get past this
error:
Error: uncaught exception: [Exception... "String contains an invalid
character"  code: "5" nsresult: "0x80530005
(NS_ERROR_DOM_INVALID_CHARACTER_ERR)"  location:
"http://openlayers.org/api/OpenLayers.js Line: 554"]

Here is the code I was using:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 762px;
            height: 825px;
            border: 1px solid black;
        }
    </style>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    <script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAIeWnOWItAsdtOsR3kxiUQhTwM0brOpm-All5BF6PoaKBxRWWERSQAgEHUq2jStqEx-kpNgzntg87iw"></script>

    <script type="text/javascript">

         var result_style = OpenLayers.Util.applyDefaults({
             strokeWidth: 7,
             strokeColor: "#ff0000",
             fillOpacity: 0
         }, OpenLayers.Feature.Vector.style['default']);

        function init() {
            var map = new OpenLayers.Map('map');
			var google = new OpenLayers.Layer.Google( "Google", { type: G_NORMAL_MAP
} );
            var highlight = new OpenLayers.Layer.Vector("highlight", {style:
result_style});

			map.addLayers([google, highlight]);

            var parser = new OpenLayers.Format.WKT();
            var wkt = "LINESTRING(-73.9444 40.75921,-73.96892 40.76396)";
            var geometry = parser.read(wkt);
            var feature = new OpenLayers.Feature.Vector(geometry);

            highlight.addFeatures([feature]);
            map.zoomToExtent(new
OpenLayers.Bounds(-74.0472500,40.6795100,-73.9071900,40.8820000));
        }

    </script>
  </head>
  <body onload="init()">
    <div id="map"></div>
  </body>
</html>

I tried lots of different variations, but nothing that proved useful, so I
left them out. Can anyone spot my issue?

Thanks in advance, 
Craig
-- 
View this message in context: http://www.nabble.com/draw-a-line-on-a-map--tp16689097p16689097.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list