[OpenLayers-Users] WMS Question
Eric Lemoine
eric.c2c at gmail.com
Thu Sep 18 01:28:20 EDT 2008
Hi. You need your WMS to serve images projected in ESPG:900913 for
that layer. OpenLayers won't do the 4326 to 900913 re-projection of
the images. Eric
2008/9/18, Jeff_Hobbs at sjwater.com <Jeff_Hobbs at sjwater.com>:
> Hi,
>
> I've got an application using the Yahoo basemap. It's loosely based on the
> sphericalmercator example. I'd like to make a WMS in SRS 4326 as a third
> basemap/base layer. I can add the WMS, however it doesn't appear on my
> map. I'm guessing it's a projection issue. Is there a way to get it to
> align to my Yahoo basemaps? If so, any code suggestions would be greatly
> appreciated as I'm new to both OL and javascript. My WMS connection info
> is right here:
> --------------------------------------------------------------
> // create 2006 SCLARCO imagery WMS
> var sclarcoImagery = new OpenLayers.Layer.WMS( "2006
> Imagery",
> "http://devinside.sjwater.com/ecwp/ecw_wms.dll?",
> {layers: "SCLARCO_2006", transparent: "false",
> singleFile: "true", srs: "EPSG:4326", format: "image/jpeg",
> sphericalMercator: "true"}, {isBaseLayer: true}, {tileSize: new
> OpenLayers.Size(256,256), buffer: 1});
> ---------------------------------------------------------------
>
> All of my code is below:
>
> ----------------------------------------------------------------
>
> Thanks in advance for any feedback!
>
> Jeff
>
>
>
>
> var map;
> var blow =
> OpenLayers.Layer.SphericalMercator.forwardMercator(-122.22565, 37.12293);
> // left bottom
> var bhigh =
> OpenLayers.Layer.SphericalMercator.forwardMercator(-121.68114, 37.50074);
> // right top
>
> // avoid pink tiles
> OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
> OpenLayers.Util.onImageLoadErrorColor = "transparent";
>
> function init(){
>
> // Create a styleMap to style your features for two
> different
> // render intents. The style for the 'default' render intent
> will
> // be applied when the feature is first drawn. The style for
> the
> // 'select' render intent will be applied when the feature is
> // selected.
> var stationStyles = new OpenLayers.StyleMap({ // This is only
> for stations
> "default": new OpenLayers.Style({
> fillColor: "#006699",
> strokeColor: "#ff9933",
> strokeWidth: 2,
> fillOpacity: 0.6
> }),
> "select": new OpenLayers.Style({
> fillColor: "#006699",
> strokeColor: "#ff9933",
> strokeWidth: 2,
> fillOpacity: 1
> })
> });
>
> var options = {
> projection: new
> OpenLayers.Projection("EPSG:900913"),
> displayProjection: new
> OpenLayers.Projection("EPSG:4326"),
> units: "m",
> //maxResolution: 156543.0339,
> 'maxResolution': "auto",
> maxExtent: new OpenLayers.Bounds(blow.lon,
> blow.lat, bhigh.lon, bhigh.lat),
> maxScale: 200,
> minScale: 50000,
> numZoomLevels: 25
> };
> map = new OpenLayers.Map('map', options);
>
> // Add the pan/zoom toolbar to all of the
> layers on the map
> var panel = new
> OpenLayers.Control.NavToolbar();
> map.addControl(panel);
>
> // create Yahoo layers
> var yahoo = new OpenLayers.Layer.Yahoo(
> "Yahoo Street",
> {'sphericalMercator': true}
> );
>
> var yahoohyb = new OpenLayers.Layer.Yahoo(
> "Yahoo Hybrid",
> {'type': YAHOO_MAP_HYB, 'sphericalMercator': true}
> );
>
> // create 2006 SCLARCO imagery WMS
> var sclarcoImagery = new
> OpenLayers.Layer.WMS( "2006 Imagery",
> "http://devinside.sjwater.com/ecwp/ecw_wms.dll?",
> {layers: "SCLARCO_2006", transparent: "false",
> singleFile: "true", srs: "EPSG:4326", format: "image/jpeg",
> sphericalMercator: "true"}, {isBaseLayer: true}, {tileSize: new
> OpenLayers.Size(256,256), buffer: 1});
>
> // SJWC Stations KML file
> stationKML = new
> OpenLayers.Layer.GML("Station", "data/station.kml",
> {
> projection: new OpenLayers.Projection
> ("EPSG:4326"),
> format: OpenLayers.Format.KML,
> styleMap: stationStyles,
> formatOptions: {
> extractStyles: false, //Use the style
> map above
> extractAttributes: true
> }
> });
>
>
> map.addLayers([yahoo, yahoohyb,
> sclarcoImagery, stationKML]);
> map.addControl(new
> OpenLayers.Control.LayerSwitcher());
> map.addControl(new
> OpenLayers.Control.Permalink());
> map.addControl(new
> OpenLayers.Control.MousePosition());
> if (!map.getCenter()) {map.zoomToMaxExtent()}
> }
> // This it the function that can be called to
> "pan" the map from station to station
> // NOTE: Need to make sure you translate
> the WGS lat/long to SphericalMercator!
> var locateMe = function(lon, lat, zoom) {
> var myTransCoord =
> OpenLayers.Layer.SphericalMercator.forwardMercator(lon, lat)
> map.setCenter(new
> OpenLayers.LonLat(myTransCoord.lon, myTransCoord.lat), zoom);
> }
>
> </script>
>
>
>
> --------------------------------
> Jeff Hobbs
> GIS Coordinator
> San Jose Water Company (NYSE:SJW)
> 1265 South Bascom Avenue
> San Jose, CA 95128
> Voice - (408) 279-7833
> Cell - (408) 314-6342
> Fax - (408) 279-7889
> jeff_hobbs at sjwater.com
> http://www.sjwater.com
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list