AW: [OpenLayers-Users] I would like to display a map with Google Maps layer with a circle with 50km radius

Arnd Wippermann arnd.wippermann at web.de
Wed Feb 1 18:05:25 EST 2012


Cool application jsFiddle

You have to add the Google API to the html section:

<div style="width:400px; height:400px" id="map"></div>

<script
src="http://maps.google.com/maps/api/js?v=3.2&amp;sensor=false"/></script>


And try this in the javascript section:
var P4326   = new OpenLayers.Projection("EPSG:4326");
var P900913 = new OpenLayers.Projection("EPSG:900913");

var mapOptions = {
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG:4326"),
        units: "m",
        numZoomLevels: 18,
        maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,
20037508.34)
}

var map = new OpenLayers.Map('map', mapOptions);
var gmap = new OpenLayers.Layer.Google("foo");
map.addLayers([gmap]);
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", { });
var point = new OpenLayers.Geometry.Point(-111,46).transform(P4326,
P900913);
var circleFeature = new OpenLayers.Feature.Vector(
    OpenLayers.Geometry.Polygon.createRegularPolygon(
        point, 10000, 50
    )
);

map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(point.x,point.y), 8);
vectorLayer.addFeatures([ circleFeature ]);

Keep in mind, that meters on EPSG:900913 not real meters. 
You have to calculate first your radius to EPSG:900913, but how I have no
clue.



Arnd

 

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Stephane
Klein
Gesendet: Mittwoch, 1. Februar 2012 22:53
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] I would like to display a map with Google Maps
layer with a circle with 50km radius

Hi,

I would like to display a map with Google Maps layer with a circle with 50km
radius.

* In this example http://jsfiddle.net/stephane_klein/VLKzY/2/
I succeed to display a map with circle but I don't know how to calculate
50km radius. Do you have a tip ?

* No success in this example with Google Maps layer
http://jsfiddle.net/stephane_klein/JNXQu/1/ Where is my mistake ?

Thanks for your help.

Regards,
Stephane

--
Stéphane Klein <stephane at harobed.org>
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
pro: http://www.is-webdesign.com

_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list